เพิ่ม 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

@ -46,11 +46,8 @@ export class kpiLinkController extends Controller {
* @returns
*/
@Post()
async createKpiLink(
@Body() requestBody: createKpiLink,
@Request() request: RequestWithUser,
) {
await new permission().PermissionCreate(request,"SYS_EVA_COMPETENCY");
async createKpiLink(@Body() requestBody: createKpiLink, @Request() request: RequestWithUser) {
await new permission().PermissionCreate(request, "SYS_EVA_COMPETENCY");
const chkkpiGroup = await this.kpiGroupRepository.findOne({
where: {
id: requestBody.kpiGroupId,
@ -71,7 +68,7 @@ export class kpiLinkController extends Controller {
await this.kpiLinkRepository.save(kpiLink);
if (requestBody.positions != null) {
Promise.all(
await Promise.all(
requestBody.positions.map(async (positionName) => {
let position = new Position();
position.name = positionName;
@ -110,7 +107,7 @@ export class kpiLinkController extends Controller {
@Body() requestBody: createKpiLink,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request,"SYS_EVA_COMPETENCY");
await new permission().PermissionUpdate(request, "SYS_EVA_COMPETENCY");
const chkKpiLink = await this.kpiLinkRepository.findOne({
where: {
id: id,
@ -134,7 +131,7 @@ export class kpiLinkController extends Controller {
chkKpiLink.lastUpdateFullName = request.user.name;
if (requestBody.positions != null) {
Promise.all(
await Promise.all(
requestBody.positions.map(async (positionName) => {
let position = new Position();
position.name = positionName;
@ -203,7 +200,7 @@ export class kpiLinkController extends Controller {
*/
@Delete("{id}")
async deleteKpiLink(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request,"SYS_EVA_COMPETENCY");
await new permission().PermissionDelete(request, "SYS_EVA_COMPETENCY");
const kpiLink = await this.kpiLinkRepository.findOne({
where: { id: id },
relations: ["kpiCapacitys"],

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()