อนุมัติ kpi

This commit is contained in:
Kittapath 2024-05-13 16:19:46 +07:00
parent 996549864e
commit 7877b591ce

View file

@ -517,6 +517,15 @@ export class KpiUserEvaluationController extends Controller {
id: string[]; id: string[];
}, },
) { ) {
let profileId: any = null;
await new CallAPI()
.GetData(request, "org/profile/keycloak/position")
.then((x) => {
profileId = x.profileId;
})
.catch((x) => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
const list = await this.kpiUserEvalutionRepository.find({ const list = await this.kpiUserEvalutionRepository.find({
where: { id: In(requestBody.id) }, where: { id: In(requestBody.id) },
}); });
@ -531,7 +540,35 @@ export class KpiUserEvaluationController extends Controller {
} }
list.forEach(async (item) => { 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.evaluationStatus = "APPROVE";
} else {
item.evaluationStatus = "NEW_COMMANDER";
}
}
} else if (role == "COMMANDER") {
if (item.evaluationStatus == "NEW_COMMANDER") {
if (item.commanderHighId == null) {
item.evaluationStatus = "APPROVE";
} else {
item.evaluationStatus = "NEW_COMMANDER_HIGH";
}
}
} else {
item.evaluationStatus = requestBody.status.trim().toUpperCase(); item.evaluationStatus = requestBody.status.trim().toUpperCase();
}
} else {
item.evaluationStatus = requestBody.status.trim().toUpperCase();
}
item.lastUpdateUserId = request.user.sub; item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name; item.lastUpdateFullName = request.user.name;
await this.kpiUserEvalutionRepository.save(item); await this.kpiUserEvalutionRepository.save(item);
@ -556,6 +593,16 @@ export class KpiUserEvaluationController extends Controller {
id: string[]; id: string[];
}, },
) { ) {
let profileId: any = null;
await new CallAPI()
.GetData(request, "org/profile/keycloak/position")
.then((x) => {
profileId = x.profileId;
})
.catch((x) => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
const list = await this.kpiUserEvalutionRepository.find({ const list = await this.kpiUserEvalutionRepository.find({
where: { id: In(requestBody.id) }, where: { id: In(requestBody.id) },
}); });
@ -570,7 +617,36 @@ export class KpiUserEvaluationController extends Controller {
} }
list.forEach(async (item) => { 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() == "DONE") {
if (role == "EVALUATOR") {
if (item.evaluationReqEdit == "EVALUATOR") {
if (item.commanderId == null) {
item.evaluationReqEdit = "DONE";
} else {
item.evaluationReqEdit = "COMMANDER";
}
}
} else if (role == "COMMANDER") {
if (item.evaluationReqEdit == "COMMANDER") {
if (item.commanderHighId == null) {
item.evaluationReqEdit = "DONE";
} else {
item.evaluationReqEdit = "COMMANDER_HIGH";
}
}
} else {
item.evaluationReqEdit = requestBody.status.trim().toUpperCase(); item.evaluationReqEdit = requestBody.status.trim().toUpperCase();
}
} else {
item.evaluationReqEdit = requestBody.status.trim().toUpperCase();
}
item.lastUpdateUserId = request.user.sub; item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name; item.lastUpdateFullName = request.user.name;
await this.kpiUserEvalutionRepository.save(item); await this.kpiUserEvalutionRepository.save(item);
@ -595,6 +671,16 @@ export class KpiUserEvaluationController extends Controller {
id: string[]; id: string[];
}, },
) { ) {
let profileId: any = null;
await new CallAPI()
.GetData(request, "org/profile/keycloak/position")
.then((x) => {
profileId = x.profileId;
})
.catch((x) => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
const list = await this.kpiUserEvalutionRepository.find({ const list = await this.kpiUserEvalutionRepository.find({
where: { id: In(requestBody.id) }, where: { id: In(requestBody.id) },
}); });
@ -609,7 +695,36 @@ export class KpiUserEvaluationController extends Controller {
} }
list.forEach(async (item) => { 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() == "DONE") {
if (role == "EVALUATOR") {
if (item.evaluationStatus == "EVALUATING_EVALUATOR") {
if (item.commanderId == null) {
item.evaluationStatus = "COMPLETE";
} else {
item.evaluationStatus = "EVALUATING_COMMANDER";
}
item.evaluationResults = requestBody.status.trim().toUpperCase(); item.evaluationResults = requestBody.status.trim().toUpperCase();
}
} else if (role == "COMMANDER") {
if (item.evaluationStatus == "EVALUATING_COMMANDER") {
if (item.commanderHighId == null) {
item.evaluationStatus = "COMPLETE";
} else {
item.evaluationStatus = "EVALUATING_COMMANDER_HIGH";
}
}
} else {
item.evaluationStatus = "COMPLETE";
}
} else {
// item.evaluationStatus = requestBody.status.trim().toUpperCase();
}
item.lastUpdateUserId = request.user.sub; item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name; item.lastUpdateFullName = request.user.name;
await this.kpiUserEvalutionRepository.save(item); await this.kpiUserEvalutionRepository.save(item);