Merge branch 'develop'

This commit is contained in:
Warunee Tamkoo 2025-03-15 19:14:56 +07:00
commit bc2b1ca42f
7 changed files with 1460 additions and 1174 deletions

View file

@ -46,6 +46,7 @@ export class DirectorController {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string, @Query("keyword") keyword?: string,
) { ) {
try {
await new permission().PermissionList(request, "SYS_EVA_INFO"); await new permission().PermissionList(request, "SYS_EVA_INFO");
const directors = await AppDataSource.getRepository(Director) const directors = await AppDataSource.getRepository(Director)
.createQueryBuilder("director") .createQueryBuilder("director")
@ -59,9 +60,12 @@ export class DirectorController {
keyword: `%${keyword}%`, keyword: `%${keyword}%`,
}, },
) )
.orWhere(keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1", { .orWhere(
keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1",
{
keyword: `%${keyword}%`, keyword: `%${keyword}%`,
}) },
)
.orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", { .orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", {
keyword: `%${keyword}%`, keyword: `%${keyword}%`,
}) })
@ -76,6 +80,11 @@ export class DirectorController {
.getMany(); .getMany();
return new HttpSuccess(directors); return new HttpSuccess(directors);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
@Get("admin") @Get("admin")
@ -85,6 +94,7 @@ export class DirectorController {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string, @Query("keyword") keyword?: string,
) { ) {
try {
const directors = await AppDataSource.getRepository(Director) const directors = await AppDataSource.getRepository(Director)
.createQueryBuilder("director") .createQueryBuilder("director")
.andWhere( .andWhere(
@ -97,9 +107,12 @@ export class DirectorController {
keyword: `%${keyword}%`, keyword: `%${keyword}%`,
}, },
) )
.orWhere(keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1", { .orWhere(
keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1",
{
keyword: `%${keyword}%`, keyword: `%${keyword}%`,
}) },
)
.orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", { .orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", {
keyword: `%${keyword}%`, keyword: `%${keyword}%`,
}) })
@ -113,6 +126,11 @@ export class DirectorController {
.take(pageSize) .take(pageSize)
.getMany(); .getMany();
return new HttpSuccess(directors); return new HttpSuccess(directors);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -123,6 +141,7 @@ export class DirectorController {
*/ */
@Get("{id}") @Get("{id}")
async one(@Path() id: string, @Request() request: RequestWithUser) { async one(@Path() id: string, @Request() request: RequestWithUser) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO"); let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO");
const director = await this.directorRepository.findOne({ where: { id } }); const director = await this.directorRepository.findOne({ where: { id } });
@ -130,6 +149,11 @@ export class DirectorController {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
} }
return new HttpSuccess(director); return new HttpSuccess(director);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -140,6 +164,7 @@ export class DirectorController {
*/ */
@Post() @Post()
async save(@Body() requestBody: CreateDirector, @Request() request: RequestWithUser) { async save(@Body() requestBody: CreateDirector, @Request() request: RequestWithUser) {
try {
await new permission().PermissionCreate(request, "SYS_EVA_INFO"); await new permission().PermissionCreate(request, "SYS_EVA_INFO");
let directorDup = await this.directorRepository.findOne({ let directorDup = await this.directorRepository.findOne({
where: { firstName: requestBody.firstName, lastName: requestBody.lastName }, where: { firstName: requestBody.firstName, lastName: requestBody.lastName },
@ -161,6 +186,11 @@ export class DirectorController {
setLogDataDiff(request, { before, after: director }); setLogDataDiff(request, { before, after: director });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -171,6 +201,7 @@ export class DirectorController {
*/ */
@Put("{id}") @Put("{id}")
async update(@Path() id: string, @Body() u: CreateDirector, @Request() request: RequestWithUser) { async update(@Path() id: string, @Body() u: CreateDirector, @Request() request: RequestWithUser) {
try {
await new permission().PermissionUpdate(request, "SYS_EVA_INFO"); await new permission().PermissionUpdate(request, "SYS_EVA_INFO");
let directorDup = await this.directorRepository.findOne({ let directorDup = await this.directorRepository.findOne({
where: { firstName: u.firstName, lastName: u.lastName, id: Not(id) }, where: { firstName: u.firstName, lastName: u.lastName, id: Not(id) },
@ -190,6 +221,11 @@ export class DirectorController {
await this.directorRepository.save(director, { data: request }); await this.directorRepository.save(director, { data: request });
setLogDataDiff(request, { before, after: director }); setLogDataDiff(request, { before, after: director });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -200,6 +236,7 @@ export class DirectorController {
*/ */
@Delete("{id}") @Delete("{id}")
async remove(id: string, @Request() request: RequestWithUser) { async remove(id: string, @Request() request: RequestWithUser) {
try {
await new permission().PermissionDelete(request, "SYS_EVA_INFO"); await new permission().PermissionDelete(request, "SYS_EVA_INFO");
let director = await this.directorRepository.findOneBy({ id }); let director = await this.directorRepository.findOneBy({ id });
if (!director) { if (!director) {
@ -207,5 +244,10 @@ export class DirectorController {
} }
await this.directorRepository.remove(director, { data: request }); await this.directorRepository.remove(director, { data: request });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
} }

View file

@ -23,6 +23,8 @@ import {
} from "../services/storage"; } from "../services/storage";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { Evaluation } from "../entities/Evaluation"; import { Evaluation } from "../entities/Evaluation";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
@Route("api/v1/evaluation/document") @Route("api/v1/evaluation/document")
@Tags("document") @Tags("document")
@ -58,9 +60,15 @@ export class DocumentController extends Controller {
}, },
]) ])
public async getFile(@Path() volume: string, @Path() id: string) { public async getFile(@Path() volume: string, @Path() id: string) {
try {
const list = await listFile(["ระบบประเมิน", volume, id]); const list = await listFile(["ระบบประเมิน", volume, id]);
if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้"); if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
return list; return list;
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -97,9 +105,15 @@ export class DocumentController extends Controller {
downloadUrl: "https://.../...", // Presigned Download URL 7 Days Exp downloadUrl: "https://.../...", // Presigned Download URL 7 Days Exp
}) })
public async getFileDownload(@Path() id: string, @Path() volume: string, @Path() file: string) { public async getFileDownload(@Path() id: string, @Path() volume: string, @Path() file: string) {
try {
const data = await downloadFile(["ระบบประเมิน", volume, id], file); const data = await downloadFile(["ระบบประเมิน", volume, id], file);
if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้"); if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
return data; return data;
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -194,6 +208,7 @@ export class DocumentController extends Controller {
replace?: boolean; replace?: boolean;
}, },
) { ) {
try {
const path = ["ระบบประเมิน", volume]; const path = ["ระบบประเมิน", volume];
if (!(await createFolder(path, id, true))) { if (!(await createFolder(path, id, true))) {
@ -223,7 +238,10 @@ export class DocumentController extends Controller {
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(dotIndex) : ""; dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(dotIndex) : "";
let i = 1; let i = 1;
while (list.findIndex((v) => v.fileName === fileName) !== -1 || used.includes(fileName)) { while (
list.findIndex((v) => v.fileName === fileName) !== -1 ||
used.includes(fileName)
) {
fileName = `${originalName} (${i++})`; fileName = `${originalName} (${i++})`;
if (dotIndex !== -1) fileName += extension; if (dotIndex !== -1) fileName += extension;
} }
@ -252,6 +270,11 @@ export class DocumentController extends Controller {
} }
return Object.fromEntries(result); return Object.fromEntries(result);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -276,6 +299,7 @@ export class DocumentController extends Controller {
metadata?: { [key: string]: unknown }; metadata?: { [key: string]: unknown };
}, },
) { ) {
try {
const props = body; const props = body;
const result = await updateFile(["ระบบประเมิน", volume, id], file, props); const result = await updateFile(["ระบบประเมิน", volume, id], file, props);
@ -283,6 +307,11 @@ export class DocumentController extends Controller {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้"); throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
} }
return this.setStatus(HttpStatus.NO_CONTENT); return this.setStatus(HttpStatus.NO_CONTENT);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -293,12 +322,18 @@ export class DocumentController extends Controller {
*/ */
@Delete("{volume}/{id}") @Delete("{volume}/{id}")
public async deleteFolder(@Path() volume: string, @Path() id: string) { public async deleteFolder(@Path() volume: string, @Path() id: string) {
try {
const result = await deleteFolder(["ระบบประเมิน", volume], id); const result = await deleteFolder(["ระบบประเมิน", volume], id);
if (!result) { if (!result) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้"); throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
} }
return this.setStatus(HttpStatus.NO_CONTENT); return this.setStatus(HttpStatus.NO_CONTENT);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -310,11 +345,17 @@ export class DocumentController extends Controller {
*/ */
@Delete("{volume}/{id}/{file}") @Delete("{volume}/{id}/{file}")
public async deleteFile(@Path() volume: string, @Path() id: string, @Path() file: string) { public async deleteFile(@Path() volume: string, @Path() id: string, @Path() file: string) {
try {
const result = await deleteFile(["ระบบประเมิน", volume, id], file); const result = await deleteFile(["ระบบประเมิน", volume, id], file);
if (!result) { if (!result) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้"); throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
} }
return this.setStatus(HttpStatus.NO_CONTENT); return this.setStatus(HttpStatus.NO_CONTENT);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
} }

View file

@ -88,6 +88,7 @@ export class EvaluationController {
status?: string[]; status?: string[];
}, },
) { ) {
try {
// await new permission().PermissionList(request, "SYS_EVA_REQ"); // await new permission().PermissionList(request, "SYS_EVA_REQ");
let _data = await new permission().PermissionOrgList(request, "SYS_EVA_REQ"); let _data = await new permission().PermissionOrgList(request, "SYS_EVA_REQ");
const [evaluation, total] = await AppDataSource.getRepository(Evaluation) const [evaluation, total] = await AppDataSource.getRepository(Evaluation)
@ -145,7 +146,9 @@ export class EvaluationController {
.andWhere( .andWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.andWhere( qb.andWhere(
body.status == undefined || body.status == null || body.status.every((s) => s === "ALL") body.status == undefined ||
body.status == null ||
body.status.every((s) => s === "ALL")
? "1=1" ? "1=1"
: `evaluation.step In (:status)`, : `evaluation.step In (:status)`,
{ {
@ -171,6 +174,11 @@ export class EvaluationController {
.getManyAndCount(); .getManyAndCount();
return new HttpSuccess({ data: evaluation, total }); return new HttpSuccess({ data: evaluation, total });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -198,12 +206,15 @@ export class EvaluationController {
status?: string[]; status?: string[];
}, },
) { ) {
try {
const [evaluation, total] = await AppDataSource.getRepository(Evaluation) const [evaluation, total] = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation") .createQueryBuilder("evaluation")
.andWhere( .andWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.andWhere( qb.andWhere(
body.status == undefined || body.status == null || body.status.every((s) => s === "ALL") body.status == undefined ||
body.status == null ||
body.status.every((s) => s === "ALL")
? "1=1" ? "1=1"
: `evaluation.step In (:status)`, : `evaluation.step In (:status)`,
{ {
@ -235,6 +246,11 @@ export class EvaluationController {
})); }));
return new HttpSuccess({ data: _evaluation, total }); return new HttpSuccess({ data: _evaluation, total });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -253,6 +269,7 @@ export class EvaluationController {
}, },
]) ])
async checkStatus(@Request() request: { user: { sub: string; name: string } }) { async checkStatus(@Request() request: { user: { sub: string; name: string } }) {
try {
const userId = request.user.sub; //UserId const userId = request.user.sub; //UserId
const fullName = request.user.name; //FullName const fullName = request.user.name; //FullName
@ -281,6 +298,11 @@ export class EvaluationController {
expertiseId, expertiseId,
}; };
return new HttpSuccess(responseData); return new HttpSuccess(responseData);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -297,6 +319,7 @@ export class EvaluationController {
}, },
]) ])
async check(@Request() request: RequestWithUser, @Path() id: string) { async check(@Request() request: RequestWithUser, @Path() id: string) {
try {
const evaluation = await this.evaluationRepository.findOne({ const evaluation = await this.evaluationRepository.findOne({
where: { id }, where: { id },
select: ["step"], select: ["step"],
@ -306,6 +329,11 @@ export class EvaluationController {
return "ไม่พบข้อมูล"; return "ไม่พบข้อมูล";
} }
return new HttpSuccess(evaluation); return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -583,7 +611,9 @@ export class EvaluationController {
id: evaluation.id, id: evaluation.id,
}); });
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
/** /**
@ -657,7 +687,9 @@ export class EvaluationController {
id: evaluation.id, id: evaluation.id,
}); });
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -694,7 +726,9 @@ export class EvaluationController {
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -722,7 +756,9 @@ export class EvaluationController {
} }
return new HttpSuccess(evaluation); return new HttpSuccess(evaluation);
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -825,6 +861,7 @@ export class EvaluationController {
}, },
]) ])
async checkSpecGet(@Request() request: RequestWithUser, @Path() id: string) { async checkSpecGet(@Request() request: RequestWithUser, @Path() id: string) {
try {
const evaluation = await AppDataSource.getRepository(Evaluation) const evaluation = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation") .createQueryBuilder("evaluation")
.leftJoin("evaluation.education", "education") .leftJoin("evaluation.education", "education")
@ -994,6 +1031,11 @@ export class EvaluationController {
return "ไม่พบข้อมูล"; return "ไม่พบข้อมูล";
} }
return new HttpSuccess(dataEvaluation); return new HttpSuccess(dataEvaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -1095,6 +1137,7 @@ export class EvaluationController {
}, },
]) ])
async checkSpecGetByAdmin(@Request() request: RequestWithUser, @Path() id: string) { async checkSpecGetByAdmin(@Request() request: RequestWithUser, @Path() id: string) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ"); let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
const evaluation = await AppDataSource.getRepository(Evaluation) const evaluation = await AppDataSource.getRepository(Evaluation)
@ -1266,6 +1309,11 @@ export class EvaluationController {
return "ไม่พบข้อมูล"; return "ไม่พบข้อมูล";
} }
return new HttpSuccess(dataEvaluation); return new HttpSuccess(dataEvaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
* API * API
@ -1319,7 +1367,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1363,7 +1413,9 @@ export class EvaluationController {
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1419,7 +1471,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1463,7 +1517,9 @@ export class EvaluationController {
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1520,7 +1576,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1581,7 +1639,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1637,7 +1697,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1693,7 +1755,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1706,8 +1770,9 @@ export class EvaluationController {
*/ */
@Put("announce/{id}") @Put("announce/{id}")
async EV1_042(@Path() id: string, @Request() request: RequestWithUser) { async EV1_042(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try { try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } }); const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) { if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
@ -1757,7 +1822,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1801,7 +1868,9 @@ export class EvaluationController {
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1814,8 +1883,9 @@ export class EvaluationController {
*/ */
@Put("wait-check-doc-v2/{id}") @Put("wait-check-doc-v2/{id}")
async EV1_031(@Path() id: string, @Request() request: RequestWithUser) { async EV1_031(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try { try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } }); const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) { if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
@ -1857,7 +1927,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1874,8 +1946,9 @@ export class EvaluationController {
@Body() body: { reason: string }, @Body() body: { reason: string },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try { try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } }); const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) { if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
@ -1919,7 +1992,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1944,7 +2019,9 @@ export class EvaluationController {
}); });
return new HttpSuccess(stepHistory); return new HttpSuccess(stepHistory);
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -1996,7 +2073,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2048,7 +2127,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2061,8 +2142,9 @@ export class EvaluationController {
*/ */
@Get("director-meeting/{id}") @Get("director-meeting/{id}")
async DirectorAndMeeting(@Request() request: RequestWithUser, @Path() id: string) { async DirectorAndMeeting(@Request() request: RequestWithUser, @Path() id: string) {
await new permission().PermissionList(request, "SYS_EVA_REQ");
try { try {
await new permission().PermissionList(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ const evaluation = await this.evaluationRepository.findOne({
where: { id }, where: { id },
relations: ["directors", "meetings"], relations: ["directors", "meetings"],
@ -2093,7 +2175,9 @@ export class EvaluationController {
return new HttpSuccess({ directors, meetings }); return new HttpSuccess({ directors, meetings });
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2134,7 +2218,9 @@ export class EvaluationController {
return new HttpSuccess(responseData); return new HttpSuccess(responseData);
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2147,9 +2233,10 @@ export class EvaluationController {
*/ */
@Get("admin/check-date/{id}") @Get("admin/check-date/{id}")
async CheckRangeDateByAdmin(@Path() id: string, @Request() request: RequestWithUser) { async CheckRangeDateByAdmin(@Path() id: string, @Request() request: RequestWithUser) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ"); let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ const evaluation = await this.evaluationRepository.findOne({
where: { id }, where: { id },
}); });
@ -2177,7 +2264,9 @@ export class EvaluationController {
return new HttpSuccess(responseData); return new HttpSuccess(responseData);
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2213,7 +2302,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2249,7 +2340,9 @@ export class EvaluationController {
.catch((x) => {}); .catch((x) => {});
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2279,7 +2372,9 @@ export class EvaluationController {
} }
return new HttpSuccess(evaluation); return new HttpSuccess(evaluation);
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2292,9 +2387,10 @@ export class EvaluationController {
*/ */
@Get("admin/doc1-signer/{id}") @Get("admin/doc1-signer/{id}")
async DocumentSigner1ByAdmin(@Path() id: string, @Request() request: RequestWithUser) { async DocumentSigner1ByAdmin(@Path() id: string, @Request() request: RequestWithUser) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ"); let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ const evaluation = await this.evaluationRepository.findOne({
where: { id }, where: { id },
select: [ select: [
@ -2311,7 +2407,9 @@ export class EvaluationController {
} }
return new HttpSuccess(evaluation); return new HttpSuccess(evaluation);
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2343,7 +2441,9 @@ export class EvaluationController {
} }
return new HttpSuccess(evaluation); return new HttpSuccess(evaluation);
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2356,9 +2456,10 @@ export class EvaluationController {
*/ */
@Get("admin/doc2-signer/{id}") @Get("admin/doc2-signer/{id}")
async DocumentSigner2ByAdmin(@Path() id: string, @Request() request: RequestWithUser) { async DocumentSigner2ByAdmin(@Path() id: string, @Request() request: RequestWithUser) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ"); let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ const evaluation = await this.evaluationRepository.findOne({
where: { id }, where: { id },
select: [ select: [
@ -2377,7 +2478,9 @@ export class EvaluationController {
} }
return new HttpSuccess(evaluation); return new HttpSuccess(evaluation);
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2434,7 +2537,9 @@ export class EvaluationController {
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2494,7 +2599,9 @@ export class EvaluationController {
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
return error.status; if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
@ -2507,6 +2614,7 @@ export class EvaluationController {
*/ */
@Delete("{id}") @Delete("{id}")
async delete_evaluation(id: string, @Request() request: RequestWithUser) { async delete_evaluation(id: string, @Request() request: RequestWithUser) {
try {
// await new permission().PermissionDelete(request, "SYS_EVA_REQ"); // await new permission().PermissionDelete(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ const evaluation = await this.evaluationRepository.findOne({
where: { id }, where: { id },
@ -2544,6 +2652,11 @@ export class EvaluationController {
"ไม่สามารถลบข้อมูลในสถานะ" + "'" + ConvertToThaiStep(evaluation.step) + "'" + "ได้", "ไม่สามารถลบข้อมูลในสถานะ" + "'" + ConvertToThaiStep(evaluation.step) + "'" + "ได้",
); );
} }
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -2560,6 +2673,7 @@ export class EvaluationController {
}, },
]) ])
async checkByAdmin(@Request() request: RequestWithUser, @Path() id: string) { async checkByAdmin(@Request() request: RequestWithUser, @Path() id: string) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ"); let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ const evaluation = await this.evaluationRepository.findOne({
@ -2571,5 +2685,10 @@ export class EvaluationController {
return "ไม่พบข้อมูล"; return "ไม่พบข้อมูล";
} }
return new HttpSuccess(evaluation); return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
} }

View file

@ -47,6 +47,7 @@ export class MeetingController {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string, @Query("keyword") keyword?: string,
) { ) {
try {
await new permission().PermissionList(request, "SYS_EVA_INFO"); await new permission().PermissionList(request, "SYS_EVA_INFO");
const meetings = await AppDataSource.getRepository(Meeting) const meetings = await AppDataSource.getRepository(Meeting)
.createQueryBuilder("meeting") .createQueryBuilder("meeting")
@ -64,6 +65,11 @@ export class MeetingController {
.take(pageSize) .take(pageSize)
.getMany(); .getMany();
return new HttpSuccess(meetings); return new HttpSuccess(meetings);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
@Get("admin") @Get("admin")
@ -73,6 +79,7 @@ export class MeetingController {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string, @Query("keyword") keyword?: string,
) { ) {
try {
const meetings = await AppDataSource.getRepository(Meeting) const meetings = await AppDataSource.getRepository(Meeting)
.createQueryBuilder("meeting") .createQueryBuilder("meeting")
.andWhere( .andWhere(
@ -89,6 +96,11 @@ export class MeetingController {
.take(pageSize) .take(pageSize)
.getMany(); .getMany();
return new HttpSuccess(meetings); return new HttpSuccess(meetings);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -99,6 +111,7 @@ export class MeetingController {
*/ */
@Get("{id}") @Get("{id}")
async one(@Path() id: string, @Request() request: RequestWithUser) { async one(@Path() id: string, @Request() request: RequestWithUser) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO"); let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO");
const meeting = await this.meetingRepository.findOne({ where: { id } }); const meeting = await this.meetingRepository.findOne({ where: { id } });
@ -106,6 +119,11 @@ export class MeetingController {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
} }
return new HttpSuccess(meeting); return new HttpSuccess(meeting);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -116,6 +134,7 @@ export class MeetingController {
*/ */
@Post() @Post()
async save(@Body() requestBody: CreateMeeting, @Request() request: RequestWithUser) { async save(@Body() requestBody: CreateMeeting, @Request() request: RequestWithUser) {
try {
await new permission().PermissionCreate(request, "SYS_EVA_INFO"); await new permission().PermissionCreate(request, "SYS_EVA_INFO");
const meeting = Object.assign(new Meeting(), requestBody); const meeting = Object.assign(new Meeting(), requestBody);
meeting.createdUserId = request.user.sub; meeting.createdUserId = request.user.sub;
@ -130,6 +149,11 @@ export class MeetingController {
setLogDataDiff(request, { before, after: meeting }); setLogDataDiff(request, { before, after: meeting });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -140,6 +164,7 @@ export class MeetingController {
*/ */
@Put("{id}") @Put("{id}")
async update(@Path() id: string, @Body() u: CreateMeeting, @Request() request: RequestWithUser) { async update(@Path() id: string, @Body() u: CreateMeeting, @Request() request: RequestWithUser) {
try {
await new permission().PermissionUpdate(request, "SYS_EVA_INFO"); await new permission().PermissionUpdate(request, "SYS_EVA_INFO");
let meeting = await this.meetingRepository.findOneBy({ id }); let meeting = await this.meetingRepository.findOneBy({ id });
if (!meeting) { if (!meeting) {
@ -154,6 +179,11 @@ export class MeetingController {
setLogDataDiff(request, { before, after: meeting }); setLogDataDiff(request, { before, after: meeting });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -164,6 +194,7 @@ export class MeetingController {
*/ */
@Delete("{id}") @Delete("{id}")
async remove(id: string, @Request() request: RequestWithUser) { async remove(id: string, @Request() request: RequestWithUser) {
try {
await new permission().PermissionDelete(request, "SYS_EVA_INFO"); await new permission().PermissionDelete(request, "SYS_EVA_INFO");
let meeting = await this.meetingRepository.findOneBy({ id }); let meeting = await this.meetingRepository.findOneBy({ id });
if (!meeting) { if (!meeting) {
@ -171,5 +202,10 @@ export class MeetingController {
} }
await this.meetingRepository.remove(meeting, { data: request }); await this.meetingRepository.remove(meeting, { data: request });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
} }

View file

@ -58,18 +58,26 @@ export class ReoportController {
* *
*/ */
@Get() @Get()
async sumaryEvaluationReport(@Query("year") year?: string, @Query("rootid") rootId?: string, @Query("nameOrg") nameOrg?: string) { async sumaryEvaluationReport(
@Query("year") year?: string,
@Query("rootid") rootId?: string,
@Query("nameOrg") nameOrg?: string,
) {
try {
const yearInAD = year ? year : null; const yearInAD = year ? year : null;
const yearInBE = yearInAD ? (parseInt(yearInAD) - 543).toString() : null; const yearInBE = yearInAD ? (parseInt(yearInAD) - 543).toString() : null;
let evaluation = []; let evaluation = [];
evaluation = await AppDataSource.getRepository(Evaluation) evaluation = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation") .createQueryBuilder("evaluation")
.where('evaluation.evaluationResult NOT IN (:...evaluationResults)', { evaluationResults: ['PENDING'] }) .where("evaluation.evaluationResult NOT IN (:...evaluationResults)", {
.andWhere( yearInBE && yearInBE != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInBE }) evaluationResults: ["PENDING"],
.andWhere('evaluation.orgRootId = :rootId',{ rootId: rootId }) })
.andWhere('evaluation.step = :step', { step: 'DONE' }) .andWhere(yearInBE && yearInBE != null ? "YEAR(createdAt) = :year" : "1=1", {
year: yearInBE,
})
.andWhere("evaluation.orgRootId = :rootId", { rootId: rootId })
.andWhere("evaluation.step = :step", { step: "DONE" })
.getMany(); .getMany();
const groupedData = evaluation.reduce((acc: any, item) => { const groupedData = evaluation.reduce((acc: any, item) => {
@ -82,9 +90,9 @@ export class ReoportController {
notPassCount: 0, notPassCount: 0,
}; };
} }
if (item.evaluationResult === 'PASS') { if (item.evaluationResult === "PASS") {
acc[key].passCount++; acc[key].passCount++;
} else if (item.evaluationResult === 'NOTPASS') { } else if (item.evaluationResult === "NOTPASS") {
acc[key].notPassCount++; acc[key].notPassCount++;
} }
return acc; return acc;
@ -113,15 +121,27 @@ export class ReoportController {
template: "summary-evaluation", template: "summary-evaluation",
reportName: "xlsx-report", reportName: "xlsx-report",
data: { data: {
year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()), year: year
? Extension.ToThaiNumber(year.toString())
: Extension.ToThaiNumber(new Date().getFullYear().toString()),
date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())),
mainAgency: rootId && result.length > 0?result[0].agency: rootId && result.length === 0 ? '':'หน่วยงานทั้งหมด', mainAgency:
rootId && result.length > 0
? result[0].agency
: rootId && result.length === 0
? ""
: "หน่วยงานทั้งหมด",
list: result, list: result,
total: Extension.ToThaiNumber(submitter.toString()), total: Extension.ToThaiNumber(submitter.toString()),
sumPass: Extension.ToThaiNumber(sumPass.toString()), sumPass: Extension.ToThaiNumber(sumPass.toString()),
sumNotPass: Extension.ToThaiNumber(sumNotPass.toString()), sumNotPass: Extension.ToThaiNumber(sumNotPass.toString()),
}, },
}); });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
/** /**
@ -133,6 +153,7 @@ export class ReoportController {
*/ */
@Get("check-spec-report/{id}") @Get("check-spec-report/{id}")
async checkSpecGetReport(@Request() request: RequestWithUser, @Path() id: string) { async checkSpecGetReport(@Request() request: RequestWithUser, @Path() id: string) {
try {
const evaluation = await AppDataSource.getRepository(Evaluation) const evaluation = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation") .createQueryBuilder("evaluation")
.leftJoin("evaluation.education", "education") .leftJoin("evaluation.education", "education")
@ -279,10 +300,7 @@ export class ReoportController {
isHaveMinPeriodOrHoldPos: evaluation.isHaveMinPeriodOrHoldPos, isHaveMinPeriodOrHoldPos: evaluation.isHaveMinPeriodOrHoldPos,
type: evaluation.type, type: evaluation.type,
prefix: evaluation.prefix, prefix: evaluation.prefix,
fullName: fullName: evaluation.fullName ? `${evaluation.fullName}` : "-",
evaluation.prefix && evaluation.fullName
? `${evaluation.prefix}${evaluation.fullName}`
: "-",
position: evaluation.position ? evaluation.position : "-", position: evaluation.position ? evaluation.position : "-",
posNo: evaluation.posNo ? Extension.ToThaiNumber(evaluation.posNo) : "-", posNo: evaluation.posNo ? Extension.ToThaiNumber(evaluation.posNo) : "-",
oc: evaluation.oc ? evaluation.oc : "-", oc: evaluation.oc ? evaluation.oc : "-",
@ -322,7 +340,9 @@ export class ReoportController {
startDate: education.startDate, startDate: education.startDate,
endDate: education.endDate, endDate: education.endDate,
finishDate: education.finishDate finishDate: education.finishDate
? Extension.ToThaiNumber(Extension.ToThaiShortDate(education.finishDate).toString()) ? Extension.ToThaiNumber(
Extension.ToThaiShortDate(education.finishDate).toString(),
)
: "-", : "-",
isEducation: education.isEducation, isEducation: education.isEducation,
degree: education.degree ? Extension.ToThaiNumber(education.degree) : "-", degree: education.degree ? Extension.ToThaiNumber(education.degree) : "-",
@ -441,5 +461,10 @@ export class ReoportController {
return "ไม่พบข้อมูล"; return "ไม่พบข้อมูล";
} }
return new HttpSuccess(dataEvaluation); return new HttpSuccess(dataEvaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
} }
} }

View file

@ -51,6 +51,7 @@ export const AppDataSource = new DataSource({
password: process.env.DB_PASSWORD, password: process.env.DB_PASSWORD,
connectorPackage: "mysql2", connectorPackage: "mysql2",
synchronize: false, synchronize: false,
// timezone: "Z", // "Z" = UTC
logging: ["query", "error"], logging: ["query", "error"],
entities: entities:
process.env.NODE_ENV !== "production" process.env.NODE_ENV !== "production"

View file

@ -184,12 +184,34 @@ class CheckAuth {
}); });
} }
public async checkOrg(token: any, keycloakId: string) { public async checkOrg(token: any, keycloakId: string) {
const redisClient = await this.redis.createClient({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
});
const getAsync = promisify(redisClient.get).bind(redisClient);
try { try {
// Validate required environment variables
const REDIS_HOST = process.env.REDIS_HOST;
const REDIS_PORT = process.env.REDIS_PORT ? Number(process.env.REDIS_PORT) : 6379;
if (!REDIS_HOST) {
throw new Error("REDIS_HOST is not set in environment variables");
}
console.log(`[REDIS] Connecting to Redis at ${REDIS_HOST}:${REDIS_PORT}`);
// Create Redis client
const redisClient = this.redis.createClient({
socket: {
host: REDIS_HOST,
port: REDIS_PORT,
},
});
redisClient.on("error", (err: any) => {
console.error("[REDIS] Connection error:", err.message);
});
await redisClient.connect();
console.log("[REDIS] Connected successfully!");
const getAsync = promisify(redisClient.get).bind(redisClient);
let reply = await getAsync("org_" + keycloakId); let reply = await getAsync("org_" + keycloakId);
if (reply != null) { if (reply != null) {
reply = JSON.parse(reply); reply = JSON.parse(reply);