From ace9962a6fdff6ca895fc848aedef5e9f226c1af Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 30 Jul 2025 10:46:01 +0700 Subject: [PATCH] #1704 --- .../ProfileGovernmentController.ts | 66 ++++++++--------- .../ProfileGovernmentEmployeeController.ts | 72 +++++++++---------- 2 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 7e8c4e2a..6f63bd0e 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -213,7 +213,7 @@ export class ProfileGovernmentHistoryController extends Controller { }, }); - if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, @@ -248,31 +248,31 @@ export class ProfileGovernmentHistoryController extends Controller { } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: record.isLeave == false ? org : orgLeave, //สังกัด + org: record?.isLeave == false ? org : orgLeave, //สังกัด positionField: position == null ? null : position.positionField, //สายงาน - position: record.position, //ตำแหน่ง - posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ - posMasterNo: record.isLeave == false + position: record?.position, //ตำแหน่ง + posLevel: record?.posLevel == null ? null : record?.posLevel.posLevelName, //ระดับ + posMasterNo: record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record.profileSalary.length > 0 - ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : record && record?.profileSalary.length > 0 + ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` : null, //เลขที่ตำแหน่ง - posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท + posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท posExecutive: position == null || position.posExecutive == null ? null : position.posExecutive.posExecutiveName, //ตำแหน่งทางการบริหาร positionArea: position == null ? null : position.positionArea, //ด้าน/สาขา positionExecutiveField: position == null ? null : position.positionExecutiveField, //ด้านทางการบริหาร - dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), - dateRetireLaw: record.dateRetireLaw ?? null, - // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), + dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), + dateRetireLaw: record?.dateRetireLaw ?? null, + // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), govAge: await calculateGovAge(profileId, "OFFICER"), - dateAppoint: record.dateAppoint, - dateStart: record.dateStart, - govAgeAbsent: record.govAgeAbsent, - govAgePlus: record.govAgePlus, - reasonSameDate: record.reasonSameDate, + dateAppoint: record?.dateAppoint, + dateStart: record?.dateStart, + govAgeAbsent: record?.govAgeAbsent, + govAgePlus: record?.govAgePlus, + reasonSameDate: record?.reasonSameDate, }; return new HttpSuccess(data); @@ -349,7 +349,7 @@ export class ProfileGovernmentHistoryController extends Controller { }, }); - if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, @@ -384,35 +384,35 @@ export class ProfileGovernmentHistoryController extends Controller { } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: record.isLeave == false ? org : orgLeave, //สังกัด + org: record?.isLeave == false ? org : orgLeave, //สังกัด positionField: position == null ? null : position.positionField, //สายงาน - position: record.position, //ตำแหน่ง - posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ + position: record?.position, //ตำแหน่ง + posLevel: record?.posLevel == null ? null : record?.posLevel.posLevelName, //ระดับ posMasterNo: - record.isLeave == false + record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record?.profileSalary.length > 0 - ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : record && record.profileSalary.length > 0 + ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` : null, //เลขที่ตำแหน่ง - posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท + posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท posExecutive: position == null || position.posExecutive == null ? null : position.posExecutive.posExecutiveName, //ตำแหน่งทางการบริหาร positionArea: position == null ? null : position.positionArea, //ด้าน/สาขา positionExecutiveField: position == null ? null : position.positionExecutiveField, //ด้านทางการบริหาร - dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), - dateRetireLaw: record.dateRetireLaw ?? null, - // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), + dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), + dateRetireLaw: record?.dateRetireLaw ?? null, + // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), govAge: await calculateGovAge(profileId, "OFFICER"), - dateAppoint: record.dateAppoint, - dateStart: record.dateStart, - govAgeAbsent: record.govAgeAbsent, - govAgePlus: record.govAgePlus, - reasonSameDate: record.reasonSameDate, - isLeave: record.isLeave + dateAppoint: record?.dateAppoint, + dateStart: record?.dateStart, + govAgeAbsent: record?.govAgeAbsent, + govAgePlus: record?.govAgePlus, + reasonSameDate: record?.reasonSameDate, + isLeave: record?.isLeave }; return new HttpSuccess(data); diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 32c32006..f93c96f0 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -192,7 +192,7 @@ export class ProfileGovernmentEmployeeController extends Controller { }, }); - if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, @@ -227,28 +227,28 @@ export class ProfileGovernmentEmployeeController extends Controller { } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: record.isLeave == false ? org : orgLeave, //สังกัด - position: record.position, //ตำแหน่ง + org: record?.isLeave == false ? org : orgLeave, //สังกัด + position: record?.position, //ตำแหน่ง posLevel: - record.posLevel == null + record?.posLevel == null ? null : `${record?.posType?.posTypeShortName ?? ""} ${record?.posLevel?.posLevelName ?? ""}`, //ระดับ - posMasterNo: record.isLeave == false + posMasterNo: record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record.profileSalary.length > 0 - ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : record && record?.profileSalary.length > 0 + ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` : null, //เลขที่ตำแหน่ง - posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท - dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), //วันเกษียณ - dateAppoint: record.dateAppoint, //วันที่สั่งบรรจุ - dateStart: record.dateStart, //วันที่เริ่มปฎิบัติงานราชการ - reasonSameDate: record.reasonSameDate, //เหตุผลที่วันที่ไม่ตรงกัน - dateRetire: record.dateRetire ?? null, //วันครบเกษียณอายุ - // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), //อายุราชการ + posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท + dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), //วันเกษียณ + dateAppoint: record?.dateAppoint, //วันที่สั่งบรรจุ + dateStart: record?.dateStart, //วันที่เริ่มปฎิบัติงานราชการ + reasonSameDate: record?.reasonSameDate, //เหตุผลที่วันที่ไม่ตรงกัน + dateRetire: record?.dateRetire ?? null, //วันครบเกษียณอายุ + // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), //อายุราชการ govAge: await calculateGovAge(profileEmployeeId, "EMPLOYEE"), - govAgeAbsent: record.govAgeAbsent ?? null, // ขาดราชการ - govAgePlus: record.govAgePlus, // อายุราชการเกื้อกูล - dateRetireLaw: record.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย + govAgeAbsent: record?.govAgeAbsent ?? null, // ขาดราชการ + govAgePlus: record?.govAgePlus, // อายุราชการเกื้อกูล + dateRetireLaw: record?.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย }; return new HttpSuccess(data); } @@ -305,7 +305,7 @@ export class ProfileGovernmentEmployeeController extends Controller { }, }); - if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, @@ -340,31 +340,31 @@ export class ProfileGovernmentEmployeeController extends Controller { } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: record.isLeave == false ? org : orgLeave, //สังกัด - position: record.position, //ตำแหน่ง - posLevel: record.posLevel == null && record.posType == null + org: record?.isLeave == false ? org : orgLeave, //สังกัด + position: record?.position, //ตำแหน่ง + posLevel: record?.posLevel == null && record?.posType == null ? null - : `${record.posType.posTypeShortName} ${record.posLevel.posLevelName}`, //ระดับ + : `${record?.posType.posTypeShortName} ${record?.posLevel.posLevelName}`, //ระดับ posMasterNo: - record.isLeave == false + record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record?.profileSalary.length > 0 - ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : record && record.profileSalary.length > 0 + ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` : null, //เลขที่ตำแหน่ง - posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท - dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), //วันเกษียณ - dateAppoint: record.dateAppoint, //วันที่สั่งบรรจุ - dateStart: record.dateStart, //วันที่เริ่มปฎิบัติงานราชการ - reasonSameDate: record.reasonSameDate, //เหตุผลที่วันที่ไม่ตรงกัน - dateRetire: record.dateRetire ?? null, //วันครบเกษียณอายุ - // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), //อายุราชการ + posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท + dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), //วันเกษียณ + dateAppoint: record?.dateAppoint, //วันที่สั่งบรรจุ + dateStart: record?.dateStart, //วันที่เริ่มปฎิบัติงานราชการ + reasonSameDate: record?.reasonSameDate, //เหตุผลที่วันที่ไม่ตรงกัน + dateRetire: record?.dateRetire ?? null, //วันครบเกษียณอายุ + // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), //อายุราชการ govAge: await calculateGovAge(profileEmployeeId, "EMPLOYEE"), - govAgeAbsent: record.govAgeAbsent ?? null, // ขาดราชการ - govAgePlus: record.govAgePlus, // อายุราชการเกื้อกูล - dateRetireLaw: record.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย - isLeave: record.isLeave + govAgeAbsent: record?.govAgeAbsent ?? null, // ขาดราชการ + govAgePlus: record?.govAgePlus, // อายุราชการเกื้อกูล + dateRetireLaw: record?.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย + isLeave: record?.isLeave }; return new HttpSuccess(data); }