ปรับเพิ่ม/แก้ไขลูกจ้าง
This commit is contained in:
parent
9d205caa1f
commit
e4c08a5dc5
2 changed files with 33 additions and 108 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue