diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index addc33db..4277a917 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -8489,22 +8489,22 @@ export class OrganizationDotnetController extends Controller { break; case 1: typeCondition = { - child1DnaId: body.nodeId, + rootDnaId: body.nodeId, }; break; case 2: typeCondition = { - child2DnaId: body.nodeId, + child1DnaId: body.nodeId, }; break; case 3: typeCondition = { - child3DnaId: body.nodeId, + child2DnaId: body.nodeId, }; break; case 4: typeCondition = { - child4DnaId: body.nodeId, + child3DnaId: body.nodeId, }; break; default: @@ -8593,29 +8593,13 @@ export class OrganizationDotnetController extends Controller { where: { ...typeCondition, createdAt: LessThanOrEqual(date), + // firstName: Not("") && Not(IsNull()), + // lastName: Not("") && Not(IsNull()), }, - select: [ - "profileId", - "prefix", - "firstName", - "lastName", - "shortName", - "posMasterNo", - "position", - "posType", - "posLevel", - "ancestorDNA", - "rootDnaId", - "child1DnaId", - "child2DnaId", - "child3DnaId", - "child4DnaId", - "createdAt", - ], order: { firstName: "ASC", lastName: "ASC", - createdAt: "DESC", + createdAt: "DESC", // ให้ createdAt ล่าสุดอยู่ข้างบน }, }); @@ -8662,41 +8646,36 @@ export class OrganizationDotnetController extends Controller { } } - const profileIds = Array.from(grouped3.values()) - .filter((x) => x.profileId != null) - .map((x) => x.profileId); + const profile_ = await Promise.all( + Array.from(grouped3.values()) + .filter((x) => x.profileId != null) + .map(async (item: PosMasterHistory) => { + let profile = await this.profileRepo.findOne({ + where: { id: item.profileId }, + }); - const profiles = await this.profileRepo.find({ - where: { id: In(profileIds) }, - select: ["id", "citizenId", "dateStart", "dateAppoint", "keycloak"], - }); - - const profileMap = new Map(profiles.map((p) => [p.id, p])); - - const profile_ = Array.from(grouped3.values()) - .filter((x) => x.profileId != null) - .map((item: PosMasterHistory) => { - const profile = profileMap.get(item.profileId); - return { - id: item.profileId, - prefix: item.prefix, - firstName: item.firstName, - lastName: item.lastName, - citizenId: profile?.citizenId ?? null, - dateStart: profile?.dateStart ?? null, - dateAppoint: profile?.dateAppoint ?? null, - keycloak: profile?.keycloak ?? null, - posNo: `${item.shortName} ${item.posMasterNo}`, - position: item.position, - positionLevel: item.posLevel, - positionType: item.posType, - orgRootId: item.rootDnaId, - orgChild1Id: item.child1DnaId, - orgChild2Id: item.child2DnaId, - orgChild3Id: item.child3DnaId, - orgChild4Id: item.child4DnaId, - }; - }); + return { + id: item.profileId, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, + citizenId: profile?.citizenId ?? null, + dateStart: profile?.dateStart ?? null, + dateAppoint: profile?.dateAppoint ?? null, + keycloak: profile?.keycloak ?? null, + posNo: `${item.shortName} ${item.posMasterNo}`, + position: item.position, + positionLevel: item.posLevel, + positionType: item.posType, + // oc: Oc, + orgRootId: item.rootDnaId, + orgChild1Id: item.child1DnaId, + orgChild2Id: item.child2DnaId, + orgChild3Id: item.child3DnaId, + orgChild4Id: item.child4DnaId, + }; + }), + ); return new HttpSuccess( (profile_ ?? []).sort((a, b) => a.posNo.localeCompare(b.posNo, undefined, { numeric: true })),