Compare commits

..

8 commits
v1.0.0 ... dev

Author SHA1 Message Date
harid
2714ea8b8a Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 59s
2026-04-03 17:15:50 +07:00
harid
96ea1a2141 api ลบรายชื่อกรรมการ และ รายการการประชุม #2399 2026-04-03 17:15:18 +07:00
harid
1a2b87a94a Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 55s
2026-04-03 11:52:21 +07:00
harid
8fc32940c5 fix ไม่บันทึก log (Endpoint ไฟล์) #223 2026-04-03 11:51:26 +07:00
harid
5d9ca12975 Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 57s
2026-03-31 17:20:09 +07:00
harid
eb2f4c8b1b fix ระบบประเมินบุคคล (EVA) เพิ่มรายชื่อกรรมการ ระบบแจ้ง Error #2396 2026-03-31 17:19:49 +07:00
harid
ee7f392ab4 Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 59s
2026-03-25 17:31:26 +07:00
harid
640c7eabee fix endPoint /document ไม่เก็บ log 2026-03-25 17:30:57 +07:00
4 changed files with 103 additions and 7 deletions

2
.gitignore vendored
View file

@ -131,3 +131,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.claude

View file

@ -10,6 +10,7 @@ import {
Route,
SuccessResponse,
Tags,
Security
} from "tsoa";
import HttpStatus from "../interfaces/http-status";
import {
@ -29,6 +30,7 @@ import HttpStatusCode from "../interfaces/http-status";
@Route("api/v1/evaluation/document")
@Tags("document")
@Security("bearerAuth")
export class DocumentController extends Controller {
/**
* @example volume "เล่ม 1"

View file

@ -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 = [];
// ดึง 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;
}
body.directors.forEach(async (directorId) => {
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;
@ -3348,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);
}
}
}

View file

@ -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,