อนุมัติ kpi
This commit is contained in:
parent
996549864e
commit
7877b591ce
1 changed files with 150 additions and 35 deletions
|
|
@ -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) => {
|
||||||
item.evaluationStatus = requestBody.status.trim().toUpperCase();
|
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();
|
||||||
|
}
|
||||||
|
} 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) => {
|
||||||
item.evaluationReqEdit = requestBody.status.trim().toUpperCase();
|
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();
|
||||||
|
}
|
||||||
|
} 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);
|
||||||
|
|
@ -579,42 +655,81 @@ export class KpiUserEvaluationController extends Controller {
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API แก้ไขสถานะผลการประเมิน
|
* API แก้ไขสถานะผลการประเมิน
|
||||||
*
|
*
|
||||||
* @summary แก้ไขสถานะผลการประเมิน
|
* @summary แก้ไขสถานะผลการประเมิน
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post("admin/result-status")
|
@Post("admin/result-status")
|
||||||
async ResultStatus(
|
async ResultStatus(
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: {
|
requestBody: {
|
||||||
status: string;
|
status: string;
|
||||||
id: string[];
|
id: string[];
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const list = await this.kpiUserEvalutionRepository.find({
|
let profileId: any = null;
|
||||||
where: { id: In(requestBody.id) },
|
await new CallAPI()
|
||||||
});
|
.GetData(request, "org/profile/keycloak/position")
|
||||||
if (!list || list.length === 0) {
|
.then((x) => {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
profileId = x.profileId;
|
||||||
}
|
})
|
||||||
|
.catch((x) => {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
|
||||||
|
});
|
||||||
|
|
||||||
const hasAllData = requestBody.id.every((id) => list.some((item) => item.id === id));
|
const list = await this.kpiUserEvalutionRepository.find({
|
||||||
|
where: { id: In(requestBody.id) },
|
||||||
|
});
|
||||||
|
if (!list || list.length === 0) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasAllData) {
|
const hasAllData = requestBody.id.every((id) => list.some((item) => item.id === id));
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "พบบางไอดีผู้ประเมินที่ไม่มีข้อมูล");
|
|
||||||
}
|
|
||||||
|
|
||||||
list.forEach(async (item) => {
|
if (!hasAllData) {
|
||||||
item.evaluationResults = requestBody.status.trim().toUpperCase();
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "พบบางไอดีผู้ประเมินที่ไม่มีข้อมูล");
|
||||||
item.lastUpdateUserId = request.user.sub;
|
}
|
||||||
item.lastUpdateFullName = request.user.name;
|
|
||||||
await this.kpiUserEvalutionRepository.save(item);
|
|
||||||
});
|
|
||||||
|
|
||||||
return new HttpSuccess();
|
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();
|
||||||
|
}
|
||||||
|
} 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.lastUpdateFullName = request.user.name;
|
||||||
|
await this.kpiUserEvalutionRepository.save(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue