diff --git a/src/libs/core/controllers/content-types.controller.ts b/src/libs/core/controllers/content-types.controller.ts index 6ba3c46f..912dafb6 100644 --- a/src/libs/core/controllers/content-types.controller.ts +++ b/src/libs/core/controllers/content-types.controller.ts @@ -15,7 +15,7 @@ import { import { ApiBearerAuth, ApiImplicitParam, ApiImplicitQuery, ApiResponse, ApiUseTags } from '@nestjs/swagger'; import { InjectRepository } from '@nestjs/typeorm'; import { plainToClass } from 'class-transformer'; -import { Repository } from 'typeorm'; +import { Repository, Like } from 'typeorm'; import { Roles } from '../decorators/roles.decorator'; import { InContentTypeDto } from '../dto/in-content-type.dto'; @@ -143,11 +143,15 @@ export class ContentTypesController { @Query('q') q ) { try { - const objects = await this.contentTypeRepository.findAndCount({ - skip: (curPage - 1) * perPage, - take: perPage, - order: { id: 'DESC' } - }); + let objects: [ContentType[], number]; + let qb = this.contentTypeRepository.createQueryBuilder('contentType'); + if (q){ + qb = qb.where('contentType.name like :q or contentType.title like :q or contentType.id = :id', { q: `%${q}%`, id: +q }); + } + qb = qb.orderBy('contentType.id', 'DESC'); + qb = qb.skip((curPage - 1) * perPage) + .take(perPage); + objects = await qb.getManyAndCount(); return plainToClass(OutContentTypesDto, { contentTypes: objects[0], meta: { diff --git a/src/libs/core/controllers/groups.controller.ts b/src/libs/core/controllers/groups.controller.ts index 8b61b08c..273f7a3f 100644 --- a/src/libs/core/controllers/groups.controller.ts +++ b/src/libs/core/controllers/groups.controller.ts @@ -15,7 +15,7 @@ import { import { ApiBearerAuth, ApiImplicitParam, ApiImplicitQuery, ApiResponse, ApiUseTags } from '@nestjs/swagger'; import { InjectRepository } from '@nestjs/typeorm'; import { plainToClass } from 'class-transformer'; -import { Repository } from 'typeorm'; +import { Repository, Like } from 'typeorm'; import { Roles } from '../decorators/roles.decorator'; import { InGroupDto } from '../dto/in-group.dto'; @@ -152,12 +152,17 @@ export class GroupsController { @Query('q') q ) { try { - const objects = await this.groupsRepository.findAndCount({ - skip: (curPage - 1) * perPage, - take: perPage, - relations: ['permissions'], - order: { id: 'DESC' } - }); + let objects: [Group[], number]; + let qb = this.groupsRepository.createQueryBuilder('group'); + qb = qb.leftJoinAndSelect('group.permissions', 'permission'); + qb = qb.leftJoinAndSelect('permission.contentType', 'contentType'); + if (q){ + qb = qb.where('group.title like :q or group.name like :q or group.id = :id', { q: `%${q}%`, id: +q }); + } + qb = qb.orderBy('group.id', 'DESC'); + qb = qb.skip((curPage - 1) * perPage) + .take(perPage); + objects = await qb.getManyAndCount(); return plainToClass(OutGroupsDto, { groups: objects[0], meta: { diff --git a/src/libs/core/controllers/permissions.controller.ts b/src/libs/core/controllers/permissions.controller.ts index 1482dbe6..f0fc85dd 100644 --- a/src/libs/core/controllers/permissions.controller.ts +++ b/src/libs/core/controllers/permissions.controller.ts @@ -164,6 +164,9 @@ export class PermissionsController { .leftJoin('permission.groups', 'group') .where('group.id = :group', { group: group }); } + if (q){ + qb = qb.where('permission.name like :q or permission.title like :q or permission.id = :id', { q: `%${q}%`, id: +q }); + } if (contentType) { qb = qb.where('contentType.id = :contentType', { contentType: contentType }); } diff --git a/src/libs/core/controllers/users.controller.ts b/src/libs/core/controllers/users.controller.ts index f096886b..50fd89e6 100644 --- a/src/libs/core/controllers/users.controller.ts +++ b/src/libs/core/controllers/users.controller.ts @@ -15,7 +15,7 @@ import { import { ApiBearerAuth, ApiImplicitParam, ApiImplicitQuery, ApiResponse, ApiUseTags } from '@nestjs/swagger'; import { InjectRepository } from '@nestjs/typeorm'; import { plainToClass } from 'class-transformer'; -import { Repository } from 'typeorm'; +import { Repository, Like } from 'typeorm'; import { Roles } from '../decorators/roles.decorator'; import { InUserDto } from '../dto/in-user.dto'; @@ -161,24 +161,24 @@ export class UsersController { ) { try { let objects: [User[], number]; - if (!group) { - objects = await this.usersRepository.findAndCount({ - skip: (curPage - 1) * perPage, - take: perPage, - relations: ['groups', 'groups.permissions'], - order: { id: 'DESC' } - }); - } else { - let qb = this.usersRepository.createQueryBuilder('user'); - if (group) { - qb = qb.leftJoinAndSelect('user.groups', 'group') - .where('group.id = :group', { group: group }) - } - qb = qb.orderBy('user.id', 'DESC'); - qb = qb.skip((curPage - 1) * perPage) - .take(perPage); - objects = await qb.getManyAndCount(); + let qb = this.usersRepository.createQueryBuilder('user'); + if (group) { + qb = qb.leftJoinAndSelect('user.groups', 'group') + .where('group.id = :group', { group: group }) + }else{ + qb = qb.leftJoinAndSelect('user.groups', 'group') + .where('group.id = :group', { group: group }); + qb = qb.leftJoinAndSelect('groups.permissions', 'permission'); + qb = qb.leftJoinAndSelect('permission.contentType', 'contentType'); + } + if (q){ + qb = qb.where('user.first_name like :q or user.last_name like :q or user.username like :q or user.id = :id', { q: `%${q}%`, id: +q }); } + qb = qb.orderBy('user.id', 'DESC'); + qb = qb.skip((curPage - 1) * perPage) + .take(perPage); + objects = await qb.getManyAndCount(); + return plainToClass(OutUsersDto, { users: objects[0], meta: {