Compare commits
No commits in common. "dev" and "v1.0.0" have entirely different histories.
4 changed files with 7 additions and 103 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -131,5 +131,3 @@ dist
|
||||||
.yarn/build-state.yml
|
.yarn/build-state.yml
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
.claude
|
|
||||||
|
|
@ -10,7 +10,6 @@ import {
|
||||||
Route,
|
Route,
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Tags,
|
Tags,
|
||||||
Security
|
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
import {
|
import {
|
||||||
|
|
@ -30,7 +29,6 @@ import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
|
||||||
@Route("api/v1/evaluation/document")
|
@Route("api/v1/evaluation/document")
|
||||||
@Tags("document")
|
@Tags("document")
|
||||||
@Security("bearerAuth")
|
|
||||||
export class DocumentController extends Controller {
|
export class DocumentController extends Controller {
|
||||||
/**
|
/**
|
||||||
* @example volume "เล่ม 1"
|
* @example volume "เล่ม 1"
|
||||||
|
|
|
||||||
|
|
@ -2630,22 +2630,13 @@ export class EvaluationController {
|
||||||
if (!evaluation) {
|
if (!evaluation) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||||
}
|
}
|
||||||
// ดึง directors เดิมที่มีอยู่
|
if (!evaluation.evaluation_directors_director) {
|
||||||
const existingDirectors = await this.evaluation_directors_directorRepository.find({
|
evaluation.evaluation_directors_director = [];
|
||||||
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 } });
|
const director = await this.directorRepository.findOne({ where: { id: directorId } });
|
||||||
if (director != null) {
|
if (director != null) {
|
||||||
newDirectors.push({
|
await this.evaluation_directors_directorRepository.save({
|
||||||
directorId: director.id,
|
directorId: director.id,
|
||||||
evaluationId: evaluation.id,
|
evaluationId: evaluation.id,
|
||||||
createdUserId: request.user.sub,
|
createdUserId: request.user.sub,
|
||||||
|
|
@ -2655,12 +2646,8 @@ export class EvaluationController {
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
lastUpdatedAt: 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.lastUpdateUserId = request.user.sub;
|
||||||
evaluation.lastUpdateFullName = request.user.name;
|
evaluation.lastUpdateFullName = request.user.name;
|
||||||
|
|
@ -3361,72 +3348,4 @@ export class EvaluationController {
|
||||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
} 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,17 +59,6 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
// Get rootId from token
|
// Get rootId from token
|
||||||
const rootId = req.app.locals.logData?.orgRootDnaId;
|
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 = {
|
const obj = {
|
||||||
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
|
|
@ -82,7 +71,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
method: req.method,
|
method: req.method,
|
||||||
endpoint: req.url,
|
endpoint: req.url,
|
||||||
responseCode: String(res.statusCode === 304 ? 200 : res.statusCode),
|
responseCode: String(res.statusCode === 304 ? 200 : res.statusCode),
|
||||||
responseDescription: _msg,
|
responseDescription: data?.message,
|
||||||
input: level === 4 ? JSON.stringify(req.body, null, 2) : undefined,
|
input: level === 4 ? JSON.stringify(req.body, null, 2) : undefined,
|
||||||
output: level === 4 ? JSON.stringify(data, null, 2) : undefined,
|
output: level === 4 ? JSON.stringify(data, null, 2) : undefined,
|
||||||
...req.app.locals.logData,
|
...req.app.locals.logData,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue