api list รายชื่อตามสิทธิ์ admin ปรับ order & แก้ของลูกจ้าง

This commit is contained in:
Bright 2025-07-09 14:26:42 +07:00
parent 4fdd5e7d7d
commit 9cda6e176e

View file

@ -26,6 +26,7 @@ import { Position } from "../entities/Position";
import { Insignia } from "../entities/Insignia";
import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia";
import { PosMaster } from "../entities/PosMaster";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosDict } from "../entities/EmployeePosDict";
import { calculateRetireLaw } from "../interfaces/utils";
import Extension from "../interfaces/extension";
@ -44,6 +45,7 @@ export class OrganizationDotnetController extends Controller {
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
private positionRepository = AppDataSource.getRepository(Position);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict);
@ -4164,7 +4166,9 @@ export class OrganizationDotnetController extends Controller {
}
} else if (body.role === "ROOT") {
typeCondition = {
orgRootId: body.nodeId
orgRoot: {
ancestorDNA: body.nodeId
},
};
} else if (body.role === "NORMAL") {
switch (node) {
@ -4225,6 +4229,26 @@ export class OrganizationDotnetController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
order: {
current_holders: {
orgRoot: {
orgRootOrder: "ASC",
},
orgChild1: {
orgChild1Order: "ASC",
},
orgChild2: {
orgChild2Order: "ASC",
},
orgChild3: {
orgChild3Order: "ASC",
},
orgChild4: {
orgChild4Order: "ASC",
},
posMasterNo: "ASC",
}
}
});
if (body.isRetirement) {
profile = await this.profileRepo.find({
@ -4246,7 +4270,7 @@ export class OrganizationDotnetController extends Controller {
});
}
let findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }
});
if (body.revisionId) {
@ -4285,15 +4309,15 @@ export class OrganizationDotnetController extends Controller {
const Oc =
item.current_holders.length == 0
? null
: (node == 4 || node == null) && item.current_holders[0].orgChild4 != null
: item.current_holders[0].orgChild4 != null
? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
: (node == 3 || node == null) && item.current_holders[0].orgChild3 != null
: item.current_holders[0].orgChild3 != null
? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
: (node == 2 || node == null) && item.current_holders[0].orgChild2 != null
: item.current_holders[0].orgChild2 != null
? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
: (node == 1 || node == null) && item.current_holders[0].orgChild1 != null
: item.current_holders[0].orgChild1 != null
? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
: (node == 0 || node == null) && item.current_holders[0].orgRoot != null
: item.current_holders[0].orgRoot != null
? `${item.current_holders[0].orgRoot.orgRootName}`
: null;
@ -4659,19 +4683,39 @@ export class OrganizationDotnetController extends Controller {
if (body.role === "OWNER" || body.role === "CHILD") {
switch (node) {
case 0:
typeCondition = { orgRootId: body.nodeId };
typeCondition = {
orgRoot: {
ancestorDNA: body.nodeId
}
};
break;
case 1:
typeCondition = { orgChild1Id: body.nodeId };
typeCondition = {
orgChild1: {
ancestorDNA: body.nodeId
}
};
break;
case 2:
typeCondition = { orgChild2Id: body.nodeId };
typeCondition = {
orgChild2: {
ancestorDNA: body.nodeId
}
};
break;
case 3:
typeCondition = { orgChild3Id: body.nodeId };
typeCondition = {
orgChild3: {
ancestorDNA: body.nodeId
}
};
break;
case 4:
typeCondition = { orgChild4Id: body.nodeId };
typeCondition = {
orgChild4: {
ancestorDNA: body.nodeId
}
};
break;
case null:
typeCondition = {};
@ -4682,32 +4726,49 @@ export class OrganizationDotnetController extends Controller {
}
} else if (body.role === "ROOT") {
typeCondition = {
orgRootId: body.nodeId
orgRoot: {
ancestorDNA: body.nodeId
},
};
} else if (body.role === "NORMAL") {
switch (node) {
case 0:
typeCondition = {
orgRootId: body.nodeId,
orgChild1Id: IsNull(),
orgRoot: {
ancestorDNA: body.nodeId
},
orgChild1: IsNull()
};
break;
case 1:
typeCondition = {
orgChild1Id: body.nodeId,
orgChild2Id: IsNull(),
orgChild1: {
ancestorDNA: body.nodeId
},
orgChild2: IsNull()
};
break;
case 2:
typeCondition = {
orgChild2Id: body.nodeId,
orgChild3Id: IsNull(),
orgChild2: {
ancestorDNA: body.nodeId
},
orgChild3: IsNull()
};
break;
case 3:
typeCondition = {
orgChild3Id: body.nodeId,
orgChild4Id: IsNull(),
orgChild3: {
ancestorDNA: body.nodeId
},
orgChild4: IsNull()
};
break;
case 4:
typeCondition = {
orgChild4: {
ancestorDNA: body.nodeId
},
};
break;
default:
@ -4728,6 +4789,26 @@ export class OrganizationDotnetController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
],
order: {
current_holders: {
orgRoot: {
orgRootOrder: "ASC",
},
orgChild1: {
orgChild1Order: "ASC",
},
orgChild2: {
orgChild2Order: "ASC",
},
orgChild3: {
orgChild3Order: "ASC",
},
orgChild4: {
orgChild4Order: "ASC",
},
posMasterNo: "ASC",
}
}
});
if (body.isRetirement) {
profile = await this.profileEmpRepo.find({
@ -4749,7 +4830,7 @@ export class OrganizationDotnetController extends Controller {
});
}
let findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }
});
if (body.revisionId) {
@ -4759,7 +4840,7 @@ export class OrganizationDotnetController extends Controller {
}
const profile_ = await Promise.all(
profile.map((item: ProfileEmployee) => {
profile.map(async(item: ProfileEmployee) => {
const shortName =
item.current_holders.length == 0
? null
@ -4788,17 +4869,25 @@ export class OrganizationDotnetController extends Controller {
const Oc =
item.current_holders.length == 0
? null
: body.node == 4 && item.current_holders[0].orgChild4 != null
: item.current_holders[0].orgChild4 != null
? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
: body.node == 3 && item.current_holders[0].orgChild3 != null
: item.current_holders[0].orgChild3 != null
? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
: body.node == 2 && item.current_holders[0].orgChild2 != null
: item.current_holders[0].orgChild2 != null
? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
: body.node == 1 && item.current_holders[0].orgChild1 != null
: item.current_holders[0].orgChild1 != null
? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
: body.node == 0 && item.current_holders[0].orgRoot != null
: item.current_holders[0].orgRoot != null
? `${item.current_holders[0].orgRoot.orgRootName}`
: null;
let _posMaster = await this.empPosMasterRepository.findOne({
where: {
orgRevisionId: findRevision?.id,
current_holderId: item.id
}
});
return {
id: item.id,
prefix: item.prefix,
@ -4808,9 +4897,16 @@ export class OrganizationDotnetController extends Controller {
keycloak: item.keycloak,
posNo: shortName,
position: item.position,
positionLevel: item.posLevel?.posLevelName ?? null,
positionLevel: item.posType?.posTypeShortName && item.posLevel?.posLevelName
? `${item.posType?.posTypeShortName} ${item.posLevel?.posLevelName}`
: null,
positionType: item.posType?.posTypeName ?? null,
oc: Oc,
orgRootId: _posMaster?.orgRootId,
orgChild1Id: _posMaster?.orgChild1Id,
orgChild2Id: _posMaster?.orgChild2Id,
orgChild3Id: _posMaster?.orgChild3Id,
orgChild4Id: _posMaster?.orgChild4Id,
};
}),
);