From 586331e87048f690668c8542cf29fc780ce5733c Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 17 Dec 2025 12:37:05 +0700 Subject: [PATCH 1/2] =?UTF-8?q?API=20=E0=B8=95=E0=B8=A3=E0=B8=A7=E0=B8=88?= =?UTF-8?q?=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B9=80=E0=B8=8A=E0=B9=87=E0=B8=84?= =?UTF-8?q?=E0=B9=80=E0=B8=A5=E0=B8=82=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=A3?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3=E0=B8=95=E0=B8=B1?= =?UTF-8?q?=E0=B8=A7=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=8A=E0=B8=B2=E0=B8=8A?= =?UTF-8?q?=E0=B8=99=20=20=E0=B8=97=E0=B8=B3=E0=B9=84=E0=B8=A7=E0=B9=89?= =?UTF-8?q?=E0=B9=83=E0=B8=AB=E0=B9=89=20service=20=E0=B8=AD=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=99=E0=B9=86=20=E0=B8=A0=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B9=83=E0=B8=99=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A=20call?= =?UTF-8?q?=20=E0=B8=A1=E0=B8=B2=E0=B8=95=E0=B8=A3=E0=B8=A7=E0=B8=88?= =?UTF-8?q?=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B9=80=E0=B8=A5=E0=B8=82=E0=B8=9A?= =?UTF-8?q?=E0=B8=B1=E0=B8=95=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88?= =?UTF-8?q?=E0=B8=B3=E0=B8=95=E0=B8=B1=E0=B8=A7=E0=B8=9B=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=8A=E0=B8=B2=E0=B8=8A=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationDotnetController.ts | 17 +++++++++++++++++ src/interfaces/extension.ts | 16 +++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 00eb9b5a..ddac1c70 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -57,6 +57,23 @@ export class OrganizationDotnetController extends Controller { private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict); + /** + * ทำไว้ให้ service อื่นๆ ภายในระบบ call มาตรวจสอบเลขบัตรประจำตัวประชาชน + * + * @summary API ตรวจสอบเช็คเลขบัตรประจำตัวประชาชน + * + */ + @Post("check-citizen") + public async CheckCitizen( + @Body() + body: { + citizenId: string; + }, + ) { + let citizen = Extension.CheckCitizen(body.citizenId) + return new HttpSuccess(citizen); + } + /** * 1. API Search Profile * diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index 4a5dc5a3..24da5b93 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -251,8 +251,11 @@ class Extension { public static CheckCitizen(value: string) { let citizen = value; - if (citizen == null || citizen == "") { - return citizen; + if (citizen == null || citizen == "" || citizen == undefined) { + throw new HttpError( + HttpStatus.NOT_FOUND, + "กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชน", + ); } if (citizen.length !== 13) { throw new HttpError( @@ -277,9 +280,12 @@ class Extension { const calStp2 = cal % 11; const chkDigit = (11 - calStp2) % 10; - // if (citizenIdDigits[12] !== chkDigit) { - // throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); - // } + if (citizenIdDigits[12] !== chkDigit) { + throw new HttpError( + HttpStatus.NOT_FOUND, + "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง" + ); + } return citizen; } From fd22fcf990d6e0e8309a9a4a39303e7f7ac67029 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 18 Dec 2025 17:29:18 +0700 Subject: [PATCH 2/2] log user --- src/middlewares/logs.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index ce4802d2..70020810 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -76,6 +76,8 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { if (req.url.startsWith("/api/v1/org/apiKey/")) system = "admin"; if (req.url.startsWith("/api/v1/org/api-manage/")) system = "admin"; + if (req.url.startsWith("/api/v1/org/keycloak/")) system = "registry"; + const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4; const profileByKeycloak = await repoProfile.findOne({ where: { keycloak: req.app.locals.logData.userId },