fix: add user deetail in get all user
This commit is contained in:
parent
e43ec5129d
commit
c3de4f56e1
|
@ -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',
|
||||||
};
|
};
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user