fix: script update profile
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m10s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m10s
This commit is contained in:
parent
c344804936
commit
520b42f2c7
1 changed files with 24 additions and 26 deletions
|
|
@ -7219,30 +7219,15 @@ export class OrganizationController extends Controller {
|
|||
// select: ["posLevelName"],
|
||||
// });
|
||||
|
||||
const [
|
||||
roots,
|
||||
child1,
|
||||
child2,
|
||||
child3,
|
||||
child4,
|
||||
hospital,
|
||||
posType,
|
||||
posLevel,
|
||||
] = await Promise.all([
|
||||
|
||||
const [roots, child1, child2, child3, child4, hospital, posType, posLevel] = await Promise.all([
|
||||
// ===== ROOT =====
|
||||
this.orgRootRepository
|
||||
.createQueryBuilder("root")
|
||||
.innerJoin("root.orgRevision", "rev")
|
||||
.select([
|
||||
"root.orgRootName AS orgRootName",
|
||||
])
|
||||
.select(["root.orgRootName AS orgRootName"])
|
||||
.where("rev.orgRevisionIsDraft = false")
|
||||
.andWhere("rev.orgRevisionIsCurrent = true")
|
||||
.orderBy(
|
||||
"CASE WHEN root.DEPARTMENT_CODE = '50' THEN 1 ELSE 0 END",
|
||||
"ASC",
|
||||
)
|
||||
.orderBy("CASE WHEN root.DEPARTMENT_CODE = '50' THEN 1 ELSE 0 END", "ASC")
|
||||
.addOrderBy("root.isDeputy", "DESC")
|
||||
.addOrderBy("root.orgRootOrder", "ASC")
|
||||
.addOrderBy("root.orgRootName", "ASC")
|
||||
|
|
@ -7296,10 +7281,7 @@ export class OrganizationController extends Controller {
|
|||
.select("c1.orgChild1Name", "orgChild1Name")
|
||||
.where("rev.orgRevisionIsDraft = false")
|
||||
.andWhere("rev.orgRevisionIsCurrent = true")
|
||||
.andWhere(
|
||||
"(root.isDeputy = true OR c1.orgChild1RankSub = :rank)",
|
||||
{ rank: "HOSPITAL" },
|
||||
)
|
||||
.andWhere("(root.isDeputy = true OR c1.orgChild1RankSub = :rank)", { rank: "HOSPITAL" })
|
||||
.getRawMany(),
|
||||
|
||||
// ===== POSITION TYPE =====
|
||||
|
|
@ -8133,7 +8115,8 @@ export class OrganizationController extends Controller {
|
|||
const toInsert: any[] = [];
|
||||
|
||||
// Track draft PosMaster ID to current PosMaster ID mapping for position sync
|
||||
const posMasterMapping: Map<string, string> = new Map();
|
||||
// Type: Map<draftPosMasterId, [currentPosMasterId, nextHolderId]>
|
||||
const posMasterMapping: Map<string, [string, string | null | undefined]> = new Map();
|
||||
|
||||
for (const draftPos of posMasterDraft) {
|
||||
const current = currentByDNA.get(draftPos.ancestorDNA);
|
||||
|
|
@ -8176,7 +8159,7 @@ export class OrganizationController extends Controller {
|
|||
toUpdate.push(current);
|
||||
|
||||
// Track mapping for position sync
|
||||
posMasterMapping.set(draftPos.id, current.id);
|
||||
posMasterMapping.set(draftPos.id, [current.id, draftPos.next_holderId]);
|
||||
} else {
|
||||
// INSERT new position
|
||||
const newPosMaster = queryRunner.manager.create(PosMaster, {
|
||||
|
|
@ -8208,7 +8191,7 @@ export class OrganizationController extends Controller {
|
|||
for (let i = 0; i < saved.length; i++) {
|
||||
const draftPos = posMasterDraft.filter((d) => !currentByDNA.has(d.ancestorDNA))[i];
|
||||
if (draftPos && saved[i]) {
|
||||
posMasterMapping.set(draftPos.id, saved[i].id);
|
||||
posMasterMapping.set(draftPos.id, [saved[i].id, draftPos.next_holderId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8220,13 +8203,14 @@ export class OrganizationController extends Controller {
|
|||
updated: 0,
|
||||
inserted: 0,
|
||||
};
|
||||
for (const [draftPosMasterId, currentPosMasterId] of posMasterMapping) {
|
||||
for (const [draftPosMasterId, [currentPosMasterId, nextHolderId]] of posMasterMapping) {
|
||||
const stats = await this.syncPositionsForPosMaster(
|
||||
queryRunner,
|
||||
draftPosMasterId,
|
||||
currentPosMasterId,
|
||||
drafRevisionId,
|
||||
currentRevisionId,
|
||||
nextHolderId,
|
||||
);
|
||||
positionSyncStats.deleted += stats.deleted;
|
||||
positionSyncStats.updated += stats.updated;
|
||||
|
|
@ -8535,6 +8519,7 @@ export class OrganizationController extends Controller {
|
|||
currentPosMasterId: string,
|
||||
draftRevisionId: string,
|
||||
currentRevisionId: string,
|
||||
nextHolderId: string | null | undefined,
|
||||
): Promise<{ deleted: number; updated: number; inserted: number }> {
|
||||
// Fetch draft and current positions for this posMaster
|
||||
const [draftPositions, currentPositions] = await Promise.all([
|
||||
|
|
@ -8593,6 +8578,10 @@ export class OrganizationController extends Controller {
|
|||
positionExecutiveField: draftPos.positionExecutiveField,
|
||||
positionArea: draftPos.positionArea,
|
||||
isSpecial: draftPos.isSpecial,
|
||||
orderNo: draftPos.orderNo,
|
||||
positionIsSelected: draftPos.positionIsSelected,
|
||||
lastUpdateFullName: draftPos.lastUpdateFullName,
|
||||
lastUpdatedAt: new Date(),
|
||||
});
|
||||
updatedCount++;
|
||||
} else {
|
||||
|
|
@ -8605,6 +8594,15 @@ export class OrganizationController extends Controller {
|
|||
await queryRunner.manager.save(newPosition);
|
||||
insertedCount++;
|
||||
}
|
||||
|
||||
// update profile
|
||||
if (nextHolderId != null && draftPos.positionIsSelected) {
|
||||
await queryRunner.manager.update(Profile, nextHolderId, {
|
||||
position: draftPos.positionName,
|
||||
posTypeId: draftPos.posTypeId,
|
||||
posLevelId: draftPos.posLevelId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return { deleted: toDelete.length, updated: updatedCount, inserted: insertedCount };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue