ดักกรณี year = 0
This commit is contained in:
parent
2cef1f1b76
commit
ebc04fcae3
1 changed files with 22 additions and 12 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue