Enhance OrganizationDotnetController: Add orgRevision to current_holders and improve profile mapping

This commit is contained in:
Suphonchai Phoonsawat 2026-03-25 14:33:44 +07:00
parent 9760c4f667
commit 936b28a9f4

View file

@ -25,8 +25,6 @@ import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { Position } from "../entities/Position";
import { PosMaster } from "../entities/PosMaster";
import { PosMasterAssign } from "../entities/PosMasterAssign";
import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
import { PosMasterHistory } from "../entities/PosMasterHistory";
import { Profile } from "../entities/Profile";
import { ProfileEducation } from "../entities/ProfileEducation";
@ -221,6 +219,7 @@ export class OrganizationDotnetController extends Controller {
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
@ -241,18 +240,59 @@ export class OrganizationDotnetController extends Controller {
)
.andWhere(condition, conditionParams)
.andWhere(selectedNodeCondition, selectedNodeConditionParams)
.select([
"profile.id",
"profile.citizenId",
"profile.prefix",
"profile.firstName",
"profile.lastName",
"current_holders",
"orgRevision",
"orgRoot",
"orgChild1",
"orgChild2",
"orgChild3",
"orgChild4",
])
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: profiles, total: total });
const mapProfiles = profiles.map((profile) => ({
id: profile.id,
citizenId: profile.citizenId,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
rootDnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgRoot?.ancestorDNA ?? null,
child1DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgChild1?.ancestorDNA ?? null,
child2DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgChild2?.ancestorDNA ?? null,
child3DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgChild3?.ancestorDNA ?? null,
child4DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgChild4?.ancestorDNA ?? null,
}));
return new HttpSuccess({ data: mapProfiles, total: total });
}
/**
@ -364,6 +404,7 @@ export class OrganizationDotnetController extends Controller {
.leftJoinAndSelect("profile.profileSalary", "profileSalary")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
@ -389,12 +430,52 @@ export class OrganizationDotnetController extends Controller {
"profile.prefix",
"profile.firstName",
"profile.lastName",
"current_holders",
"orgRevision",
"orgRoot",
"orgChild1",
"orgChild2",
"orgChild3",
"orgChild4",
])
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: profileEmp, total: total });
const mapProfiles = profileEmp.map((profile) => ({
id: profile.id,
citizenId: profile.citizenId,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
rootDnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgRoot?.ancestorDNA ?? null,
child1DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgChild1?.ancestorDNA ?? null,
child2DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgChild2?.ancestorDNA ?? null,
child3DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgChild3?.ancestorDNA ?? null,
child4DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.id === findRevision.id && x.orgRevision?.orgRevisionIsDraft === false,
)?.orgChild4?.ancestorDNA ?? null,
}));
return new HttpSuccess({ data: mapProfiles, total: total });
}
/**
@ -1073,7 +1154,7 @@ export class OrganizationDotnetController extends Controller {
profile.posLevel != null &&
(profile.posType.posTypeName == "บริหาร" || profile.posType.posTypeName == "อำนวยการ")
? `${profile.posType?.posTypeName ?? ""}${profile.posLevel?.posLevelName ?? ""}`
: (profile.posLevel?.posLevelName ?? null);
: profile.posLevel?.posLevelName ?? null;
const _profileCurrent = profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft === false && x.orgRevision?.orgRevisionIsCurrent === true,
@ -1409,7 +1490,7 @@ export class OrganizationDotnetController extends Controller {
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: (profile.posLevel?.posLevelName ?? null);
: profile.posLevel?.posLevelName ?? null;
const mapProfile = {
id: profile.id,
@ -1610,7 +1691,7 @@ export class OrganizationDotnetController extends Controller {
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: (profile.posLevel?.posLevelName ?? null);
: profile.posLevel?.posLevelName ?? null;
/* =========================================
* 8. map response
@ -1868,7 +1949,7 @@ export class OrganizationDotnetController extends Controller {
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: (profile.posLevel?.posLevelName ?? null);
: profile.posLevel?.posLevelName ?? null;
/* =========================================
* 8. map response
@ -2195,7 +2276,7 @@ export class OrganizationDotnetController extends Controller {
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: (profile.posLevel?.posLevelName ?? null);
: profile.posLevel?.posLevelName ?? null;
/* =========================================
* 8. map response
@ -7542,7 +7623,7 @@ export class OrganizationDotnetController extends Controller {
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" || profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: (profile.posLevel?.posLevelName ?? null);
: profile.posLevel?.posLevelName ?? null;
/* =========================================
* position executive