From e4c08a5dc58deb51852f318aef05e915150d2f98 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 5 Jun 2024 13:49:58 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B9=80?= =?UTF-8?q?=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1/=E0=B9=81=E0=B8=81?= =?UTF-8?q?=E0=B9=89=E0=B9=84=E0=B8=82=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileEmployeeController.ts | 87 +++----------------- src/entities/ProfileEmployee.ts | 54 ++++++------ 2 files changed, 33 insertions(+), 108 deletions(-) diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 55638bf1..626078fc 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -494,42 +494,8 @@ export class ProfileEmployeeController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } - if (body.citizenId.length !== 13) { - throw new HttpError( - HttpStatus.NOT_FOUND, - "กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก", - ); - } - - 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 = chkDigit % 10; - } - // else if(chkDigit === 11){ - // chkDigit = cal % 10; - // } - - if (citizenIdDigits[12] !== chkDigit) { - throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); - } + if (!["PERM", "TEMP"].includes(body.employeeClass.toLocaleUpperCase())) { + throw new HttpError(HttpStatus.NOT_FOUND, "ประเภทลูกจ้างไม่ถูกต้อง"); } const profile = Object.assign(new ProfileEmployee(), body); @@ -539,8 +505,9 @@ export class ProfileEmployeeController extends Controller { profile.lastUpdateFullName = request.user.name; profile.dateRetire = calculateRetireDate(profile.birthDate); profile.dateRetireLaw = calculateRetireLaw(profile.birthDate); + profile.citizenId = Extension.CheckCitizen(profile.citizenId); + profile.employeeClass = profile.employeeClass.toLocaleUpperCase() await this.profileRepo.save(profile); - return new HttpSuccess(); } @@ -577,46 +544,8 @@ export class ProfileEmployeeController extends Controller { if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } - if (body.citizenId && body.citizenId.length !== 13) { - throw new HttpError( - HttpStatus.NOT_FOUND, - "กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก", - ); - } - - 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 = chkDigit % 10; - } - // else if(chkDigit === 11){ - // chkDigit = cal % 10; - // } - - if (citizenIdDigits[12] !== chkDigit) { - throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); - } - } const record = await this.profileRepo.findOneBy({ id }); - if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); await this.profileHistoryRepo.save( @@ -627,14 +556,18 @@ export class ProfileEmployeeController extends Controller { }), ); + if (!["PERM", "TEMP"].includes(body.employeeClass.toLocaleUpperCase())) { + throw new HttpError(HttpStatus.NOT_FOUND, "ประเภทลูกจ้างไม่ถูกต้อง"); + } + Object.assign(record, body); record.lastUpdateUserId = request.user.sub; record.lastUpdateFullName = request.user.name; record.dateRetire = calculateRetireDate(record.birthDate); record.dateRetireLaw = calculateRetireLaw(record.birthDate); - + record.citizenId = Extension.CheckCitizen(record.citizenId); + record.employeeClass = record.employeeClass.toLocaleUpperCase(); await this.profileRepo.save(record); - return new HttpSuccess(); } diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 930e7c8a..b1ad91ca 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -472,51 +472,43 @@ export class ProfileEmployeeHistory extends ProfileEmployee { } export class CreateProfileEmployee { - rank: string; prefix: string; + rank?: string | null; firstName: string; lastName: string; - // position: string; - // isProbation: boolean | null; - // dateRetire: Date | null; - birthDate: Date | null; - salaryLevel: number | null; - // ethnicity: string | null; - // telephoneNumber: string | null; citizenId: string; - // religion: string | null; - posLevelId: string | null; - posTypeId: string | null; - // nationality: string | null; - // gender: string | null; - // relationship: string | null; - // bloodGroup: string | null; - // email: string | null; - // phone: string | null; + birthDate?: Date | null; + position?: string | null; + posLevelId?: string | null; + posTypeId?: string | null; + gender?: string | null; + relationship?: string | null; + nationality?: string | null; + ethnicity?: string | null; + religion?: string | null; + bloodGroup?: string | null; + phone?: string | null; + employeeClass: string; } export type UpdateProfileEmployee = { + prefix: string; rank?: string | null; - prefix?: string | null; - firstName?: string | null; - lastName?: string | null; - // position?: string | null; - // isProbation?: boolean | null; - // dateRetire?: Date | null; + firstName: string; + lastName: string; + citizenId: string; birthDate?: Date | null; - salaryLevel?: number | null; - ethnicity?: string | null; - telephoneNumber?: string | null; - citizenId?: string; - religion: string | null; + position?: string | null; posLevelId?: string | null; posTypeId?: string | null; - nationality?: string | null; gender?: string | null; relationship?: string | null; + nationality?: string | null; + ethnicity?: string | null; + religion?: string | null; bloodGroup?: string | null; - email: string | null; - phone: string | null; + phone?: string | null; + employeeClass: string; }; export type UpdateProfileAddressEmployee = {