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

@ -280,15 +280,12 @@ export class Salary extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
//ssss total ผิด
// try {
const [salary, total] = await this.salaryRepository.findAndCount({
relations: ["posLevel_", "posType_"],
order: {
startDate: "DESC",
},
skip: (page - 1) * pageSize,
take: pageSize,
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
});
if (keyword != undefined && keyword !== "") {
const filteredSalary = salary.filter(
@ -318,8 +315,8 @@ export class Salary extends Controller {
endDate: item.endDate,
details: item.details,
}));
return new HttpSuccess({ data: formattedData, total: formattedData.length });
const slicedData = formattedData.slice((page - 1) * pageSize, page * pageSize);
return new HttpSuccess({ data: slicedData, total: formattedData.length });
}
const formattedData = salary.map((item) => ({
@ -337,9 +334,7 @@ export class Salary extends Controller {
details: item.details,
}));
return new HttpSuccess({ data: formattedData, total });
// } catch (error: any) {
// throw new Error(error);
// }
}
/**

View file

@ -43,12 +43,8 @@ export class SalaryPeriodController extends Controller {
@Body() requestBody: CreateSalaryPeriod,
@Request() request: { user: Record<string, any> },
) {
//ssss ไม่ต้องเช็ค?
const salaryPeriod = Object.assign(new SalaryPeriod(), requestBody);
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chk_toUpper = ["SPECIAL", "APR", "OCT"];
if (!chk_toUpper.includes(salaryPeriod.period.toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง");

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);
// }
}
}