diff --git a/src/controllers/SalaryController.ts b/src/controllers/SalaryController.ts index 392b402..9d154a9 100644 --- a/src/controllers/SalaryController.ts +++ b/src/controllers/SalaryController.ts @@ -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); - // } + } /** diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 303f1e4..d244350 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -43,12 +43,8 @@ export class SalaryPeriodController extends Controller { @Body() requestBody: CreateSalaryPeriod, @Request() request: { user: Record }, ) { - //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, "ประเภทผัง ไม่ถูกต้อง"); diff --git a/src/controllers/SalaryRankController.ts b/src/controllers/SalaryRankController.ts index be6d3f0..6fe0e39 100644 --- a/src/controllers/SalaryRankController.ts +++ b/src/controllers/SalaryRankController.ts @@ -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); - // } } }