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;