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:34 +00:00
commit 6ace9926fe
2 changed files with 14 additions and 8 deletions

View File

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

View File

@ -130,7 +130,7 @@ export class UsersService {
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
.createQueryBuilder('user')
.where('user.id != :id', {
@ -176,8 +176,8 @@ export class UsersService {
const data = await baseQuery
.orderBy('user.createdAt', 'DESC')
.skip(page * 10)
.take(10)
.skip(page * pageSize)
.take(pageSize)
.getMany();
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
.createQueryBuilder('user')
.where('user.id != :id and user.superior_id = :superior', {
@ -277,8 +277,8 @@ export class UsersService {
]);
const data = await baseQuery
.skip(page * 10)
.take(10)
.skip(page * pageSize)
.take(pageSize)
.getMany();
const totalData = await baseQuery.getCount();