fix total

This commit is contained in:
AdisakKanthawilang 2024-02-27 10:09:51 +07:00
parent bf12751bfa
commit 906edd7050
3 changed files with 9 additions and 22 deletions

View file

@ -156,8 +156,7 @@ export class SalaryRanksController extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
//ssss total ผิด
// try {
const [salaryRank, total] = await this.salaryRankRepository.findAndCount({
where: {
salaryId: id,
@ -177,8 +176,7 @@ export class SalaryRanksController extends Controller {
salary: "DESC",
salaryHalf: "DESC",
},
skip: (page - 1) * pageSize,
take: pageSize,
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
});
if (keyword != undefined && keyword !== "") {
const filteredSalaryRank = salaryRank.filter(
@ -191,12 +189,10 @@ export class SalaryRanksController extends Controller {
x.salaryFullHalf?.toString().includes(keyword) ||
x.salaryFullHalfSpecial?.toString().includes(keyword),
);
return new HttpSuccess({ data: filteredSalaryRank, total: filteredSalaryRank.length });
const slicedData = filteredSalaryRank.slice((page - 1) * pageSize, page * pageSize);
return new HttpSuccess({ data: slicedData, total: filteredSalaryRank.length });
}
return new HttpSuccess({ data: salaryRank, total });
// } catch (error: any) {
// throw new Error(error);
// }
}
}