try catch

This commit is contained in:
Adisak 2025-10-28 14:30:00 +07:00
parent 810e782a39
commit 8155565186

View file

@ -1318,60 +1318,73 @@ export class KpiUserEvaluationController extends Controller {
@Body() requestBody: { reason: string; actor: string }, @Body() requestBody: { reason: string; actor: string },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ try{
where: { id: id }, const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
}); where: { id: id },
if (!kpiUserEvaluation) { });
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( 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);
} }
/** /**