From ebc04fcae39fc77aed62c706eb4abaa0309bbc94 Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 23 Feb 2024 12:13:12 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=94=E0=B8=B1=E0=B8=81=E0=B8=81=E0=B8=A3?= =?UTF-8?q?=E0=B8=93=E0=B8=B5=20=20year=20=3D=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 34 +++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 7cc0be5..9e118fc 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -178,25 +178,35 @@ export class SalaryPeriodController extends Controller { @Query("keyword") keyword?: string, @Query("year") year: number = 2024, ) { - const startOfYear = new Date(year, 0, 1); - const endOfYear = new Date(year, 11, 31); - const [salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({ - skip: (page - 1) * pageSize, - take: pageSize, - where: { - effectiveDate: Between(startOfYear, endOfYear) - } - }); + + let salaryPeriod: any + let total: any + if(year != 0){ + const startOfYear = new Date(year, 0, 1); + const endOfYear = new Date(year, 11, 31); + [salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({ + skip: (page - 1) * pageSize, + take: pageSize, + where: { + effectiveDate: Between(startOfYear, endOfYear) + } + }); + }else{ + [salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({ + skip: (page - 1) * pageSize, + take: pageSize, + }); + } if (keyword != undefined && keyword !== "") { const filteredSalaryPeriod = salaryPeriod.filter( - (x) => + (x:any) => x.period.toString().includes(keyword) || x.isActive.toString().includes(keyword) || x.effectiveDate.getFullYear().toString().includes(keyword) ); - const formattedData = filteredSalaryPeriod.map((item) => ({ + const formattedData = filteredSalaryPeriod.map((item:any) => ({ id: item.id, period: item.period, isActive: item.isActive, @@ -210,7 +220,7 @@ export class SalaryPeriodController extends Controller { return new HttpSuccess([]); } - const formattedData = salaryPeriod.map((item) => ({ + const formattedData = salaryPeriod.map((item:any) => ({ id: item.id, period: item.period, isActive: item.isActive,