คำนวนเลขบัตรประชาชน (ยังไม่ได้ validate)

This commit is contained in:
AdisakKanthawilang 2024-05-15 11:45:06 +07:00
parent 40205a3a97
commit 56960aeb47
2 changed files with 54 additions and 0 deletions

View file

@ -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;