|
@@ -7,7 +7,7 @@ import {
|
|
|
InternalServerErrorException,
|
|
InternalServerErrorException,
|
|
|
UnauthorizedException
|
|
UnauthorizedException
|
|
|
} from '@nestjs/common'
|
|
} from '@nestjs/common'
|
|
|
-import { In, Repository, UpdateResult, MoreThanOrEqual, LessThanOrEqual, And } from 'typeorm'
|
|
|
|
|
|
|
+import { In, Repository, UpdateResult, MoreThanOrEqual, LessThanOrEqual, And, Raw } from 'typeorm'
|
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
|
import { Users } from './entities/users.entity'
|
|
import { Users } from './entities/users.entity'
|
|
|
import { IUsers } from './interfaces/users.interface'
|
|
import { IUsers } from './interfaces/users.interface'
|
|
@@ -24,7 +24,7 @@ import { Role } from '../model/role.enum'
|
|
|
import { PageRequest } from '../common/dto/page-request'
|
|
import { PageRequest } from '../common/dto/page-request'
|
|
|
import { th } from 'date-fns/locale'
|
|
import { th } from 'date-fns/locale'
|
|
|
import { startOfDay, endOfDay, addDays, format } from 'date-fns'
|
|
import { startOfDay, endOfDay, addDays, format } from 'date-fns'
|
|
|
-import { where } from 'sequelize'
|
|
|
|
|
|
|
+import { where, FindOptions } from 'sequelize'
|
|
|
|
|
|
|
|
@Injectable()
|
|
@Injectable()
|
|
|
export class UsersService {
|
|
export class UsersService {
|
|
@@ -38,6 +38,12 @@ export class UsersService {
|
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
async findAll(req: PageRequest<Users>): Promise<Pagination<Users>> {
|
|
async findAll(req: PageRequest<Users>): Promise<Pagination<Users>> {
|
|
|
|
|
+ let where = (req as any).search?.where
|
|
|
|
|
+ if (where?.roles) {
|
|
|
|
|
+ where.roles = Raw((alias) => `find_in_set(:value, ${alias})`, {
|
|
|
|
|
+ value: where.roles
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
return await paginate<Users>(this.userRepository, req.page, req.search)
|
|
return await paginate<Users>(this.userRepository, req.page, req.search)
|
|
|
}
|
|
}
|
|
|
|
|
|