no message

This commit is contained in:
Kittapath 2024-02-07 14:01:39 +07:00
parent 148fa2c81c
commit d33569005a
2 changed files with 150 additions and 112 deletions

View file

@ -86,27 +86,26 @@ export class PositionController extends Controller {
} }
const checkPosTypeId = await this.posTypeRepository.findOne({ const checkPosTypeId = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId }, where: { id: posDict.posTypeId },
}); });
if (!checkPosTypeId) { if (!checkPosTypeId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosTypeId"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosTypeId");
} }
const checkPosLevelId = await this.posLevelRepository.findOne({ const checkPosLevelId = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId }, where: { id: posDict.posLevelId },
}); });
if (!checkPosLevelId) { if (!checkPosLevelId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
} }
if (requestBody.posExecutiveId == "") { if (posDict.posExecutiveId == "") {
requestBody.posExecutiveId = null;
posDict.posExecutiveId = null; posDict.posExecutiveId = null;
} }
if (requestBody.posExecutiveId != null) { if (posDict.posExecutiveId != null) {
const checkPosExecutiveId = await this.posExecutiveRepository.findOne({ const checkPosExecutiveId = await this.posExecutiveRepository.findOne({
where: { id: requestBody.posExecutiveId }, where: { id: posDict.posExecutiveId },
}); });
if (!checkPosExecutiveId) { if (!checkPosExecutiveId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId");

View file

@ -176,11 +176,23 @@ export class ReportController extends Controller {
}); });
let orgRevisionActive: any = await this.orgRevisionRepository.findOne({ let orgRevisionActive: any = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
relations: [
"posMasters",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
],
}); });
if (orgRevisionActive == null) { if (orgRevisionActive == null) {
const _orgRevisionActive = await this.orgRevisionRepository.find({ const _orgRevisionActive = await this.orgRevisionRepository.find({
order: { orgRevisionCreatedAt: "DESC" }, order: { orgRevisionCreatedAt: "DESC" },
skip: 1, skip: 1,
relations: [
"posMasters",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
],
}); });
if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0];
} }
@ -205,114 +217,141 @@ export class ReportController extends Controller {
orgTreeName: orgRoot.orgRootName, orgTreeName: orgRoot.orgRootName,
orgTreeShortName: orgRoot.orgRootShortName, orgTreeShortName: orgRoot.orgRootShortName,
posMasters: await Promise.all( posMasters: await Promise.all(
orgRoot.posMasters.map(async (posMaster) => { orgRoot.posMasters
// let posMasterOld: any = null; .sort((a, b) => a.posMasterOrder - b.posMasterOrder)
// if (posMaster.next_holder != null) { .map(async (posMaster) => {
// // posMasterOld = posMasterOlds.find((posMasOld) => const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))];
// // posMasOld.current_holder == null const posType = [...new Set(posMaster.positions.map((x) => x.posType.posTypeName))];
// // ? false const posLevel = [
// // : posMasOld.current_holder.id === posMaster.next_holder.id, ...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)),
// // ); ];
// } const positionField = [...new Set(posMaster.positions.map((x) => x.positionField))];
// let positionOld: any = null; let positionMasterProfileOld: any = null;
// if (posMasterOld != null) if (posMaster.next_holder != null) {
// positionOld = positionOlds.find( positionMasterProfileOld = posMaster.next_holder.current_holders.find(
// (positionold) => positionold.posMasterId === posMasterOld.id, (x) => x.orgRevisionId == orgRevisionActive.id,
// ); );
// const positionNow = await Promise.all( }
// positions
// .filter((position) => position.posMasterId === posMaster.id)
// .map(async (position) => {
// return {
// positionName: position.positionName,
// positionField: position.positionField,
// posType: position.posType == null ? null : position.posType.posTypeName,
// posLevel: position.posLevel == null ? null : position.posLevel.posLevelName,
// posExecutive:
// position.posExecutive == null
// ? null
// : position.posExecutive.posExecutiveName,
// };
// }),
// );
const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))];
const posType = [...new Set(posMaster.positions.map((x) => x.posType.posTypeName))];
const posLevel = [
...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)),
];
const positionField = [...new Set(posMaster.positions.map((x) => x.positionField))];
const positionMasterOld = posMaster.next_holder.current_holders.find(
(x) => x == orgRevisionActive,
);
console.log(orgRevisionActive);
console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
return {
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
profileFullname:
posMaster.next_holder == null
? "- ว่าง -"
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
// profilePosMasterNo: let positionMasterOld: any = null;
// posMaster.next_holder == null let profilePositionName: any = [];
// ? posMaster.posMasterNo let profilePosType: any = [];
// : positionMasterOld == null let profilePosLevel: any = [];
// ? null let profilePositionField: any = [];
// : positionMasterOld.posMasterNo, if (posMaster.ancestorDNA != null) {
profilePositionName: positionMasterOld = orgRevisionActive.posMasters.find(
posMaster.next_holder == null (x: any) =>
? positionName.join(" หรือ ") x.orgRevisionId == orgRevisionActive.id &&
: posMaster.next_holder.position, x.ancestorDNA == posMaster.ancestorDNA,
profilePosType: );
posMaster.next_holder == null profilePositionName = [
? posType.join(" หรือ ") ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)),
: posMaster.next_holder.posType == null ];
? null profilePosType = [
: posMaster.next_holder.posType.posTypeName, ...new Set(positionMasterOld.positions.map((x: any) => x.posType.posTypeName)),
profilePosLevel: ];
posMaster.next_holder == null profilePosLevel = [
? posLevel.join(" หรือ ") ...new Set(
: posMaster.next_holder.posLevel == null positionMasterOld.positions.map((x: any) => x.posLevel.posLevelName),
? null ),
: posMaster.next_holder.posLevel.posLevelName, ];
// profilePositionField: profilePositionField = [
// posMaster.next_holder == null ...new Set(positionMasterOld.positions.map((x: any) => x.positionField)),
// ? positionField.join(" หรือ ") ];
// : positionMasterOld == null }
// ? null
// : positionMasterOld.positions.find((x) => (x.positionIsSelected = true))
// ?.positionField,
// profilePosMasterNo: (posMasterOld == null ? null : posMasterOld.posMasterNo), return {
// profilePositionName: (positionOld == null ? null : positionOld.positionName), posMasterOrder: posMaster.posMasterOrder,
// profilePosType: (positionOld == null ? null : positionOld.posType.posTypeName), posMasterNoPrefix: posMaster.posMasterNoPrefix,
// profilePosLevel: (positionOld == null ? null : positionOld.posLevel.posLevelName), posMasterNo: posMaster.posMasterNo,
// profilePositionField: (positionOld == null ? null : positionOld.positionField), posMasterNoSuffix: posMaster.posMasterNoSuffix,
PositionName: positionName.join(" หรือ "), profileFullname:
PosType: posType.join(" หรือ "), posMaster.next_holder == null
PosLevel: posLevel.join(" หรือ "), ? "- ว่าง -"
PositionField: positionField.join(" หรือ "), : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
// positions: await Promise.all( profilePosMasterNo:
// positions positionMasterProfileOld == null
// .filter((position) => position.posMasterId === posMaster.id) ? positionMasterOld == null
// .map(async (position) => { ? "-"
// return { : positionMasterOld.posMasterNo
// positionName: position.positionName, : positionMasterProfileOld.posMasterNo,
// positionField: position.positionField,
// posType: position.posType == null ? null : position.posType.posTypeName, profilePositionName:
// posLevel: posMaster.next_holder == null
// position.posLevel == null ? null : position.posLevel.posLevelName, ? profilePositionName.length > 0
// posExecutive: ? profilePositionName.join(" หรือ ")
// position.posExecutive == null : positionName.join(" หรือ ")
// ? null : posMaster.next_holder.position,
// : position.posExecutive.posExecutiveName, profilePosType:
// }; posMaster.next_holder == null
// }), ? profilePosType.length > 0
// ), ? profilePosType.join(" หรือ ")
}; : posType.join(" หรือ ")
}), : posMaster.next_holder.posType == null
? "-"
: posMaster.next_holder.posType.posTypeName,
profilePosLevel:
posMaster.next_holder == null
? profilePosLevel.length > 0
? profilePosLevel.join(" หรือ ")
: posLevel.join(" หรือ ")
: posMaster.next_holder.posLevel == null
? "-"
: posMaster.next_holder.posLevel.posLevelName,
profilePositionField:
posMaster.next_holder == null
? profilePositionField.length > 0
? profilePositionField.join(" หรือ ")
: positionField.join(" หรือ ")
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.positions.find(
(x: any) => (x.positionIsSelected = true),
)?.positionField,
positionName:
posMaster.next_holder == null
? positionName.join(" หรือ ")
: posMaster.next_holder.position,
posType:
posMaster.next_holder == null
? posType.join(" หรือ ")
: posMaster.next_holder.posType == null
? "-"
: posMaster.next_holder.posType.posTypeName,
posLevel:
posMaster.next_holder == null
? posLevel.join(" หรือ ")
: posMaster.next_holder.posLevel == null
? "-"
: posMaster.next_holder.posLevel.posLevelName,
positionField:
posMaster.next_holder == null
? positionField.join(" หรือ ")
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.positions.find(
(x: any) => (x.positionIsSelected = true),
)?.positionField,
// positions: await Promise.all(
// positions
// .filter((position) => position.posMasterId === posMaster.id)
// .map(async (position) => {
// return {
// positionName: position.positionName,
// positionField: position.positionField,
// posType: position.posType == null ? null : position.posType.posTypeName,
// posLevel:
// position.posLevel == null ? null : position.posLevel.posLevelName,
// posExecutive:
// position.posExecutive == null
// ? null
// : position.posExecutive.posExecutiveName,
// };
// }),
// ),
};
}),
), ),
}; };
data.push(node); data.push(node);