From 2f17c100506b0c028507b4121ee9c8c0a746a703 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 18 Jun 2026 16:26:27 +0700 Subject: [PATCH] fix error #224 --- src/services/OfficerProfileService.ts | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/services/OfficerProfileService.ts b/src/services/OfficerProfileService.ts index fae024d3..2225e7c4 100644 --- a/src/services/OfficerProfileService.ts +++ b/src/services/OfficerProfileService.ts @@ -180,6 +180,46 @@ export class OfficerProfileService { console.log("[OfficerProfileService] Starting executeCreateOfficerProfile"); console.log("[OfficerProfileService] Request body count:", data?.length); + // ───────────────────────────────────────────────────────────── + // Normalize date fields + // ผ่าน HTTP endpoint → tsoa แปลง ISO string → Date ให้อัตโนมัติ + // แต่ผ่าน RabbitMQ handler (axios) → จะได้ string → ต้องแปลงเอง + // ไม่งั้น calculateRetireDate/getFullYear ฯลฯ จะพัง + // ───────────────────────────────────────────────────────────── + const toDate = (v: any): Date | null => { + if (v == null || v === "") return null; + if (v instanceof Date) return isNaN(v.getTime()) ? null : v; + const d = new Date(v); + return isNaN(d.getTime()) ? null : d; + }; + for (const item of data ?? []) { + const bp = item.bodyProfile as any; + if (bp) { + bp.birthDate = toDate(bp.birthDate); + bp.dateStart = toDate(bp.dateStart); + bp.dateAppoint = toDate(bp.dateAppoint); + bp.dateRetire = toDate(bp.dateRetire); + } + const bs = item.bodySalarys as any; + if (bs) { + bs.commandDateAffect = toDate(bs.commandDateAffect); + bs.commandDateSign = toDate(bs.commandDateSign); + } + if (item.bodyEducations) { + for (const edu of item.bodyEducations as any[]) { + edu.startDate = toDate(edu.startDate); + edu.endDate = toDate(edu.endDate); + edu.finishDate = toDate(edu.finishDate); + } + } + if (item.bodyCertificates) { + for (const cer of item.bodyCertificates as any[]) { + cer.expireDate = toDate(cer.expireDate); + cer.issueDate = toDate(cer.issueDate); + } + } + } + const req = ctx.req; const roleKeycloak = await this.roleKeycloakRepo.findOne({ where: { name: Like("USER") },