fix: add user deetail in get all user

This commit is contained in:
ilham 2021-12-16 17:28:56 +07:00
parent e43ec5129d
commit c3de4f56e1
2 changed files with 34 additions and 17 deletions

View File

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

View File

@ -160,18 +160,39 @@ export class UsersService {
});
}
findBySuperrior(superriorId: string, page: number) {
return this.usersRepository.findAndCount({
skip: page * 10,
take: 10,
relations: ['roles'],
where: {
async findBySuperrior(superriorId: string, page: number) {
const baseQuery = this.usersRepository
.createQueryBuilder('user')
.where('user.id != :id and user.superior_id = :superior', {
id: superriorId,
superior: superriorId,
},
order: {
updatedAt: 'DESC',
},
});
})
.leftJoinAndSelect('user.roles', 'roles', `roles.id = user.roles_id`)
.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) {