From 56960aeb4796c810910ae1d27714372a4f8e3bad Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 15 May 2024 11:45:06 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=84=E0=B8=B3=E0=B8=99=E0=B8=A7=E0=B8=99?= =?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=8A=E0=B8=B2=E0=B8=8A=E0=B8=99?= =?UTF-8?q?=20(=E0=B8=A2=E0=B8=B1=E0=B8=87=E0=B9=84=E0=B8=A1=E0=B9=88?= =?UTF-8?q?=E0=B9=84=E0=B8=94=E0=B9=89=20validate)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 27 ++++++++++++++++++++ src/controllers/ProfileEmployeeController.ts | 27 ++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 154195ca..348182c3 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -195,6 +195,33 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } + if (body.citizenId) { + const citizenIdDigits = body.citizenId.toString().split("").map(Number); + const cal = + citizenIdDigits[0] * 13 + + citizenIdDigits[1] * 12 + + citizenIdDigits[2] * 11 + + citizenIdDigits[3] * 10 + + citizenIdDigits[4] * 9 + + citizenIdDigits[5] * 8 + + citizenIdDigits[6] * 7 + + citizenIdDigits[7] * 6 + + citizenIdDigits[8] * 5 + + citizenIdDigits[9] * 4 + + citizenIdDigits[10] * 3 + + citizenIdDigits[11] * 2; + const calStp2 = cal % 11; + let chkDigit = 11 - calStp2; + if(chkDigit === 10){ + chkDigit = 1; + }else if(chkDigit === 11){ + chkDigit = cal % 10; + } + // if(chkDigit && citizenIdDigits[12] !== chkDigit){ + // throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); + // } + } + if (body.citizenId && (await this.profileRepo.findOneBy({ citizenId: body.citizenId }))) { throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว"); } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index ec7dcb00..b3bcf409 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -73,6 +73,33 @@ export class ProfileEmployeeController extends Controller { if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } + + if (body.citizenId) { + const citizenIdDigits = body.citizenId.toString().split("").map(Number); + const cal = + citizenIdDigits[0] * 13 + + citizenIdDigits[1] * 12 + + citizenIdDigits[2] * 11 + + citizenIdDigits[3] * 10 + + citizenIdDigits[4] * 9 + + citizenIdDigits[5] * 8 + + citizenIdDigits[6] * 7 + + citizenIdDigits[7] * 6 + + citizenIdDigits[8] * 5 + + citizenIdDigits[9] * 4 + + citizenIdDigits[10] * 3 + + citizenIdDigits[11] * 2; + const calStp2 = cal % 11; + let chkDigit = 11 - calStp2; + if(chkDigit === 10){ + chkDigit = 1; + }else if(chkDigit === 11){ + chkDigit = cal % 10; + } + // if(chkDigit && citizenIdDigits[12] !== chkDigit){ + // throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); + // } + } const profile = Object.assign(new ProfileEmployee(), body); profile.createdUserId = request.user.sub;