diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 14f4692b..4579fb65 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -309,19 +309,27 @@ export class PositionController extends Controller { posDictField: requestBody.posDictField, posTypeId: requestBody.posTypeId, posLevelId: requestBody.posLevelId, - posExecutiveId: String(requestBody.posExecutiveId), - posDictExecutiveField: requestBody.posDictExecutiveField, - posDictArea: requestBody.posDictArea, + posExecutiveId: requestBody.posExecutiveId?requestBody.posExecutiveId:"", + posDictExecutiveField: requestBody.posDictExecutiveField?requestBody.posDictExecutiveField:"", + posDictArea: requestBody.posDictArea?requestBody.posDictArea:"", isSpecial: requestBody.isSpecial, }, }); if (rowRepeated) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว"); } - + Object.assign(posDict, requestBody); posDict.lastUpdateUserId = request.user.sub; posDict.lastUpdateFullName = request.user.name; - this.posDictRepository.merge(posDict, requestBody); + posDict.posDictName = requestBody.posDictName, + posDict.posDictField = requestBody.posDictField, + posDict.posTypeId = requestBody.posTypeId, + posDict.posLevelId = requestBody.posLevelId, + posDict.posExecutiveId = requestBody.posExecutiveId?requestBody.posExecutiveId:null, + posDict.posDictExecutiveField = requestBody.posDictExecutiveField?requestBody.posDictExecutiveField:"", + posDict.posDictArea = requestBody.posDictArea?requestBody.posDictArea:"", + posDict.isSpecial = requestBody.isSpecial, + // this.posDictRepository.merge(posDict, requestBody); await this.posDictRepository.save(posDict); return new HttpSuccess(); } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 88946386..99ac32e5 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -386,14 +386,12 @@ export class ProfileController extends Controller { Start: item.startDate == null ? "" - : Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()), + : Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate)), End: - item.endDate == null - ? "" - : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), + item.endDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate)), Date: item.startDate && item.endDate - ? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}` + ? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}` : "", Level: "", Degree: item.name, @@ -427,7 +425,7 @@ export class ProfileController extends Controller { : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), Date: item.startDate && item.endDate - ? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}` + ? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}` : "", Level: item.educationLevel ?? "", Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "", diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 855b8ba5..b13debe4 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -406,7 +406,7 @@ export class ProfileEmployeeController extends Controller { : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), Date: item.startDate && item.endDate - ? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}` + ? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}` : "", Level: "", Degree: item.name, @@ -433,7 +433,7 @@ export class ProfileEmployeeController extends Controller { End: new Date(item.endDate).getFullYear().toString() ?? null, Date: item.startDate && item.endDate - ? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}` + ? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}` : "", Level: item.educationLevel ?? null, Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "", @@ -494,42 +494,11 @@ 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.employeeClass == null || body.employeeClass == undefined || body.employeeClass == ""){ + body.employeeClass = "PERM"; } - - 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 +508,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 +547,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 +559,21 @@ export class ProfileEmployeeController extends Controller { }), ); + if(body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == ""){ + body.employeeClass = "PERM"; + } + 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(); } @@ -846,6 +785,11 @@ export class ProfileEmployeeController extends Controller { position: _data.position, posNo: shortName, employeeClass: _data.employeeClass == null ? null : _data.employeeClass, + dateAppoint: _data.dateAppoint, + dateStart: _data.dateStart, + createdAt: _data.createdAt, + dateRetireLaw: _data.dateRetireLaw, + draftOrgEmployeeStatus: null }; }), ); diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index b349e6b3..9e152c41 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -209,7 +209,7 @@ export class KeycloakController extends Controller { @Get("user") async getUserList(@Query() first = "", @Query() max = "", @Query() search = "") { - const total = await getUserCount(); + const total = await getUserCount(first, max, search); const result = await getUserList(first, max, search); if (Array.isArray(result)) { diff --git a/src/entities/PosDict.ts b/src/entities/PosDict.ts index 581c73c2..4035f95b 100644 --- a/src/entities/PosDict.ts +++ b/src/entities/PosDict.ts @@ -40,7 +40,7 @@ export class PosDict extends EntityBase { comment: "ตำแหน่งทางการบริหาร", default: null, }) - posExecutiveId: string; + posExecutiveId?: string|null; @Column({ nullable: true, @@ -94,10 +94,10 @@ export class CreatePosDict { posExecutiveId?: string | null; @Column() - posDictExecutiveField: string | null; + posDictExecutiveField?: string | null; @Column() - posDictArea: string | null; + posDictArea?: string | null; @Column() isSpecial: boolean; @@ -146,13 +146,13 @@ export class UpdatePosDict { posLevelId: string; @Column() - posExecutiveId?: string | undefined; + posExecutiveId?: string | null; @Column() - posDictExecutiveField: string; + posDictExecutiveField?: string | null; @Column() - posDictArea: string; + posDictArea?: string | null; @Column() isSpecial: boolean; diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 930e7c8a..24e557aa 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -472,51 +472,45 @@ 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; + salaryLevel?: number | null; + employeeClass?: string | null; } 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; + salaryLevel?: number | null; + employeeClass?: string | null; }; export type UpdateProfileAddressEmployee = { diff --git a/src/keycloak/index.ts b/src/keycloak/index.ts index 7047d295..b32eaf6e 100644 --- a/src/keycloak/index.ts +++ b/src/keycloak/index.ts @@ -150,22 +150,22 @@ export async function getUserList(first = "", max = "", search = "") { })); } -export async function getUserCount() { +export async function getUserCount(first = "", max = "", search = "") { const res = await fetch( - `${KC_URL}/admin/realms/${KC_REALM}/users/count`, + `${KC_URL}/admin/realms/${KC_REALM}/users/count?first=${first || "0"}&max=${max || "-1"}${search ? `&search=${search}` : ""}`, { headers: { - "authorization": `Bearer ${await getToken()}`, - "content-type": `application/json`, - }, + authorization: `Bearer ${await getToken()}`, + "content-type": `application/json`, + }, }, ).catch((e) => console.log("Keycloak Error: ", e)); - + if (!res) return false; if (!res.ok) { return Boolean(console.error("Keycloak Error Response: ", await res.json())); } - + return await res.json(); } @@ -283,13 +283,17 @@ export async function getRoles(name?: string) { const data = (await res.json()) as any; if (Array.isArray(data)) { - return data.map((v: Record) => ({ id: v.id, name: v.name })); + return data.map((v: Record) => ({ + id: v.id, + name: v.name, + description: v.description, + })); } - return { - id: data.id, - name: data.name, - }; + // return { + // id: data.id, + // name: data.name, + // }; } /**