try catch
This commit is contained in:
parent
810e782a39
commit
8155565186
1 changed files with 64 additions and 51 deletions
|
|
@ -1318,60 +1318,73 @@ export class KpiUserEvaluationController extends Controller {
|
|||
@Body() requestBody: { reason: string; actor: string },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiUserEvaluation) {
|
||||
try{
|
||||
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiUserEvaluation) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
||||
);
|
||||
}
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti/profiles", {
|
||||
subject: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName} มีความเห็นต่างเนื่องจาก: ${requestBody.reason}`,
|
||||
body: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName} มีความเห็นต่างเนื่องจาก: ${requestBody.reason}`,
|
||||
receiverUserIds: [
|
||||
{
|
||||
receiverUserId: kpiUserEvaluation.evaluatorId,
|
||||
notiLink: `${process.env.VITE_URL_USER}/KPI-evaluator/${kpiUserEvaluation.id}`,
|
||||
},
|
||||
],
|
||||
payload: "",
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
isSendNotification: true,
|
||||
})
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
const before = structuredClone(kpiUserEvaluation);
|
||||
let _null: any = null;
|
||||
kpiUserEvaluation.evaluationStatus = "EVALUATING_EVALUATOR";
|
||||
kpiUserEvaluation.isReasonCommander = _null;
|
||||
kpiUserEvaluation.reasonCommander = _null;
|
||||
kpiUserEvaluation.reasonReject = requestBody.reason;
|
||||
kpiUserEvaluation.actorReject = requestBody.actor;
|
||||
kpiUserEvaluation.actorNameReject = request.user.name;
|
||||
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
|
||||
kpiUserEvaluation.lastUpdateFullName = request.user.name;
|
||||
kpiUserEvaluation.lastUpdatedAt = new Date();
|
||||
let kpiReject = {
|
||||
kpiUserEvaluationId: kpiUserEvaluation.id,
|
||||
reason: requestBody.reason,
|
||||
actor: requestBody.actor,
|
||||
fullname: `${kpiUserEvaluation.prefixEvaluator}${kpiUserEvaluation.firstNameEvaluator} ${kpiUserEvaluation.lastNameEvaluator}`,
|
||||
profileId: kpiUserEvaluation.evaluatorId,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
|
||||
await this.kpiUserRejectResultRepository.save(kpiReject);
|
||||
setLogDataDiff(request, { before, after: kpiUserEvaluation });
|
||||
return new HttpSuccess(kpiUserEvaluation.id);
|
||||
} catch (error: any) {
|
||||
console.error("เกิดข้อผิดพลาดระหว่างการประมวลผล:", error);
|
||||
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาดภายในระบบ กรุณาลองใหม่อีกครั้ง",
|
||||
);
|
||||
}
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti/profiles", {
|
||||
subject: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName} มีความเห็นต่างเนื่องจาก: ${requestBody.reason}`,
|
||||
body: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName} มีความเห็นต่างเนื่องจาก: ${requestBody.reason}`,
|
||||
receiverUserIds: [
|
||||
{
|
||||
receiverUserId: kpiUserEvaluation.evaluatorId,
|
||||
notiLink: `${process.env.VITE_URL_USER}/KPI-evaluator/${kpiUserEvaluation.id}`,
|
||||
},
|
||||
],
|
||||
payload: "",
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
isSendNotification: true,
|
||||
})
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
const before = structuredClone(kpiUserEvaluation);
|
||||
let _null: any = null;
|
||||
kpiUserEvaluation.evaluationStatus = "EVALUATING_EVALUATOR";
|
||||
kpiUserEvaluation.isReasonCommander = _null;
|
||||
kpiUserEvaluation.reasonCommander = _null;
|
||||
kpiUserEvaluation.reasonReject = requestBody.reason;
|
||||
kpiUserEvaluation.actorReject = requestBody.actor;
|
||||
kpiUserEvaluation.actorNameReject = request.user.name;
|
||||
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
|
||||
kpiUserEvaluation.lastUpdateFullName = request.user.name;
|
||||
kpiUserEvaluation.lastUpdatedAt = new Date();
|
||||
let kpiReject = {
|
||||
kpiUserEvaluationId: kpiUserEvaluation.id,
|
||||
reason: requestBody.reason,
|
||||
actor: requestBody.actor,
|
||||
fullname: `${kpiUserEvaluation.prefixEvaluator}${kpiUserEvaluation.firstNameEvaluator} ${kpiUserEvaluation.lastNameEvaluator}`,
|
||||
profileId: kpiUserEvaluation.evaluatorId,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
|
||||
await this.kpiUserRejectResultRepository.save(kpiReject);
|
||||
setLogDataDiff(request, { before, after: kpiUserEvaluation });
|
||||
return new HttpSuccess(kpiUserEvaluation.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue