Browse Source

Prod fix and change

merge-requests/245/head
Oksana Stepanenko 2 years ago committed by Coder
parent
commit
930f32ad62
  1. 18
      src/core/namespaces/ips.namespace.ts
  2. 13
      src/core/namespaces/logs.namespace.ts
  3. 19
      src/core/namespaces/tasks.namespace.ts
  4. 16
      src/core/namespaces/users.namespace.ts
  5. 18
      src/domain/ips/services/ips.service.ts
  6. 14
      src/domain/logs/services/logs.service.ts
  7. 19
      src/domain/tasks/services/tasks-list.service.ts
  8. 7
      src/domain/tasks/services/tasks.service.ts
  9. 17
      src/domain/users/services/users-list.service.ts
  10. 7
      src/domain/users/services/users.service.ts
  11. 10
      src/rest/admin/ips/controllers/admin-ips.controller.ts
  12. 1
      src/rest/admin/ips/dto/index.ts
  13. 11
      src/rest/admin/ips/dto/ips-paginated-response.dto.ts
  14. 6
      src/rest/admin/ips/dto/remove-ips.dto.ts
  15. 14
      src/rest/admin/ips/services/admin-ips.service.ts
  16. 9
      src/rest/admin/logs/services/admin-logs.service.ts
  17. 4
      src/rest/admin/tasks/controllers/admin-tasks.controller.ts
  18. 5
      src/rest/admin/tasks/dto/filter-tasks-params.dto.ts
  19. 22
      src/rest/admin/tasks/dto/tasks-list.dto.ts
  20. 15
      src/rest/admin/tasks/services/admin-tasks.service.ts
  21. 11
      src/rest/admin/users/dtos/get-users-list.dto.ts
  22. 41
      src/rest/admin/users/services/admin-users.service.ts

18
src/core/namespaces/ips.namespace.ts

@ -41,6 +41,11 @@ export namespace IPs { @@ -41,6 +41,11 @@ export namespace IPs {
ip?: string
}
export interface IIpData {
id?: number
ip?: string
}
export interface IIPsService {
/**
* Метод для додавання IP-адреси користувача
@ -88,5 +93,18 @@ export namespace IPs { @@ -88,5 +93,18 @@ export namespace IPs {
* @param {String[]} ips - масив ІР адрес
*/
blockIps(ips: string[]): Promise<void>
/**
* Видалення ІР адрес
* @param {string[]} ips - IP адреси
*/
removeIps(ips: string[]): Promise<void>
/**
* Отримання списку всіх ІР адрес з обмеженими даними
* @param {IFetchIpsListParams} params - параметри для пошуку ІР
@returns Повертає список ІР адрес з обмеженими даними
*/
getAllShortDataByParams(params: IFetchIpsListParams): Promise<IIpData[]>
}
}

13
src/core/namespaces/logs.namespace.ts

@ -65,6 +65,12 @@ export namespace Logs { @@ -65,6 +65,12 @@ export namespace Logs {
dateTo?: string
}
export interface ILogShortData {
id?: number
userId?: number
ip?: string
}
export interface ILogsService {
/**
* Метод для додавання лога
@ -90,5 +96,12 @@ export namespace Logs { @@ -90,5 +96,12 @@ export namespace Logs {
* @param ids - id логів, які видаляються
*/
deleteMany(ids: number[]): Promise<void>
/**
* Метод для отримання всіх логів з обмеженими даними
* @param params - параметри для пошуку логів
* @returns Повертає список логів з обмеженими даними
*/
getAllShortDataByParams(params: Logs.IGetLogsListParams): Promise<ILogShortData[]>
}
}

19
src/core/namespaces/tasks.namespace.ts

@ -131,6 +131,14 @@ export namespace Tasks { @@ -131,6 +131,14 @@ export namespace Tasks {
events?: Record<string, Event>[]
}
export interface ITaskShortData {
id: number
executorId: number
status: Status
authorId: number
startDate: string
}
export interface ITaskCommentRelation {
/** Ідентифікатор */
id: number
@ -458,6 +466,17 @@ export namespace Tasks { @@ -458,6 +466,17 @@ export namespace Tasks {
* @returns Повертає задачу
*/
findTaskByOfflineKey(key: string): Promise<TaskModel>
/**
* Отримання всіх id задач за заданими параметрами
* @param pagination - параметри пагінації
* @param params - параметри пошуку задач
* @returns Поверає масив задач з обмеженими даними (id задачі та id виконавця)
*/
getAllShortDataByParams(
pagination: IPagination,
params: Tasks.IGetTasksListParams,
): Promise<ITaskShortData[]>
}
export interface ITasksPermissionsService {

16
src/core/namespaces/users.namespace.ts

@ -260,6 +260,11 @@ export namespace Users { @@ -260,6 +260,11 @@ export namespace Users {
taxonomiesV?: string
}
export interface IUserShortData {
id: number
status: Status
}
export interface IUsersService {
/**
* Перевіряє чи користувач існує
@ -461,6 +466,17 @@ export namespace Users { @@ -461,6 +466,17 @@ export namespace Users {
* @returns Повертає список користувачів, у яких ім'я або прізвище містить заданий набір літер
*/
getUsersBySearchString(string: string): Promise<UserModel[]>
/**
* Отримання списку всіх користувачів з обмеженими даними (id та статус)
* @param {IPagination} pagination - параметри пагінації
* @param {IGetUsersListParams} params - параметри для пошуку користувачів
* @returns Повертає список користувачів з обмеженими даними
*/
getAllShortDataByParams(
pagination: IPagination,
params: IGetUsersListParams,
): Promise<IUserShortData[]>
}
export interface IChangePhoneNumberPayload {

18
src/domain/ips/services/ips.service.ts

@ -40,6 +40,15 @@ export class IPsService implements IPs.IIPsService { @@ -40,6 +40,15 @@ export class IPsService implements IPs.IIPsService {
return await paginateAndGetMany(query, pagination, 'it')
}
public async getAllShortDataByParams(params: IPs.IFetchIpsListParams) {
const query = this.ipsRepository.createQueryBuilder('it').select('it.id').addSelect('it.ip')
if (params.type) query.andWhere('it.listType = :type', { type: params?.type })
if (params.ip) query.andWhere('it.ip ILIKE :ip', { ip: `%${params?.ip}%` })
return query.getMany()
}
public async remove(ids: number[]) {
const ips = await this.ipsRepository.findByIds(JSON.parse(ids as any))
@ -71,4 +80,13 @@ export class IPsService implements IPs.IIPsService { @@ -71,4 +80,13 @@ export class IPsService implements IPs.IIPsService {
}),
)
}
public async removeIps(ips: string[]) {
await Promise.all(
ips.map(async ip => {
const ipEntity = await this.ipsRepository.findOne({ ip })
if (ipEntity) await this.ipsRepository.remove(ipEntity)
}),
)
}
}

14
src/domain/logs/services/logs.service.ts

@ -40,6 +40,20 @@ export class LogsService implements Logs.ILogsService { @@ -40,6 +40,20 @@ export class LogsService implements Logs.ILogsService {
return paginated
}
public async getAllShortDataByParams(params: Logs.IGetLogsListParams) {
const query = this.logsRepository
.createQueryBuilder('it')
.select('it.id')
.addSelect('it.userId')
.addSelect('it.ip')
this.addSearchStringToQuery(query, params)
this.addSearchParams(query, params)
const logs: Logs.ILogShortData[] = await query.getMany()
return logs
}
private substituteDescriptionInList(items: Logs.ILog[]) {
items.forEach(it => {
if (it.key in LogKeysDictionary) it.description = LogKeysDictionary[it.key]

19
src/domain/tasks/services/tasks-list.service.ts

@ -49,6 +49,25 @@ export class TasksListService { @@ -49,6 +49,25 @@ export class TasksListService {
return count
}
public async getAllShortDataByParams(
pagination: IPagination,
params: Tasks.IGetTasksListParams,
) {
const query = await this.tasksRepository
.createQueryBuilder('it')
.leftJoinAndSelect('it.favorites', 'favorites')
.select('it.id')
.addSelect('it.executorId')
.addSelect('it.status')
.addSelect('it.authorId')
.addSelect('it.startDate')
await this.addSearchStringToQuery(query, pagination.searchString, params)
await this.addSearchParams(query, params)
return query.getMany()
}
private addSort(query: SelectQueryBuilder<Tasks.TaskModel>, pagination: IPagination) {
if (!pagination.sortField) return
let sortString = ''

7
src/domain/tasks/services/tasks.service.ts

@ -644,4 +644,11 @@ export class TasksService implements Tasks.ITasksService { @@ -644,4 +644,11 @@ export class TasksService implements Tasks.ITasksService {
public async findTaskByOfflineKey(key: string) {
return this.tasksRepository.findOneOrFail({ offlineKey: key })
}
public async getAllShortDataByParams(
pagination: IPagination,
params: Tasks.IGetTasksListParams,
) {
return this.tasksListService.getAllShortDataByParams(pagination, params)
}
}

17
src/domain/users/services/users-list.service.ts

@ -43,6 +43,23 @@ export class UsersListService { @@ -43,6 +43,23 @@ export class UsersListService {
return { items, count }
}
public async getAllShortDataByParams(
pagination: IPagination,
params: Users.IGetUsersListParams = {},
) {
const query = this.usersRepository
.createQueryBuilder('it')
.leftJoinAndSelect('it.info', 'info')
.andWhere('it.status <> :deleted', { deleted: Users.Status.Deleted })
.select('it.id')
.addSelect('it.status')
this.addSearchStringToQuery(query, pagination.searchString, params)
await this.addSearchParams(query, params)
return query.getMany()
}
// для випадків, коли потрібно виконати сортування інакше, ніж це робиться в paginateAndGetMany
private addSort(query: SelectQueryBuilder<Users.UserModel>, pagination: IPagination) {
if (!pagination.sortField) return

7
src/domain/users/services/users.service.ts

@ -409,4 +409,11 @@ export class UsersService implements Users.IUsersService { @@ -409,4 +409,11 @@ export class UsersService implements Users.IUsersService {
.orWhere('info.lastName ILIKE :search', { search: toSearch })
.getMany()
}
public async getAllShortDataByParams(
pagination: IPagination,
params: Users.IGetUsersListParams = {},
) {
return this.usersListService.getAllShortDataByParams(pagination, params)
}
}

10
src/rest/admin/ips/controllers/admin-ips.controller.ts

@ -9,6 +9,7 @@ import { @@ -9,6 +9,7 @@ import {
BlockIPsPayloadDto,
FetchIpsListParamsDto,
IpsPaginatedResponseDto,
RemoveIpsDto,
SetIpListTypeDto,
StoreIpDto,
} from '../dto'
@ -58,7 +59,14 @@ export class AdminsIpsController { @@ -58,7 +59,14 @@ export class AdminsIpsController {
return await this.adminIpsService.getList(pagination, params)
}
@ApiOperation({ summary: 'Видалення IP' })
@ApiOperation({ summary: 'Видалення списку IP' })
@RoleGuard(Users.Role.Admin)
@Delete('by-ips')
public async removeByIps(@Query() dto: RemoveIpsDto) {
return await this.adminIpsService.removeByIps(dto.ips)
}
@ApiOperation({ summary: 'Видалення IP по їх id' })
@RoleGuard(Users.Role.Admin)
@Delete('/:ids')
public async removeById(@Param('ids') ids: number[]) {

1
src/rest/admin/ips/dto/index.ts

@ -3,3 +3,4 @@ export * from './set-ip-list-type.dto' @@ -3,3 +3,4 @@ export * from './set-ip-list-type.dto'
export * from './ips-paginated-response.dto'
export * from './fetch-ips-list.dto'
export * from './block-ips.dto'
export * from './remove-ips.dto'

11
src/rest/admin/ips/dto/ips-paginated-response.dto.ts

@ -1,10 +1,21 @@ @@ -1,10 +1,21 @@
import { IpDto } from 'src/core/dto'
import { DtoProperty } from 'src/shared'
export class IPShortDataDto {
@DtoProperty()
id: number
@DtoProperty()
ip: string
}
export class IpsPaginatedResponseDto {
@DtoProperty({ isArray: true, type: IpDto })
items: IpDto[]
@DtoProperty()
count: number
@DtoProperty({ isArray: true, type: IPShortDataDto })
data: IPShortDataDto[]
}

6
src/rest/admin/ips/dto/remove-ips.dto.ts

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
import { DtoProperty } from 'src/shared'
export class RemoveIpsDto {
@DtoProperty({ isArray: true, type: String })
ips: string[]
}

14
src/rest/admin/ips/services/admin-ips.service.ts

@ -18,13 +18,25 @@ export class AdminIpsService { @@ -18,13 +18,25 @@ export class AdminIpsService {
}
public async getList(pagination: IPagination, params: FetchIpsListParamsDto) {
return await this.ipsService.getList(pagination, _.omitBy(params, _.isNil))
const list = await this.ipsService.getList(pagination, _.omitBy(params, _.isNil))
const ipsShortData = await this.ipsService.getAllShortDataByParams(
_.omitBy(params, _.isNil),
)
return {
...list,
data: ipsShortData,
}
}
public async removeById(ids: number[]) {
return await this.ipsService.remove(ids)
}
public async removeByIps(ips: string[]) {
return await this.ipsService.removeIps(ips)
}
public async blockIPs(dto: BlockIPsPayloadDto) {
await this.ipsService.blockIps(dto.ips)
}

9
src/rest/admin/logs/services/admin-logs.service.ts

@ -10,7 +10,14 @@ export class AdminLogsService { @@ -10,7 +10,14 @@ export class AdminLogsService {
constructor(@Inject(LOGS_SERVICE) private readonly logsService: Logs.ILogsService) {}
public async getList(pagination: IPagination, params: FetchLogsListDto) {
return await this.logsService.getList(pagination, _.omitBy(params, _.isNil))
const list = await this.logsService.getList(pagination, _.omitBy(params, _.isNil))
const logsShortData = await this.logsService.getAllShortDataByParams(
_.omitBy(params, _.isNil),
)
return {
...list,
data: logsShortData,
}
}
public async deleteMany(idsStr: string) {

4
src/rest/admin/tasks/controllers/admin-tasks.controller.ts

@ -8,7 +8,7 @@ import { @@ -8,7 +8,7 @@ import {
AdminCreateTaskDto,
DeleteTasksParamsDto,
FetchExecutorsListDto,
FilteredTasksListDto,
AdminFilteredTasksListDto,
FilterTasksParamsDto,
FinishTasksDto,
GetTasksCountsParamsDto,
@ -101,7 +101,7 @@ export class AdminTasksController { @@ -101,7 +101,7 @@ export class AdminTasksController {
})
@ApiOkResponse({
description: 'Повертає список задач, які відповідають параметрам, зазначеним в фільтрі',
type: FilteredTasksListDto,
type: AdminFilteredTasksListDto,
})
@ApiImplictPagination()
@AuthGuard()

5
src/rest/admin/tasks/dto/filter-tasks-params.dto.ts

@ -83,4 +83,9 @@ export class FilterTasksParamsDto { @@ -83,4 +83,9 @@ export class FilterTasksParamsDto {
@IsBoolean()
@TransformStringToBoolean()
withGroup?: boolean
@DtoPropertyOptional()
@IsBoolean()
@TransformStringToBoolean()
withoutAdditionalData: boolean
}

22
src/rest/admin/tasks/dto/tasks-list.dto.ts

@ -93,7 +93,24 @@ export class TaskListItemDto { @@ -93,7 +93,24 @@ export class TaskListItemDto {
hasUnreadDocuments?: boolean
}
export class FilteredTasksListDto {
export class TasksDataDto {
@DtoProperty()
id: number
@DtoProperty()
executorId: number
@DtoProperty()
authorId: number
@DtoProperty({ enum: Tasks.Status })
status: Tasks.Status
@DtoProperty()
startDate: string
}
export class AdminFilteredTasksListDto {
@DtoProperty({
isArray: true,
type: TaskListItemDto,
@ -102,4 +119,7 @@ export class FilteredTasksListDto { @@ -102,4 +119,7 @@ export class FilteredTasksListDto {
@DtoProperty()
count: number
@DtoPropertyOptional({ isArray: true, type: TasksDataDto })
data?: TasksDataDto[]
}

15
src/rest/admin/tasks/services/admin-tasks.service.ts

@ -138,7 +138,20 @@ export class AdminTasksService { @@ -138,7 +138,20 @@ export class AdminTasksService {
const preparedTasks = await this.prepareTasksForResponse(items, userId, dto)
return { items: preparedTasks, count }
const response: Record<string, any> = {
items: preparedTasks,
count,
}
if (!dto.withoutAdditionalData) {
const tasksShortData = await this.tasksService.getAllShortDataByParams(
pagination,
_.omit(params, ['withComments', 'withDocuments']),
)
response.data = tasksShortData
}
return response
}
public async getTasksCountByAuthor(userId: number, dto: GetTasksCountsParamsDto) {

11
src/rest/admin/users/dtos/get-users-list.dto.ts

@ -17,6 +17,14 @@ class UserWithAdditionalInfoDto extends UserDto { @@ -17,6 +17,14 @@ class UserWithAdditionalInfoDto extends UserDto {
factoryIds?: number[]
}
class UserDataDto {
@DtoProperty()
id: number
@DtoProperty({ enum: Users.Status })
status: Users.Status
}
export class FetchUsersListResDto extends UsersListDto {
@DtoProperty({
isArray: true,
@ -26,6 +34,9 @@ export class FetchUsersListResDto extends UsersListDto { @@ -26,6 +34,9 @@ export class FetchUsersListResDto extends UsersListDto {
@DtoProperty()
count: number
@DtoProperty({ isArray: true, type: UserDataDto })
data: UserDataDto[]
}
export class UserShortInfoResDto {

41
src/rest/admin/users/services/admin-users.service.ts

@ -116,27 +116,30 @@ export class AdminUsersService { @@ -116,27 +116,30 @@ export class AdminUsersService {
const searchFields = ['firstName', 'middleName', 'lastName', 'login', 'email']
const usersList = await this.usersDomainService.getList(
const _pagination = {
...pagination,
searchString: this.configureSearchString(pagination?.searchString, userIdsByFactories),
}
const _params = _.omitBy(
{
...pagination,
searchString: this.configureSearchString(
pagination?.searchString,
...params,
includeIds: this.configureIdsToInclude(
params.includeIds,
userIdsByFactories,
userIdsByFactoryId,
),
withFactoriesRelations: true,
searchFields: params.globalSearchString ? searchFields : null,
},
_.omitBy(
{
...params,
includeIds: this.configureIdsToInclude(
params.includeIds,
userIdsByFactories,
userIdsByFactoryId,
),
withFactoriesRelations: true,
searchFields: params.globalSearchString ? searchFields : null,
},
_.isNil,
),
_.isNil,
)
const usersList = await this.usersDomainService.getList(_pagination, _params)
const usersShortData = await this.usersDomainService.getAllShortDataByParams(
_pagination,
_.omit(_params, ['withFactoriesRelations']),
)
const factoriesIds = []
@ -175,7 +178,7 @@ export class AdminUsersService { @@ -175,7 +178,7 @@ export class AdminUsersService {
}),
)
return usersList
return { ...usersList, data: usersShortData }
}
private async findUserIdsByFactoriesSearchString(searchString: string) {
@ -339,7 +342,7 @@ export class AdminUsersService { @@ -339,7 +342,7 @@ export class AdminUsersService {
await this.usersDomainService.update({ id, avatarUrl })
return avatarUrl
} catch(e) {
} catch (e) {
console.log('Update avatar error ', e)
}
}

Loading…
Cancel
Save