add filter in user

This commit is contained in:
Ilham Dwi Pratama S 2021-12-29 07:59:07 +07:00
parent af8f42c2d3
commit e882237a8a
2 changed files with 27 additions and 3 deletions

View File

@ -113,8 +113,18 @@ export class UsersController {
}
@Get()
async findAll(@Request() req, @Query('page') page: number) {
const data = await this.usersService.findAll(page, req.user.userId);
async findAll(
@Request() req,
@Query('page') page: number,
@Query('superior') superior: string,
@Query('type') type: string,
) {
const data = await this.usersService.findAll(
page,
req.user.userId,
superior == 'null' ? null : superior,
type == 'null' ? null : type,
);
return {
...data,

View File

@ -118,7 +118,7 @@ export class UsersService {
return userData;
}
async findAll(page: number, id: string) {
async findAll(page: number, id: string, superior: string, type: string) {
const baseQuery = this.usersRepository
.createQueryBuilder('user')
.where('user.id != :id', {
@ -148,6 +148,20 @@ export class UsersService {
'coa.amount',
]);
if(superior){
baseQuery.where('user.superior = :id_supperior',{
id_supperior:superior
})
}
if(type){
if(type == 'partner'){
baseQuery.where('user.partner_id is not null')
} else {
baseQuery.where('user.partner_id is null')
}
}
const data = await baseQuery
.orderBy('user.createdAt', 'DESC')
.skip(page * 10)