Merge branch 'development' into 'devops-staging'

Development

See merge request empatnusabangsa/ppob/ppob-backend!28
This commit is contained in:
ilham dwi pratama 2021-12-16 10:30:37 +00:00
commit 09947acad0
2 changed files with 34 additions and 17 deletions

View File

@ -149,14 +149,10 @@ export class UsersController {
@Get('find-by-supperior') @Get('find-by-supperior')
async findBySuperrior(@Request() req, @Query('page') page: number) { async findBySuperrior(@Request() req, @Query('page') page: number) {
const [data, count] = await this.usersService.findBySuperrior( const data = await this.usersService.findBySuperrior(req.user.userId, page);
req.user.userId,
page,
);
return { return {
data, ...data,
count,
statusCode: HttpStatus.OK, statusCode: HttpStatus.OK,
message: 'success', message: 'success',
}; };

View File

@ -160,18 +160,39 @@ export class UsersService {
}); });
} }
findBySuperrior(superriorId: string, page: number) { async findBySuperrior(superriorId: string, page: number) {
return this.usersRepository.findAndCount({ const baseQuery = this.usersRepository
skip: page * 10, .createQueryBuilder('user')
take: 10, .where('user.id != :id and user.superior_id = :superior', {
relations: ['roles'], id: superriorId,
where: {
superior: superriorId, superior: superriorId,
}, })
order: { .leftJoinAndSelect('user.roles', 'roles', `roles.id = user.roles_id`)
updatedAt: 'DESC', .leftJoinAndMapOne(
}, 'user.user_detail',
}); UserDetail,
'user_detail',
`user_detail.user = user.id`,
)
.select([
'user.id',
'user.username',
'user.isActive',
'roles.name',
'user_detail',
]);
const data = await baseQuery
.skip(page * 10)
.take(10)
.getMany();
const totalData = await baseQuery.getCount();
return {
data,
count: totalData,
};
} }
async findExist(id: string) { async findExist(id: string) {