fix โคลนสิทธิ์เมนู task #2160
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s
This commit is contained in:
parent
7a25dc98aa
commit
96a2d34c1f
2 changed files with 36 additions and 25 deletions
|
|
@ -35,4 +35,10 @@ export class CreatePosMaster {
|
||||||
posMasterNoPrefix: string;
|
posMasterNoPrefix: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class PosMasterAssignDTO {
|
||||||
|
id: string;
|
||||||
|
posMasterId: string;
|
||||||
|
assignId: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type UpdatePosMaster = Partial<PosMaster>;
|
export type UpdatePosMaster = Partial<PosMaster>;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import { OrgChild2 } from "../entities/OrgChild2";
|
||||||
import { OrgChild3 } from "../entities/OrgChild3";
|
import { OrgChild3 } from "../entities/OrgChild3";
|
||||||
import { OrgChild4 } from "../entities/OrgChild4";
|
import { OrgChild4 } from "../entities/OrgChild4";
|
||||||
import { OrgRoot } from "../entities/OrgRoot";
|
import { OrgRoot } from "../entities/OrgRoot";
|
||||||
import { PosMasterAssign } from "../entities/PosMasterAssign";
|
import { PosMasterAssign, PosMasterAssignDTO } from "../entities/PosMasterAssign";
|
||||||
import { Position } from "../entities/Position";
|
import { Position } from "../entities/Position";
|
||||||
import { In, Not } from "typeorm";
|
import { In, Not } from "typeorm";
|
||||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||||
|
|
@ -561,7 +561,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
"positions.posExecutive",
|
"positions.posExecutive",
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
// ดึง posMasterAssign ของ revision เดิม xxx
|
// Task #2160 ดึง posMasterAssign ของ revision เดิม
|
||||||
const oldposMasterAssigns = await posMasterAssignRepository.find({
|
const oldposMasterAssigns = await posMasterAssignRepository.find({
|
||||||
relations: ["posMaster"],
|
relations: ["posMaster"],
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -570,14 +570,18 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
// สร้าง Map: ancestorDNA → posMasterAssign[]
|
// สร้าง assignMap เอาไว้เก็บ posMasterAssign.ancestorDNA ของ revision เดิม
|
||||||
const assignMap = new Map<string, PosMasterAssign[]>();
|
const assignMap = new Map<string, PosMasterAssignDTO[]>();
|
||||||
for (const posmasterAssign of oldposMasterAssigns) {
|
for (const posmasterAssign of oldposMasterAssigns) {
|
||||||
const dna = posmasterAssign.posMaster.ancestorDNA;
|
const dna = posmasterAssign.posMaster.ancestorDNA;
|
||||||
if (!assignMap.has(dna)) {
|
if (!assignMap.has(dna)) {
|
||||||
assignMap.set(dna, []);
|
assignMap.set(dna, []);
|
||||||
}
|
}
|
||||||
assignMap.get(dna)!.push(posmasterAssign);
|
assignMap.get(dna)!.push({
|
||||||
|
id: posmasterAssign.id,
|
||||||
|
posMasterId: posmasterAssign.posMasterId,
|
||||||
|
assignId: posmasterAssign.assignId
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ดึง posMasterAct ของ revision เดิม xxx
|
// ดึง posMasterAct ของ revision เดิม xxx
|
||||||
|
|
@ -612,18 +616,18 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
const _null: any = null;
|
const _null: any = null;
|
||||||
for (const item of posMaster) {
|
for (const item of posMaster) {
|
||||||
|
|
||||||
// Clone posMasterAssign xxx
|
// Task #2160 Clone posMasterAssign
|
||||||
const assigns = assignMap.get(item.ancestorDNA);
|
const assigns = assignMap.get(item.ancestorDNA);
|
||||||
if (assigns && assigns.length > 0) {
|
if (assigns && assigns.length > 0) {
|
||||||
const newAssigns = assigns.map(({ id, ...fields }) => ({
|
const newAssigns = assigns.map(({ id, ...fields }) => ({
|
||||||
...fields, // copy ทุก field ยกเว้น id
|
...fields, // copy ทุก field ยกเว้น id
|
||||||
posMasterId: item.id, // ผูกกับ posMasterId ใหม่
|
posMasterId: item.id, // ผูกกับ posMasterId ใหม่
|
||||||
createdAt: new Date(),
|
createdAt: lastUpdatedAt,
|
||||||
createdFullName: user.name,
|
createdFullName: lastUpdateFullName,
|
||||||
createdUserId: user.sub,
|
createdUserId: lastUpdateUserId,
|
||||||
lastUpdatedAt: new Date(),
|
lastUpdatedAt: lastUpdatedAt,
|
||||||
lastUpdateFullName: user.name,
|
lastUpdateFullName: lastUpdateFullName,
|
||||||
lastUpdateUserId: user.sub,
|
lastUpdateUserId: lastUpdateUserId,
|
||||||
}));
|
}));
|
||||||
await posMasterAssignRepository.save(newAssigns);
|
await posMasterAssignRepository.save(newAssigns);
|
||||||
}
|
}
|
||||||
|
|
@ -720,11 +724,11 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
const orgChild4 = await child4Repository.find({
|
const orgChild4 = await child4Repository.find({
|
||||||
where: { orgRevisionId: orgRevisionPublish.id },
|
where: { orgRevisionId: orgRevisionPublish.id },
|
||||||
});
|
});
|
||||||
|
// Task #2172 ดึง orgRoot ของ revision ใหม่
|
||||||
const newRoots = await orgRootRepository.find({
|
const newRoots = await orgRootRepository.find({
|
||||||
where: { orgRevisionId: orgRevisionDraft.id },
|
where: { orgRevisionId: orgRevisionDraft.id },
|
||||||
});
|
});
|
||||||
// map ancestorDNA -> newRootId
|
// สร้าง newRootMap เอาไว้เก็บ orgRoot.ancestorDNA ของ revision ใหม่
|
||||||
const newRootMap = new Map(
|
const newRootMap = new Map(
|
||||||
newRoots.map(r => [r.ancestorDNA, r.id])
|
newRoots.map(r => [r.ancestorDNA, r.id])
|
||||||
);
|
);
|
||||||
|
|
@ -739,23 +743,24 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
});
|
});
|
||||||
const inserts: any[] = [];
|
const inserts: any[] = [];
|
||||||
for (const permiss of oldPermissionProfiles) {
|
for (const permiss of oldPermissionProfiles) {
|
||||||
|
// หา orgRootId ใหม่จาก newRootMap
|
||||||
const newRootId = newRootMap.get(permiss.orgRootTree.ancestorDNA);
|
const newRootId = newRootMap.get(permiss.orgRootTree.ancestorDNA);
|
||||||
if (!newRootId) continue;
|
if (!newRootId) continue;
|
||||||
|
// ตัด id กับ orgRootTree ออกแล้วสร้าง object ใหม่
|
||||||
const { id, ...fields } = permiss;
|
const { id, orgRootTree, ...fields } = permiss;
|
||||||
|
// เตรียมข้อมูลสำหรับ insert
|
||||||
inserts.push({
|
inserts.push({
|
||||||
...fields,
|
...fields,
|
||||||
orgRootId: newRootId,
|
orgRootId: newRootId,
|
||||||
createdAt: new Date(),
|
createdAt: lastUpdatedAt,
|
||||||
createdFullName: user.name,
|
createdFullName: lastUpdateFullName,
|
||||||
createdUserId: user.sub,
|
createdUserId: lastUpdateUserId,
|
||||||
lastUpdatedAt: new Date(),
|
lastUpdatedAt: lastUpdatedAt,
|
||||||
lastUpdateFullName: user.name,
|
lastUpdateFullName: lastUpdateFullName,
|
||||||
lastUpdateUserId: user.sub,
|
lastUpdateUserId: lastUpdateUserId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// ทำการ insert ข้อมูลใหม่ครั้งเดียว
|
||||||
if (inserts.length > 0) {
|
if (inserts.length > 0) {
|
||||||
await permissionProfilesRepository.insert(inserts);
|
await permissionProfilesRepository.insert(inserts);
|
||||||
}
|
}
|
||||||
|
|
@ -2422,7 +2427,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
await child3Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
await child3Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||||
await child2Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
await child2Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||||
await child1Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
await child1Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||||
// ถ้าเลือกทำสำเนาให้อัพเดทจากแบบร่างเดิมไปแบบร่างใหม่แทนการลบ xxx
|
// Task #2160 อัพเดทหน้าที่จัดการโครงสร้างแบบร่าง
|
||||||
if (["ORG", "ORG_POSITION", "ORG_POSITION_PERSON", "ORG_POSITION_ROLE", "ORG_POSITION_PERSON_ROLE"].includes(requestBody.typeDraft?.toUpperCase())) {
|
if (["ORG", "ORG_POSITION", "ORG_POSITION_PERSON", "ORG_POSITION_ROLE", "ORG_POSITION_PERSON_ROLE"].includes(requestBody.typeDraft?.toUpperCase())) {
|
||||||
const _newRoots = await orgRootRepository.find({
|
const _newRoots = await orgRootRepository.find({
|
||||||
where: { orgRevisionId: revision.id }
|
where: { orgRevisionId: revision.id }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue