From eb2f4c8b1ba7675d72cb3764a4b03036a1d7b2c4 Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 31 Mar 2026 17:19:49 +0700 Subject: [PATCH 1/3] =?UTF-8?q?fix=20=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B9=80=E0=B8=A1=E0=B8=B4=E0=B8=99?= =?UTF-8?q?=E0=B8=9A=E0=B8=B8=E0=B8=84=E0=B8=84=E0=B8=A5=20(EVA)=20=20?= =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=81=E0=B8=A3?= =?UTF-8?q?=E0=B8=A3=E0=B8=A1=E0=B8=81=E0=B8=B2=E0=B8=A3=20=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B8=9A=E0=B8=9A=E0=B9=81=E0=B8=88=E0=B9=89=E0=B8=87?= =?UTF-8?q?=20Error=20#2396?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/EvaluationController.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/controllers/EvaluationController.ts b/src/controllers/EvaluationController.ts index 622060e..09a09bc 100644 --- a/src/controllers/EvaluationController.ts +++ b/src/controllers/EvaluationController.ts @@ -2630,13 +2630,22 @@ export class EvaluationController { if (!evaluation) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); } - if (!evaluation.evaluation_directors_director) { - evaluation.evaluation_directors_director = []; - } - body.directors.forEach(async (directorId) => { + // ดึง directors เดิมที่มีอยู่ + const existingDirectors = await this.evaluation_directors_directorRepository.find({ + where: { evaluationId: evaluation.id }, + }); + const existingDirectorIds = new Set(existingDirectors.map((d) => d.directorId)); + + // เพิ่ม directors ใหม่ที่ยังไม่มี + const newDirectors = []; + for (const directorId of body.directors) { + // ข้ามถ้ามีอยู่แล้ว + if (existingDirectorIds.has(directorId)) { + continue; + } const director = await this.directorRepository.findOne({ where: { id: directorId } }); if (director != null) { - await this.evaluation_directors_directorRepository.save({ + newDirectors.push({ directorId: director.id, evaluationId: evaluation.id, createdUserId: request.user.sub, @@ -2646,8 +2655,12 @@ export class EvaluationController { createdAt: new Date(), lastUpdatedAt: new Date(), }); + existingDirectorIds.add(director.id); // เพิ่มเพื่อป้องกันซ้ำใน batch เดียวกัน } - }); + } + if (newDirectors.length > 0) { + await this.evaluation_directors_directorRepository.insert(newDirectors); + } evaluation.lastUpdateUserId = request.user.sub; evaluation.lastUpdateFullName = request.user.name; From 8fc32940c5d36df86e1ce5c55c03fca006ab2291 Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 3 Apr 2026 11:51:26 +0700 Subject: [PATCH 2/3] =?UTF-8?q?fix=20=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B8=9A?= =?UTF-8?q?=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B6=E0=B8=81=20log=20(Endpoint?= =?UTF-8?q?=20=E0=B9=84=E0=B8=9F=E0=B8=A5=E0=B9=8C)=20#223?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/middlewares/logs.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index 4bcf111..2ae251c 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -59,6 +59,17 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { // Get rootId from token const rootId = req.app.locals.logData?.orgRootDnaId; + let _msg = data?.message; + if (!_msg) { + if (res.statusCode >= 500) { + _msg = "ไม่สำเร็จ"; + } else if (res.statusCode >= 400) { + _msg = "พบข้อผิดพลาด"; + } else if (res.statusCode >= 200) { + _msg = "สำเร็จ"; + } + } + const obj = { logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info", ip: req.ip, @@ -71,7 +82,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { method: req.method, endpoint: req.url, responseCode: String(res.statusCode === 304 ? 200 : res.statusCode), - responseDescription: data?.message, + responseDescription: _msg, input: level === 4 ? JSON.stringify(req.body, null, 2) : undefined, output: level === 4 ? JSON.stringify(data, null, 2) : undefined, ...req.app.locals.logData, From 96ea1a21413a47246ac898ffdb746c8c818b7394 Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 3 Apr 2026 17:15:18 +0700 Subject: [PATCH 3/3] =?UTF-8?q?api=20=E0=B8=A5=E0=B8=9A=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=81=E0=B8=A3?= =?UTF-8?q?=E0=B8=A3=E0=B8=A1=E0=B8=81=E0=B8=B2=E0=B8=A3=20=E0=B9=81?= =?UTF-8?q?=E0=B8=A5=E0=B8=B0=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B8=8A=E0=B8=B8=E0=B8=A1=20#2399?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/EvaluationController.ts | 68 +++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/controllers/EvaluationController.ts b/src/controllers/EvaluationController.ts index 09a09bc..5bd7ca2 100644 --- a/src/controllers/EvaluationController.ts +++ b/src/controllers/EvaluationController.ts @@ -3361,4 +3361,72 @@ export class EvaluationController { } else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error); } } + + /** + * API สำหรับลบกรรมการออกจากการประเมิน + * @summary ลบกรรมการในการประเมิน (ADMIN) + * @param {string} id id ของ evaluation_directors_director + */ + @Delete("del-director/{id}") + async removeEvaluationDirector( + @Path() id: string, + @Request() request: RequestWithUser, + ) { + try { + const evaluationDirector = + await this.evaluation_directors_directorRepository.findOneBy({ id }); + + if (!evaluationDirector) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกรรมการ"); + } + + await this.evaluation_directors_directorRepository.remove(evaluationDirector, { + data: request, + }); + + return new HttpSuccess(); + } catch (error: any) { + if (error instanceof HttpError) { + throw error; + } else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error); + } + } + + /** + * API สำหรับลบการประชุมออกจากการประเมิน + * @summary ลบการประชุมในการประเมิน (ADMIN) + * @param {string} evaluationId id ของ evaluation + * @param {string} meetingId id ของ meeting + */ + @Delete("del-meeting/{evaluationId}/{meetingId}") + async removeMeetingFromEvaluation( + @Path() evaluationId: string, + @Path() meetingId: string, + @Request() request: RequestWithUser, + ) { + try { + const evaluation = await this.evaluationRepository.findOne({ + where: { id: evaluationId }, + relations: { meetings: true }, + }); + + if (!evaluation) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน"); + } + + const meetingExists = evaluation.meetings.some((m) => m.id === meetingId); + if (!meetingExists) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประชุมในการประเมินนี้"); + } + + evaluation.meetings = evaluation.meetings.filter((m) => m.id !== meetingId); + await this.evaluationRepository.save(evaluation, { data: request }); + + return new HttpSuccess(); + } catch (error: any) { + if (error instanceof HttpError) { + throw error; + } else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error); + } + } }