Merge branch 'development' into 'devops-staging'

fix: paging in membership

See merge request empatnusabangsa/ppob/ppob-backend!97
This commit is contained in:
ilham dwi pratama 2022-01-12 04:10:58 +00:00
commit cd478fe21d
2 changed files with 14 additions and 8 deletions

View File

@ -116,11 +116,13 @@ export class UsersController {
async findAll( async findAll(
@Request() req, @Request() req,
@Query('page') page: number, @Query('page') page: number,
@Query('pageSize') pageSize: number,
@Query('superior') superior: string, @Query('superior') superior: string,
@Query('type') type: string, @Query('type') type: string,
) { ) {
const data = await this.usersService.findAll( const data = await this.usersService.findAll(
page, page,
pageSize,
req.user.userId, req.user.userId,
superior == 'null' ? null : superior, superior == 'null' ? null : superior,
type == 'null' ? null : type, type == 'null' ? null : type,
@ -180,8 +182,12 @@ export class UsersController {
} }
@Get('find-by-supperior') @Get('find-by-supperior')
async findBySuperrior(@Request() req, @Query('page') page: number) { async findBySuperrior(
const data = await this.usersService.findBySuperrior(req.user.userId, page); @Request() req,
@Query('page') page: number,
@Query('pageSize') pageSize: number,
) {
const data = await this.usersService.findBySuperrior(req.user.userId, page, pageSize);
return { return {
...data, ...data,

View File

@ -130,7 +130,7 @@ export class UsersService {
return userData; return userData;
} }
async findAll(page: number, id: string, superior: string, type: string) { async findAll(page: number, pageSize: number, id: string, superior: string, type: string) {
const baseQuery = this.usersRepository const baseQuery = this.usersRepository
.createQueryBuilder('user') .createQueryBuilder('user')
.where('user.id != :id', { .where('user.id != :id', {
@ -176,8 +176,8 @@ export class UsersService {
const data = await baseQuery const data = await baseQuery
.orderBy('user.createdAt', 'DESC') .orderBy('user.createdAt', 'DESC')
.skip(page * 10) .skip(page * pageSize)
.take(10) .take(pageSize)
.getMany(); .getMany();
const totalData = await baseQuery.getCount(); const totalData = await baseQuery.getCount();
@ -246,7 +246,7 @@ export class UsersService {
}); });
} }
async findBySuperrior(superriorId: string, page: number) { async findBySuperrior(superriorId: string, page: number, pageSize: number) {
const baseQuery = this.usersRepository const baseQuery = this.usersRepository
.createQueryBuilder('user') .createQueryBuilder('user')
.where('user.id != :id and user.superior_id = :superior', { .where('user.id != :id and user.superior_id = :superior', {
@ -277,8 +277,8 @@ export class UsersService {
]); ]);
const data = await baseQuery const data = await baseQuery
.skip(page * 10) .skip(page * pageSize)
.take(10) .take(pageSize)
.getMany(); .getMany();
const totalData = await baseQuery.getCount(); const totalData = await baseQuery.getCount();