fixed condition check
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m6s

This commit is contained in:
Warunee Tamkoo 2026-05-08 14:47:58 +07:00
parent 1c5faecf04
commit 7104ce4f34

View file

@ -31,7 +31,6 @@ export class RetirementService {
}; };
try { try {
// หาวันที่ 1 ตุลาคมของปีปัจจุบัน // หาวันที่ 1 ตุลาคมของปีปัจจุบัน
const now = new Date(); const now = new Date();
const currentYear = now.getFullYear(); const currentYear = now.getFullYear();
@ -50,7 +49,7 @@ export class RetirementService {
}); });
// Filter เอาเฉพาะวันที่ 1 ตุลาคมเท่านั้น // Filter เอาเฉพาะวันที่ 1 ตุลาคมเท่านั้น
const filteredProfiles = profiles.filter(p => { const filteredProfiles = profiles.filter((p) => {
if (!p.leaveDate) return false; if (!p.leaveDate) return false;
const leaveDate = new Date(p.leaveDate); const leaveDate = new Date(p.leaveDate);
return ( return (
@ -87,11 +86,10 @@ export class RetirementService {
}; };
result.failedProfiles.push(errorInfo); result.failedProfiles.push(errorInfo);
} }
}) }),
); );
} }
} }
} catch (error: any) { } catch (error: any) {
// Log error but don't throw - allow cronjob to complete with partial results // Log error but don't throw - allow cronjob to complete with partial results
console.error("[cronjobPostRetireToExprofile] Error:", error); console.error("[cronjobPostRetireToExprofile] Error:", error);
@ -118,7 +116,7 @@ export class RetirementService {
const retireYear = retireDate.getFullYear(); const retireYear = retireDate.getFullYear();
// Validate date is valid // Validate date is valid
if (isNaN(retireYear) || retireYear < 2000 || retireYear > 2100) { if (isNaN(retireYear) || retireYear < 2000) {
throw new Error(`Invalid leaveDate for profile ${profile.id}: ${profile.leaveDate}`); throw new Error(`Invalid leaveDate for profile ${profile.id}: ${profile.leaveDate}`);
} }
@ -135,7 +133,7 @@ export class RetirementService {
profile.posLevel?.posLevelName || "", profile.posLevel?.posLevelName || "",
retireDate, retireDate,
profile.org || "", profile.org || "",
profile.leaveReason || "เกษียณอายุราชการ" profile.leaveReason || "เกษียณอายุราชการ",
); );
} }
} }