add find user by roles
This commit is contained in:
		| @@ -1,4 +1,4 @@ | |||||||
| import { IsNotEmpty } from 'class-validator'; | import { IsNotEmpty, IsUUID } from 'class-validator'; | ||||||
|  |  | ||||||
| export class CreateUserDto { | export class CreateUserDto { | ||||||
|   @IsNotEmpty() |   @IsNotEmpty() | ||||||
| @@ -6,4 +6,10 @@ export class CreateUserDto { | |||||||
|  |  | ||||||
|   @IsNotEmpty() |   @IsNotEmpty() | ||||||
|   password: string; |   password: string; | ||||||
|  |  | ||||||
|  |   @IsUUID() | ||||||
|  |   roleId: string; | ||||||
|  |  | ||||||
|  |   @IsUUID() | ||||||
|  |   superior: string; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ import { Roles } from 'src/configurable/entities/roles.entity'; | |||||||
| import { | import { | ||||||
|   Entity, |   Entity, | ||||||
|   Column, |   Column, | ||||||
|   PrimaryGeneratedColumn, BeforeInsert, ManyToOne, |   PrimaryGeneratedColumn, ManyToOne, | ||||||
| } from 'typeorm'; | } from 'typeorm'; | ||||||
| import { BaseModel } from '../../config/basemodel.entity'; | import { BaseModel } from '../../config/basemodel.entity'; | ||||||
| import { hashPassword } from '../../helper/hash_password'; | import { hashPassword } from '../../helper/hash_password'; | ||||||
|   | |||||||
| @@ -42,6 +42,18 @@ export class UsersController { | |||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   @Get('find-by-roles/:id') | ||||||
|  |   async findByRoles( | ||||||
|  |       @Param('id', ParseUUIDPipe) id: string, | ||||||
|  |       @Query('page') page: number | ||||||
|  |       ) { | ||||||
|  |     return { | ||||||
|  |       data: await this.usersService.findByRoles(id,page), | ||||||
|  |       statusCode: HttpStatus.OK, | ||||||
|  |       message: 'success', | ||||||
|  |     }; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   @Get(':id') |   @Get(':id') | ||||||
|   async findOne(@Param('id', ParseUUIDPipe) id: string) { |   async findOne(@Param('id', ParseUUIDPipe) id: string) { | ||||||
|     return { |     return { | ||||||
|   | |||||||
| @@ -38,6 +38,19 @@ export class UsersService { | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   findByRoles(relationId:string,page:number) { | ||||||
|  |     return this.usersRepository.findAndCount({ | ||||||
|  |       skip: page * 10, | ||||||
|  |       take: 10, | ||||||
|  |       where:{ | ||||||
|  |         roles:relationId | ||||||
|  |       }, | ||||||
|  |       order: { | ||||||
|  |         updatedAt: 'DESC', | ||||||
|  |       }, | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   async findOne(id: string) { |   async findOne(id: string) { | ||||||
|     const coa = await this.coaService.findByUser(id,coaType.WALLET); |     const coa = await this.coaService.findByUser(id,coaType.WALLET); | ||||||
|     try { |     try { | ||||||
| @@ -83,7 +96,7 @@ export class UsersService { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const result = await this.usersRepository.update(id, updateUserDto); |     // const result = await this.usersRepository.update(id, updateUserDto); | ||||||
|  |  | ||||||
|     return this.usersRepository.findOneOrFail(id); |     return this.usersRepository.findOneOrFail(id); | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user