From 0ab26752b6db00da4ba64dd802084e0e485c241f Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Fri, 31 May 2024 10:47:52 +0700 Subject: [PATCH 1/6] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=A7=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=E0=B9=83=E0=B8=99=20profile=20training=20/education?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 10 ++++------ src/controllers/ProfileEmployeeController.ts | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) 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..55638bf1 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}` : "", From ecaab4fc5c2e82e8cc1ddea987d74a21b47435ed Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 31 May 2024 11:53:26 +0700 Subject: [PATCH 2/6] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20role=3D>=20description?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/keycloak/index.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/keycloak/index.ts b/src/keycloak/index.ts index 7047d295..07a531cc 100644 --- a/src/keycloak/index.ts +++ b/src/keycloak/index.ts @@ -151,21 +151,18 @@ export async function getUserList(first = "", max = "", search = "") { } export async function getUserCount() { - const res = await fetch( - `${KC_URL}/admin/realms/${KC_REALM}/users/count`, - { - headers: { - "authorization": `Bearer ${await getToken()}`, + const res = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/users/count`, { + headers: { + authorization: `Bearer ${await getToken()}`, "content-type": `application/json`, }, - }, - ).catch((e) => console.log("Keycloak Error: ", e)); - + }).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 +280,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, + // }; } /** From 43a1dfe8d2a47555e36315f898bbf333b153f993 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 31 May 2024 13:53:08 +0700 Subject: [PATCH 3/6] fix bug getListUser --- src/controllers/UserController.ts | 2 +- src/keycloak/index.ts | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) 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/keycloak/index.ts b/src/keycloak/index.ts index 07a531cc..b32eaf6e 100644 --- a/src/keycloak/index.ts +++ b/src/keycloak/index.ts @@ -150,13 +150,16 @@ export async function getUserList(first = "", max = "", search = "") { })); } -export async function getUserCount() { - const res = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/users/count`, { - headers: { - authorization: `Bearer ${await getToken()}`, - "content-type": `application/json`, +export async function getUserCount(first = "", max = "", search = "") { + const res = await fetch( + `${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`, + }, }, - }).catch((e) => console.log("Keycloak Error: ", e)); + ).catch((e) => console.log("Keycloak Error: ", e)); if (!res) return false; if (!res.ok) { From 9d205caa1f86f5c487dd67a04b8abb3e9395f2e3 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 4 Jun 2024 16:49:52 +0700 Subject: [PATCH 4/6] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1/=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= =?UTF-8?q?=20=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B9=83=E0=B8=AB?= =?UTF-8?q?=E0=B9=89=E0=B8=AA=E0=B9=88=E0=B8=87=20null=20=E0=B8=9A?= =?UTF-8?q?=E0=B8=B2=E0=B8=87=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94=E0=B9=8C?= =?UTF-8?q?=E0=B9=84=E0=B8=94=E0=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 18 +++++++++++++----- src/entities/PosDict.ts | 12 ++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) 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/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; From e4c08a5dc58deb51852f318aef05e915150d2f98 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 5 Jun 2024 13:49:58 +0700 Subject: [PATCH 5/6] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1/=E0=B9=81?= =?UTF-8?q?=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=E0=B8=A5=E0=B8=B9=E0=B8=81?= =?UTF-8?q?=E0=B8=88=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 = { From fb4732a724ca397141067a9dfeb2b1d45101bb33 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 5 Jun 2024 16:27:26 +0700 Subject: [PATCH 6/6] no message --- src/controllers/ProfileEmployeeController.ts | 11 +++++++++++ src/entities/ProfileEmployee.ts | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 626078fc..b13debe4 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -494,6 +494,9 @@ export class ProfileEmployeeController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } + 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, "ประเภทลูกจ้างไม่ถูกต้อง"); } @@ -556,6 +559,9 @@ 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, "ประเภทลูกจ้างไม่ถูกต้อง"); } @@ -779,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/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index b1ad91ca..24e557aa 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -488,7 +488,8 @@ export class CreateProfileEmployee { religion?: string | null; bloodGroup?: string | null; phone?: string | null; - employeeClass: string; + salaryLevel?: number | null; + employeeClass?: string | null; } export type UpdateProfileEmployee = { @@ -508,7 +509,8 @@ export type UpdateProfileEmployee = { religion?: string | null; bloodGroup?: string | null; phone?: string | null; - employeeClass: string; + salaryLevel?: number | null; + employeeClass?: string | null; }; export type UpdateProfileAddressEmployee = {