add filter in user
This commit is contained in:
parent
af8f42c2d3
commit
e882237a8a
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user