From a3d9d40a529d3c379f7e7475c7f95128830f4914 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 11 Feb 2026 11:31:09 +0700 Subject: [PATCH] api getProfile (No token) --- .../OrganizationDotnetController.ts | 61 +- .../OrganizationUnauthorizeController.ts | 676 +++++++++++++++++- 2 files changed, 707 insertions(+), 30 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 1d4ef30a..16566685 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -2345,8 +2345,6 @@ export class OrganizationDotnetController extends Controller { relations: [ "posLevel", "posType", - "profileSalary", - "profileInsignias", "current_holders", "current_holders.orgRevision", "current_holders.orgRoot", @@ -2356,14 +2354,6 @@ export class OrganizationDotnetController extends Controller { "current_holders.orgChild4", ], where: { id: profileId }, - order: { - profileSalary: { - commandDateAffect: "DESC", - }, - profileInsignias: { - receiveDate: "DESC", - }, - }, }); if (!profile) { @@ -2371,8 +2361,6 @@ export class OrganizationDotnetController extends Controller { relations: [ "posLevel", "posType", - "profileSalary", - "profileInsignias", "current_holders", "current_holders.orgRevision", "current_holders.orgRoot", @@ -2382,17 +2370,20 @@ export class OrganizationDotnetController extends Controller { "current_holders.orgChild4", ], where: { id: profileId }, - order: { - profileSalary: { - commandDateAffect: "DESC", - }, - profileInsignias: { - receiveDate: "DESC", - }, - }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const [latestSalary, latestInsignia] = await Promise.all([ + this.salaryRepo.findOne({ + where: { profileEmployeeId: profile.id }, + order: { commandDateAffect: "DESC" }, + }), + this.insigniaRepo.findOne({ + where: { profileEmployeeId: profile.id }, + order: { receiveDate: "DESC" }, + }), + ]); + const org = { root: profile?.current_holders?.find( @@ -2426,7 +2417,7 @@ export class OrganizationDotnetController extends Controller { )?.orgChild4?.id ?? null, }; let fullname = ""; - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { current_holder: Not(IsNull()), @@ -2450,7 +2441,7 @@ export class OrganizationDotnetController extends Controller { " " + pos.current_holder.lastName; } else { - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { current_holder: Not(IsNull()), @@ -2473,7 +2464,7 @@ export class OrganizationDotnetController extends Controller { " " + pos.current_holder.lastName; } else { - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { current_holder: Not(IsNull()), @@ -2496,7 +2487,7 @@ export class OrganizationDotnetController extends Controller { " " + pos.current_holder.lastName; } else { - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { current_holder: Not(IsNull()), @@ -2519,7 +2510,7 @@ export class OrganizationDotnetController extends Controller { " " + pos.current_holder.lastName; } else { - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { current_holder: Not(IsNull()), @@ -2689,14 +2680,25 @@ export class OrganizationDotnetController extends Controller { ? "" : profile.posType?.posTypeShortName + " ") + (profile.posLevel?.posLevelName ?? ""), posType: profile.posType?.posTypeName ?? null, - profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null, - profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null, + profileSalary: latestSalary ?? null, + profileInsignia: latestInsignia ?? null, profileType: "EMPLOYEE", }; return new HttpSuccess(mapProfile); } + const [latestSalary, latestInsignia] = await Promise.all([ + this.salaryRepo.findOne({ + where: { profileId: profile.id }, + order: { commandDateAffect: "DESC" }, + }), + this.insigniaRepo.findOne({ + where: { profileId: profile.id }, + order: { receiveDate: "DESC" }, + }), + ]); + const org = { root: profile?.current_holders?.find( @@ -2991,13 +2993,14 @@ export class OrganizationDotnetController extends Controller { commander: fullname, posLevel: profile.posLevel?.posLevelName ?? null, posType: profile.posType?.posTypeName ?? null, - profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null, - profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null, + profileSalary: latestSalary ?? null, + profileInsignia: latestInsignia ?? null, profileType: "OFFICER", }; return new HttpSuccess(mapProfile); } + /** * 3. API Get Profile จาก citizen Id * diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index dfd26df5..d2ec617d 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -22,6 +22,8 @@ import Extension from "../interfaces/extension"; import { resetPassword } from "../keycloak"; import { viewEmployeePosMaster } from "../entities/view/viewEmployeePosMaster"; import { EmployeePosDict } from "../entities/EmployeePosDict"; +import { ProfileSalary } from "../entities/ProfileSalary"; +import { ProfileInsignia } from "../entities/ProfileInsignia"; @Route("api/v1/org/unauthorize") @Tags("OrganizationUnauthorize") @Response( @@ -39,7 +41,10 @@ export class OrganizationUnauthorizeController extends Controller { viewProfileEmployeeEvaluation, ); private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict); - + private posMasterRepository = AppDataSource.getRepository(PosMaster); + private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); + private salaryRepo = AppDataSource.getRepository(ProfileSalary); + private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); @Post("user/reset-password") async forgetPassword( @Body() @@ -1036,6 +1041,675 @@ export class OrganizationUnauthorizeController extends Controller { return new HttpSuccess(findRevision.id); } + /** + * API Get Profile จาก profile id + * + * @summary API Get Profile จาก profile id + * + * @param {string} profileId Id profile + */ + @Get("profile/{profileId}") + async GetProfileByProfileIdAsync(@Path() profileId: string) { + const profile = await this.profileRepo.findOne({ + relations: [ + "posLevel", + "posType", + "current_holders", + "current_holders.orgRevision", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + where: { id: profileId }, + }); + + if (!profile) { + const profile = await this.profileEmpRepo.findOne({ + relations: [ + "posLevel", + "posType", + "current_holders", + "current_holders.orgRevision", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + where: { id: profileId }, + }); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const [latestSalary, latestInsignia] = await Promise.all([ + this.salaryRepo.findOne({ + where: { profileEmployeeId: profile.id }, + order: { commandDateAffect: "DESC" }, + }), + this.insigniaRepo.findOne({ + where: { profileEmployeeId: profile.id }, + order: { receiveDate: "DESC" }, + }), + ]); + + const org = { + root: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRoot?.id ?? null, + child1: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild1?.id ?? null, + child2: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2?.id ?? null, + child3: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3?.id ?? null, + child4: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4?.id ?? null, + }; + let fullname = ""; + let pos = await this.empPosMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + isDirector: true, + orgRootId: org?.root ?? "", + orgChild1Id: org?.child1 ?? "", + orgChild2Id: org?.child2 ?? "", + orgChild3Id: org?.child3 ?? "", + orgChild4Id: org?.child4 ?? "", + }, + }); + + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + let pos = await this.empPosMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + isDirector: true, + orgRootId: org?.root ?? "", + orgChild1Id: org?.child1 ?? "", + orgChild2Id: org?.child2 ?? "", + orgChild3Id: org?.child3 ?? "", + orgChild4Id: IsNull(), + }, + }); + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + let pos = await this.empPosMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + isDirector: true, + orgRootId: org?.root ?? "", + orgChild1Id: org?.child1 ?? "", + orgChild2Id: org?.child2 ?? "", + orgChild3Id: IsNull(), + orgChild4Id: IsNull(), + }, + }); + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + let pos = await this.empPosMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + isDirector: true, + orgRootId: org?.root ?? "", + orgChild1Id: org?.child1 ?? "", + orgChild2Id: IsNull(), + orgChild3Id: IsNull(), + orgChild4Id: IsNull(), + }, + }); + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + let pos = await this.empPosMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + orgRootId: org?.root ?? "", + orgChild1Id: IsNull(), + orgChild2Id: IsNull(), + orgChild3Id: IsNull(), + orgChild4Id: IsNull(), + }, + }); + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + fullname = ""; + } + } + } + } + } + + const mapProfile = { + id: profile.id, + avatar: profile.avatar, + avatarName: profile.avatarName, + rank: profile.rank, + prefix: profile.prefix, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + position: profile.position, + posLevelId: profile.posLevelId, + email: profile.email, + phone: profile.phone, + keycloak: profile.keycloak, + isProbation: profile.isProbation, + isLeave: profile.isLeave, + leaveReason: profile.leaveReason, + dateRetire: profile.dateRetire, + dateAppoint: profile.dateAppoint, + dateRetireLaw: profile.dateRetireLaw, + dateStart: profile.dateStart, + govAgeAbsent: profile.govAgeAbsent, + govAgePlus: profile.govAgePlus, + birthDate: profile.birthDate ?? new Date(), + reasonSameDate: profile.reasonSameDate, + telephoneNumber: profile.phone, + nationality: profile.nationality, + gender: profile.gender, + relationship: profile.relationship, + religion: profile.religion, + bloodGroup: profile.bloodGroup, + registrationAddress: profile.registrationAddress, + registrationProvinceId: profile.registrationProvinceId, + registrationDistrictId: profile.registrationDistrictId, + registrationSubDistrictId: profile.registrationSubDistrictId, + registrationZipCode: profile.registrationZipCode, + currentAddress: profile.currentAddress, + currentProvinceId: profile.currentProvinceId, + currentSubDistrictId: profile.currentSubDistrictId, + currentZipCode: profile.currentZipCode, + dutyTimeId: profile.dutyTimeId, + dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate, + amount: profile.amount, + positionSalaryAmount: profile.positionSalaryAmount, + mouthSalaryAmount: profile.mouthSalaryAmount, + root: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRoot?.orgRootName ?? null, + child1: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild1?.orgChild1Name ?? null, + child2: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2?.orgChild2Name ?? null, + child3: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3?.orgChild3Name ?? null, + child4: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4?.orgChild4Name ?? null, + rootId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRootId ?? null, + child1Id: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild1Id ?? null, + child2Id: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2Id ?? null, + child3Id: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3Id ?? null, + child4Id: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4Id ?? null, + rootDnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRoot?.ancestorDNA ?? null, + child1DnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3?.ancestorDNA ?? null, + child2DnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2?.ancestorDNA ?? null, + child3DnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3?.ancestorDNA ?? null, + child4DnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4?.ancestorDNA ?? null, + commander: fullname, + posLevel: + (profile.posType == null || profile.posType?.posTypeShortName == null + ? "" + : profile.posType?.posTypeShortName + " ") + (profile.posLevel?.posLevelName ?? ""), + posType: profile.posType?.posTypeName ?? null, + profileSalary: latestSalary ?? null, + profileInsignia: latestInsignia ?? null, + profileType: "EMPLOYEE", + }; + + return new HttpSuccess(mapProfile); + } + + const [latestSalary, latestInsignia] = await Promise.all([ + this.salaryRepo.findOne({ + where: { profileId: profile.id }, + order: { commandDateAffect: "DESC" }, + }), + this.insigniaRepo.findOne({ + where: { profileId: profile.id }, + order: { receiveDate: "DESC" }, + }), + ]); + + const org = { + root: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRoot?.id ?? null, + child1: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild1?.id ?? null, + child2: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2?.id ?? null, + child3: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3?.id ?? null, + child4: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4?.id ?? null, + }; + + let fullname = ""; + let pos = await this.posMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + isDirector: true, + orgRootId: org?.root ?? "", + orgChild1Id: org?.child1 ?? "", + orgChild2Id: org?.child2 ?? "", + orgChild3Id: org?.child3 ?? "", + orgChild4Id: org?.child4 ?? "", + }, + }); + + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + let pos = await this.posMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + isDirector: true, + orgRootId: org?.root ?? "", + orgChild1Id: org?.child1 ?? "", + orgChild2Id: org?.child2 ?? "", + orgChild3Id: org?.child3 ?? "", + orgChild4Id: IsNull(), + }, + }); + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + let pos = await this.posMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + isDirector: true, + orgRootId: org?.root ?? "", + orgChild1Id: org?.child1 ?? "", + orgChild2Id: org?.child2 ?? "", + orgChild3Id: IsNull(), + orgChild4Id: IsNull(), + }, + }); + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + let pos = await this.posMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + isDirector: true, + orgRootId: org?.root ?? "", + orgChild1Id: org?.child1 ?? "", + orgChild2Id: IsNull(), + orgChild3Id: IsNull(), + orgChild4Id: IsNull(), + }, + }); + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + let pos = await this.posMasterRepository.findOne({ + relations: ["current_holder"], + where: { + current_holder: Not(IsNull()), + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + orgRootId: org?.root ?? "", + orgChild1Id: IsNull(), + orgChild2Id: IsNull(), + orgChild3Id: IsNull(), + orgChild4Id: IsNull(), + }, + }); + if (pos) { + fullname = + pos.current_holder.prefix + + pos.current_holder.firstName + + " " + + pos.current_holder.lastName; + } else { + fullname = ""; + } + } + } + } + } + + const mapProfile = { + id: profile.id, + avatar: profile.avatar, + avatarName: profile.avatarName, + rank: profile.rank, + prefix: profile.prefix, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + position: profile.position, + posLevelId: profile.posLevelId, + email: profile.email, + phone: profile.phone, + keycloak: profile.keycloak, + isProbation: profile.isProbation, + isLeave: profile.isLeave, + leaveReason: profile.leaveReason, + dateRetire: profile.dateRetire, + dateAppoint: profile.dateAppoint, + dateRetireLaw: profile.dateRetireLaw, + dateStart: profile.dateStart, + govAgeAbsent: profile.govAgeAbsent, + govAgePlus: profile.govAgePlus, + birthDate: profile.birthDate ?? new Date(), + reasonSameDate: profile.reasonSameDate, + telephoneNumber: profile.phone, + nationality: profile.nationality, + gender: profile.gender, + relationship: profile.relationship, + religion: profile.religion, + bloodGroup: profile.bloodGroup, + registrationAddress: profile.registrationAddress, + registrationProvinceId: profile.registrationProvinceId, + registrationDistrictId: profile.registrationDistrictId, + registrationSubDistrictId: profile.registrationSubDistrictId, + registrationZipCode: profile.registrationZipCode, + currentAddress: profile.currentAddress, + currentProvinceId: profile.currentProvinceId, + currentSubDistrictId: profile.currentSubDistrictId, + currentZipCode: profile.currentZipCode, + dutyTimeId: profile.dutyTimeId, + dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate, + amount: profile.amount, + positionSalaryAmount: profile.positionSalaryAmount, + mouthSalaryAmount: profile.mouthSalaryAmount, + root: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRoot?.orgRootName ?? null, + child1: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild1?.orgChild1Name ?? null, + child2: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2?.orgChild2Name ?? null, + child3: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3?.orgChild3Name ?? null, + child4: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4?.orgChild4Name ?? null, + rootId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRootId ?? null, + child1Id: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild1Id ?? null, + child2Id: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2Id ?? null, + child3Id: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3Id ?? null, + child4Id: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4Id ?? null, + rootDnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRoot?.ancestorDNA ?? null, + child1DnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild1?.ancestorDNA ?? null, + child2DnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2?.ancestorDNA ?? null, + child3DnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3?.ancestorDNA ?? null, + child4DnaId: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4?.ancestorDNA ?? null, + commander: fullname, + posLevel: profile.posLevel?.posLevelName ?? null, + posType: profile.posType?.posTypeName ?? null, + profileSalary: latestSalary ?? null, + profileInsignia: latestInsignia ?? null, + profileType: "OFFICER", + }; + + return new HttpSuccess(mapProfile); + } + /** * API หา user profile officer *