เพิ่ม promose all ก่อน return

This commit is contained in:
kittapath 2024-08-16 10:11:36 +07:00
parent 0272361d36
commit c5ca718b9f
2 changed files with 61 additions and 63 deletions

View file

@ -945,65 +945,66 @@ export class KpiUserEvaluationController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "พบบางไอดีผู้ประเมินที่ไม่มีข้อมูล");
}
await list.forEach(async (item) => {
let role = "EVALUATOR";
if (profileId == item.commanderId) {
role = "COMMANDER";
} else if (profileId == item.commanderHighId) {
role = "COMMANDERHIGH";
}
if (requestBody.status.trim().toUpperCase() == "APPROVE") {
if (role == "EVALUATOR") {
if (item.evaluationStatus == "NEW_EVALUATOR") {
if (item.commanderId == null || item.commanderId == "") {
item.evaluationStatus = "APPROVE";
} else {
await new CallAPI()
.PostData(request, "/placement/noti/profile", {
subject: `${item.prefix}${item.firstName} ${item.lastName} ผู้ประเมินอนุมัติข้อตกลง`,
body: `${item.prefix}${item.firstName} ${item.lastName} ผู้ประเมินอนุมัติข้อตกลง`,
receiverUserId: item.commanderId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
item.evaluationStatus = "NEW_COMMANDER";
await Promise.all(
list.map(async (item) => {
let role = "EVALUATOR";
if (profileId == item.commanderId) {
role = "COMMANDER";
} else if (profileId == item.commanderHighId) {
role = "COMMANDERHIGH";
}
if (requestBody.status.trim().toUpperCase() == "APPROVE") {
if (role == "EVALUATOR") {
if (item.evaluationStatus == "NEW_EVALUATOR") {
if (item.commanderId == null || item.commanderId == "") {
item.evaluationStatus = "APPROVE";
} else {
await new CallAPI()
.PostData(request, "/placement/noti/profile", {
subject: `${item.prefix}${item.firstName} ${item.lastName} ผู้ประเมินอนุมัติข้อตกลง`,
body: `${item.prefix}${item.firstName} ${item.lastName} ผู้ประเมินอนุมัติข้อตกลง`,
receiverUserId: item.commanderId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
item.evaluationStatus = "NEW_COMMANDER";
}
}
}
} else if (role == "COMMANDER") {
if (item.evaluationStatus == "NEW_COMMANDER") {
if (item.commanderHighId == null || item.commanderHighId == "") {
item.evaluationStatus = "APPROVE";
} else {
await new CallAPI()
.PostData(request, "/placement/noti/profile", {
subject: `${item.prefix}${item.firstName} ${item.lastName} ผู้บังคับบัญชาเหนือขึ้นไปอนุมัติข้อตกลง`,
body: `${item.prefix}${item.firstName} ${item.lastName} ผู้บังคับบัญชาเหนือขึ้นไปอนุมัติข้อตกลง`,
receiverUserId: item.commanderHighId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
item.evaluationStatus = "NEW_COMMANDER_HIGH";
} else if (role == "COMMANDER") {
if (item.evaluationStatus == "NEW_COMMANDER") {
if (item.commanderHighId == null || item.commanderHighId == "") {
item.evaluationStatus = "APPROVE";
} else {
await new CallAPI()
.PostData(request, "/placement/noti/profile", {
subject: `${item.prefix}${item.firstName} ${item.lastName} ผู้บังคับบัญชาเหนือขึ้นไปอนุมัติข้อตกลง`,
body: `${item.prefix}${item.firstName} ${item.lastName} ผู้บังคับบัญชาเหนือขึ้นไปอนุมัติข้อตกลง`,
receiverUserId: item.commanderHighId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
item.evaluationStatus = "NEW_COMMANDER_HIGH";
}
}
} else {
item.evaluationStatus = requestBody.status.trim().toUpperCase();
}
} else {
item.evaluationStatus = requestBody.status.trim().toUpperCase();
}
} else {
item.evaluationStatus = requestBody.status.trim().toUpperCase();
}
item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name;
await this.kpiUserEvalutionRepository.save(item);
});
item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name;
await this.kpiUserEvalutionRepository.save(item);
}),
);
return new HttpSuccess();
}
@ -1396,7 +1397,7 @@ export class KpiUserEvaluationController extends Controller {
where: { id: In(requestBody.id) },
});
Promise.all(
await Promise.all(
kpiUserEvaluations.map(async (kpiUserEvaluation) => {
kpiUserEvaluation.evaluationStatus = "KP7";
new CallAPI()