From af8f42c2d32190f475ccf3f0d8938a5e42aab97e Mon Sep 17 00:00:00 2001 From: Ilham Dwi Pratama S Date: Wed, 29 Dec 2021 07:21:32 +0700 Subject: [PATCH 1/2] add: pageSize in findAllForPartner --- src/product/product.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 1e8dc17..a258c5a 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -336,8 +336,8 @@ export class ProductService { } const data = await baseQuery - .offset(page * 10) - .limit(10) + .offset(page * pageSize) + .limit(pageSize) .getRawMany(); const totalData = await baseQuery.getCount(); From e882237a8ac5386db2f91b58fd9e60549fa8b548 Mon Sep 17 00:00:00 2001 From: Ilham Dwi Pratama S Date: Wed, 29 Dec 2021 07:59:07 +0700 Subject: [PATCH 2/2] add filter in user --- src/users/users.controller.ts | 14 ++++++++++++-- src/users/users.service.ts | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index eec7377..37dce66 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -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, diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 939af19..cd948cd 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -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)