add find user by roles

This commit is contained in:
Ilham Dwi Pratama S 2021-12-08 11:06:26 +07:00
parent a418e74db5
commit 10984f65a5
4 changed files with 34 additions and 3 deletions

View File

@ -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;
}

View File

@ -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';

View File

@ -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 {

View File

@ -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);
}