diff --git a/src/users/dto/create-user.dto.ts b/src/users/dto/create-user.dto.ts index f6c8301..2147aed 100644 --- a/src/users/dto/create-user.dto.ts +++ b/src/users/dto/create-user.dto.ts @@ -1,4 +1,4 @@ -import { IsNotEmpty } from 'class-validator'; +import { IsNotEmpty, IsUUID } from 'class-validator'; export class CreateUserDto { @IsNotEmpty() @@ -6,4 +6,10 @@ export class CreateUserDto { @IsNotEmpty() password: string; + + @IsUUID() + roleId: string; + + @IsUUID() + superior: string; } diff --git a/src/users/entities/user.entity.ts b/src/users/entities/user.entity.ts index 17cea15..e23355a 100644 --- a/src/users/entities/user.entity.ts +++ b/src/users/entities/user.entity.ts @@ -2,7 +2,7 @@ import { Roles } from 'src/configurable/entities/roles.entity'; import { Entity, Column, - PrimaryGeneratedColumn, BeforeInsert, ManyToOne, + PrimaryGeneratedColumn, ManyToOne, } from 'typeorm'; import { BaseModel } from '../../config/basemodel.entity'; import { hashPassword } from '../../helper/hash_password'; diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index f7a7c76..06e5902 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -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') async findOne(@Param('id', ParseUUIDPipe) id: string) { return { diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 5c01f87..af76258 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -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) { const coa = await this.coaService.findByUser(id,coaType.WALLET); 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); }