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,