diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 92943776..434e7b77 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -93,6 +93,7 @@ import { CreatePosMasterHistoryOfficer, getTopDegrees, getPosMasterPositions } f import { ProfileLeaveService } from "../services/ProfileLeaveService"; // import { PostRetireToExprofile } from "./ExRetirementController"; import { getPosNumCodeSit } from "../services/CommandService"; +import { updateHolderProfileHistory } from "../services/PositionService"; @Route("api/v1/org/profile") @Tags("Profile") @Security("bearerAuth") @@ -5774,26 +5775,7 @@ export class ProfileController extends Controller { } 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; - const chkDigit = (11 - calStp2) % 10; - - if (citizenIdDigits[12] !== chkDigit) { - throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); - } + Extension.CheckCitizen(body.citizenId); } const record = await this.profileRepo.findOneBy({ id }); const before = structuredClone(record); @@ -5833,6 +5815,9 @@ export class ProfileController extends Controller { } } + // บันทึกประวัติคนครองตำแหน่ง (ถ้า profile นี้ครองตำแหน่งอยู่) + await updateHolderProfileHistory(record.id, request); + return new HttpSuccess(); } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index f79e27cd..cdf1a4e4 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -84,6 +84,7 @@ import { ProfileDuty } from "../entities/ProfileDuty"; import { CreatePosMasterHistoryEmployee, getTopDegrees } from "../services/PositionService"; import { ProfileLeaveService } from "../services/ProfileLeaveService"; import { CommandCode } from "../entities/CommandCode"; +import { updateHolderProfileHistory } from "../services/PositionService"; @Route("api/v1/org/profile-employee") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -2381,26 +2382,7 @@ export class ProfileEmployeeController extends Controller { } 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; - const chkDigit = (11 - calStp2) % 10; - - if (citizenIdDigits[12] !== chkDigit) { - throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); - } + Extension.CheckCitizen(body.citizenId); } const record = await this.profileRepo.findOneBy({ id }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); @@ -2434,6 +2416,8 @@ export class ProfileEmployeeController extends Controller { }), ); await this.profileRepo.save(record); + // บันทึกประวัติคนครองตำแหน่ง (ถ้า profile นี้ครองตำแหน่งอยู่) + await updateHolderProfileHistory(record.id, request, "EMPLOYEE"); return new HttpSuccess(); }