From f1cdec9076649e7632dbf39cc2bacf194c81cd01 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 12 Jun 2024 12:52:12 +0700 Subject: [PATCH 1/9] =?UTF-8?q?=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=A5=E0=B8=B9?= =?UTF-8?q?=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B8=8A=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=A7=E0=B8=84=E0=B8=A3=E0=B8=B2=E0=B8=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileEmployeeController.ts | 74 +++++++++++++------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 075251b9..ba6c374e 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -18,7 +18,7 @@ import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; -import { Brackets, IsNull, Like, Not } from "typeorm"; +import { Brackets, In, IsNull, Like, Not } from "typeorm"; import { OrgRevision } from "../entities/OrgRevision"; import { calculateRetireDate, calculateRetireLaw } from "../interfaces/utils"; import { EmployeePosMaster } from "../entities/EmployeePosMaster"; @@ -557,10 +557,10 @@ export class ProfileEmployeeController extends Controller { const exists = !!body.citizenId && (await this.profileRepo.findOne({ - where: { - id: Not(id), - citizenId: body.citizenId, - employeeClass: String(body.employeeClass) + where: { + id: Not(id), + citizenId: body.citizenId, + employeeClass: String(body.employeeClass), }, })); @@ -690,12 +690,12 @@ export class ProfileEmployeeController extends Controller { : _data.current_holders[0].orgRoot != null ? `${_data.current_holders[0].orgRoot.orgRootShortName}${_data.current_holders[0].posMasterNo}` : null; - const dateEmployment = + const dateEmployment = _data.profileEmployeeEmployment.length == 0 ? null : _data.profileEmployeeEmployment.reduce((latest, current) => { - return (latest.date > current.date) ? latest : current; - }).date; + return latest.date > current.date ? latest : current; + }).date; return { id: _data.id, prefix: _data.prefix, @@ -933,12 +933,12 @@ export class ProfileEmployeeController extends Controller { : _data.current_holders[0].orgRoot != null ? `${_data.current_holders[0].orgRoot.orgRootShortName}${_data.current_holders[0].posMasterNo}` : null; - const dateEmployment = + const dateEmployment = _data.profileEmployeeEmployment.length == 0 ? null : _data.profileEmployeeEmployment.reduce((latest, current) => { - return (latest.date > current.date) ? latest : current; - }).date; + return latest.date > current.date ? latest : current; + }).date; return { id: _data.id, prefix: _data.prefix, @@ -2569,33 +2569,33 @@ export class ProfileEmployeeController extends Controller { /** * API ข้อมูลลูกจ้างชั่วคราว * - * @summary ข้อมูลลูกจ้างชั่วคราว (ADMIN) + * @summary ข้อมูลลูกจ้างชั่วคราว (ADMIN) * * @param {string} profileEmployeeId profileEmployeeId ทะเบียนประวัติลูกจ้างชั่วคราว */ @Get("information/{profileEmployeeId}") async getInformationById(@Path() profileEmployeeId: string) { const profileInformation = await this.profileRepo.findOne({ - where: { id: profileEmployeeId } + where: { id: profileEmployeeId }, }); if (!profileInformation) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const mapData = { - id: profileInformation.id, - positionEmployeeGroupId: profileInformation.positionEmployeeGroupId, - positionEmployeeLineId: profileInformation.positionEmployeeLineId, - positionEmployeePositionId: profileInformation.positionEmployeePositionId, - employeeOc: profileInformation.employeeOc, - employeeTypeIndividual: profileInformation.employeeTypeIndividual, - employeeWage: profileInformation.employeeWage, - employeeMoneyIncrease: profileInformation.employeeMoneyIncrease, - employeeMoneyAllowance: profileInformation.employeeMoneyAllowance, - employeeMoneyEmployee: profileInformation.employeeMoneyEmployee, - employeeMoneyEmployer: profileInformation.employeeMoneyEmployer, + id: profileInformation.id, + positionEmployeeGroupId: profileInformation.positionEmployeeGroupId, + positionEmployeeLineId: profileInformation.positionEmployeeLineId, + positionEmployeePositionId: profileInformation.positionEmployeePositionId, + employeeOc: profileInformation.employeeOc, + employeeTypeIndividual: profileInformation.employeeTypeIndividual, + employeeWage: profileInformation.employeeWage, + employeeMoneyIncrease: profileInformation.employeeMoneyIncrease, + employeeMoneyAllowance: profileInformation.employeeMoneyAllowance, + employeeMoneyEmployee: profileInformation.employeeMoneyEmployee, + employeeMoneyEmployer: profileInformation.employeeMoneyEmployer, }; return new HttpSuccess(mapData); } - + /** * API ประวัติการแก้ไขข้อมูลลูกจ้างชั่วคราว * @@ -2781,4 +2781,28 @@ export class ProfileEmployeeController extends Controller { return new HttpSuccess(); } + + /** + * API ออกคำสั่งลูกจ้าง + * + * @summary ORG_038 - ออกคำสั่งลูกจ้าง (ADMIN) # + * + */ + @Post("report") + async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) { + const profiles = await this.profileRepo.find({ where: { id: In(requestBody.id) } }); + + const _profiles = await Promise.all( + profiles.map(async (item: any) => { + return { + ...item, + statusTemp: "REPORT", + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + }; + }), + ); + await this.profileRepo.save(_profiles); + return new HttpSuccess(); + } } From 2f525bae9516544373de70283833d6f727125f5f Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 12 Jun 2024 13:21:15 +0700 Subject: [PATCH 2/9] add auth sync by menu --- src/controllers/AuthSysController.ts | 20 +++++++++---- src/entities/AuthSys.ts | 43 ++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/controllers/AuthSysController.ts b/src/controllers/AuthSysController.ts index 756bd368..c76868b2 100644 --- a/src/controllers/AuthSysController.ts +++ b/src/controllers/AuthSysController.ts @@ -27,11 +27,21 @@ export class AuthSysController extends Controller { @Get("list") public async listAuthSys() { - const getList = await this.authSysRepo.find(); - // if (!getList || getList.length === 0) { - // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - // } - return new HttpSuccess(getList); + const getList = await this.authSysRepo.find({ + select: ["id", "parentId", "sysName", "sysDescription", "order"], + }); + + const lists = getList + .filter((x) => x.parentId == null) + .map((item) => { + return { + ...item, + children: getList.filter((x) => x.parentId == item.id).sort((a, b) => a.order - b.order), + }; + }) + .sort((a, b) => a.order - b.order); + + return new HttpSuccess(lists); } @Get("{systemId}") diff --git a/src/entities/AuthSys.ts b/src/entities/AuthSys.ts index b331cba5..3626578f 100644 --- a/src/entities/AuthSys.ts +++ b/src/entities/AuthSys.ts @@ -1,12 +1,4 @@ -import { - Entity, - Column, - OneToMany, - CreateDateColumn, - UpdateDateColumn, - PrimaryColumn, -} from "typeorm"; -import { AuthRoleAttr } from "./AuthRoleAttr"; +import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryColumn } from "typeorm"; @Entity("authSys") export class AuthSys { @@ -16,6 +8,36 @@ export class AuthSys { }) id: string; + @Column({ + comment: "Id ของเมนูหลักถ้าเป็นเมนูหลักจะเป็นค่า null", + nullable: true, + default: null, + length: 255, + }) + parentId!: string; + + @Column({ + comment: "ชื่อ icon", + nullable: true, + default: null, + length: 100, + }) + icon!: string; + + @Column({ + comment: "path url ของระบบ", + nullable: true, + default: null, + length: 255, + }) + path!: string; + + @Column({ + comment: "ลำดับการแสดงผล", + default: 0, + }) + order: number; + @CreateDateColumn({ comment: "สร้างข้อมูลเมื่อ" }) createdAt!: Date; @@ -66,6 +88,9 @@ export class CreateAuthSys { @PrimaryColumn() id: string; + @Column() + parentId: string; + @Column() sysName: string; From 624b1a062734cc2085e1ffdc4e0b59ef94c2ed89 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 12 Jun 2024 13:23:02 +0700 Subject: [PATCH 3/9] updated throw --- src/controllers/AuthSysController.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/AuthSysController.ts b/src/controllers/AuthSysController.ts index 756bd368..f8c58159 100644 --- a/src/controllers/AuthSysController.ts +++ b/src/controllers/AuthSysController.ts @@ -28,9 +28,9 @@ export class AuthSysController extends Controller { @Get("list") public async listAuthSys() { const getList = await this.authSysRepo.find(); - // if (!getList || getList.length === 0) { - // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - // } + if (!getList || getList.length === 0) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } return new HttpSuccess(getList); } From 7a4b25079fa84e2dff84eed0fb8e2e1a6909229d Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 12 Jun 2024 13:27:48 +0700 Subject: [PATCH 4/9] migrate --- ...1718173589821-update_table_role_add_sys.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/migration/1718173589821-update_table_role_add_sys.ts diff --git a/src/migration/1718173589821-update_table_role_add_sys.ts b/src/migration/1718173589821-update_table_role_add_sys.ts new file mode 100644 index 00000000..06306bc3 --- /dev/null +++ b/src/migration/1718173589821-update_table_role_add_sys.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableRoleAddSys1718173589821 implements MigrationInterface { + name = 'UpdateTableRoleAddSys1718173589821' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX \`FK_b5b59c60792d518f4f025379dba\` ON \`authRoleAttr\``); + await queryRunner.query(`ALTER TABLE \`authSys\` ADD \`parentId\` varchar(255) NULL COMMENT 'Id ของเมนูหลักถ้าเป็นเมนูหลักจะเป็นค่า null'`); + await queryRunner.query(`ALTER TABLE \`authSys\` ADD \`icon\` varchar(100) NULL COMMENT 'ชื่อ icon'`); + await queryRunner.query(`ALTER TABLE \`authSys\` ADD \`path\` varchar(255) NULL COMMENT 'path url ของระบบ'`); + await queryRunner.query(`ALTER TABLE \`authSys\` ADD \`order\` int NOT NULL COMMENT 'ลำดับการแสดงผล' DEFAULT '0'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`authSys\` DROP COLUMN \`order\``); + await queryRunner.query(`ALTER TABLE \`authSys\` DROP COLUMN \`path\``); + await queryRunner.query(`ALTER TABLE \`authSys\` DROP COLUMN \`icon\``); + await queryRunner.query(`ALTER TABLE \`authSys\` DROP COLUMN \`parentId\``); + await queryRunner.query(`CREATE INDEX \`FK_b5b59c60792d518f4f025379dba\` ON \`authRoleAttr\` (\`authSysId\`)`); + } + +} From c95b0565623ef498507619b6bc579856901caf7c Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 12 Jun 2024 14:17:55 +0700 Subject: [PATCH 5/9] add field --- src/controllers/ChangePositionController.ts | 43 +++++++++++++++++-- src/controllers/ProfileController.ts | 1 + src/entities/ProfileChangePosition.ts | 47 ++++++++++++++++++++- 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/src/controllers/ChangePositionController.ts b/src/controllers/ChangePositionController.ts index b9e0dbc4..273e336a 100644 --- a/src/controllers/ChangePositionController.ts +++ b/src/controllers/ChangePositionController.ts @@ -23,6 +23,7 @@ import HttpError from "../interfaces/http-error"; import { Equal, ILike, In, IsNull, Like, Not, Brackets, MoreThan } from "typeorm"; import { RequestWithUser } from "../middlewares/user"; import { ChangePosition, CreateChangePosition, UpdateChangePosition } from "../entities/ChangePosition"; +import { ProfileChangePosition, CreateProfileChangePosition } from "../entities/ProfileChangePosition"; @Route("api/v1/org/placement/change-position") @Tags("Placement") @@ -33,7 +34,8 @@ import { ChangePosition, CreateChangePosition, UpdateChangePosition } from "../e ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class ChangePositionController extends Controller { - private ChangePositionRepository = AppDataSource.getRepository(ChangePosition); + private ChangePositionRepository = AppDataSource.getRepository(ChangePosition); + private ProfileChangePositionRepository = AppDataSource.getRepository(ProfileChangePosition); /** * API เพิ่มรอบย้ายสับเปลี่ยนตำแหน่ง @@ -68,6 +70,41 @@ export class ChangePositionController extends Controller { return new HttpSuccess(); } + /** + * API เพิ่มเพิ่มรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง + * + * @summary เพิ่มเพิ่มรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง (ADMIN) + * + * @param {string} id Id รอบย้ายสับเปลี่ยนตำแหน่ง + */ + @Post("profile/{id}") + async CreateProfileChangePosition( + @Path() id: string, + @Body() body: CreateProfileChangePosition, + @Request() request: RequestWithUser, + ) { + const changePosition = await this.ChangePositionRepository.findOneBy({ id }); + if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); + + const profileChangePositions: ProfileChangePosition[] = []; + const profiles = new ProfileChangePosition(); + for (const data of body.profiles) { + Object.assign(profiles, data); + let positionOld = data.positionOld ? `${data.positionOld}` : ""; + let rootOld = data.rootOld ? data.positionOld ? `/${data.rootOld}` : `${data.rootOld}` : ""; + profiles.changePositionId = id; + profiles.organizationPositionOld = `${positionOld}${rootOld}`, + profiles.status = "WAITTING", + profiles.createdUserId = request.user.sub; + profiles.createdFullName = request.user.name; + profiles.lastUpdateUserId = request.user.sub; + profiles.lastUpdateFullName = request.user.name; + profileChangePositions.push(profiles); + } + await this.ProfileChangePositionRepository.save(profileChangePositions); + return new HttpSuccess(); + } + /** * API ลบรอบย้ายสับเปลี่ยนตำแหน่ง * @@ -107,7 +144,7 @@ export class ChangePositionController extends Controller { ) { const changePosition = await this.ChangePositionRepository.findOneBy({ id }); - if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); const checkDuplicate = await this.ChangePositionRepository.find({ where: { @@ -134,7 +171,7 @@ export class ChangePositionController extends Controller { * @summary API รายการรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN) * */ - @Get("") + @Get() async GetChangePositionLists() { const data = await this.ChangePositionRepository.find(); return new HttpSuccess(data); diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 72bcb67c..aa1f0d0a 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2097,6 +2097,7 @@ export class ProfileController extends Controller { child3ShortName: child3Holder?.orgChild3ShortName ?? null, child4: child4Holder?.orgChild4Name ?? null, child4Id: child4Holder?.id ?? null, + child4ShortName: child4Holder?.orgChild4ShortName ?? null, posMasterNo: posMasterNo ?? null, posTypeId: item.posTypeId, posTypeName: item.posType?.posTypeName, diff --git a/src/entities/ProfileChangePosition.ts b/src/entities/ProfileChangePosition.ts index 0baa3bf8..1ffac9e1 100644 --- a/src/entities/ProfileChangePosition.ts +++ b/src/entities/ProfileChangePosition.ts @@ -10,7 +10,7 @@ export class ProfileChangePosition extends EntityBase { @Column({ nullable: true, comment: "วุฒิ/สาขาเดิม", default: null }) educationOld: string; - @Column({ nullable: true, comment: "สังกัดเดิม", default: null }) + @Column({ nullable: true, comment: "สังกัดเดิม ตำแหน่ง", default: null }) organizationPositionOld: string; @Column({ nullable: true, comment: "สังกัดเดิม", default: null }) @@ -32,7 +32,6 @@ export class ProfileChangePosition extends EntityBase { amountOld: number; - @Column({ nullable: true, comment: "profile Id", default: null }) profileId: string; @@ -191,6 +190,9 @@ export class ProfileChangePosition extends EntityBase { @Column({ nullable: true, comment: "ชื่อระดับตำแหน่ง old", default: null }) posLevelNameOld: string; + @Column({ nullable: true, comment: "สถานะ", type: "text", default: null }) + status: string; + @Column({nullable: true, length: 40, comment: "คีย์นอก(FK)ของตาราง ChangePosition", default: null }) changePositionId: string; @@ -198,3 +200,44 @@ export class ProfileChangePosition extends EntityBase { @JoinColumn({ name: "changePositionId" }) profile: ChangePosition; } + +export class CreateProfileChangePosition { + changePositionId: string; + profiles: ProfileItem[] +} + +export class ProfileItem { + profileId: string; + prefix: string; + firstName: string; + lastName: string; + citizenId: string; + positionOld: string | null; + positionTypeOld: string | null; + positionLevelOld: string | null; + positionNumberOld: string | null; + organizationOld: string | null; + organizationPositionOld: string | null; + amountOld: number | null; + educationOld: string | null; + rootOld: string | null; + rootOldId: string | null; + rootShortNameOld: string | null; + child1Old: string | null; + child1OldId: string | null; + child1ShortNameOld: string | null; + child2Old: string | null; + child2OldId: string | null; + child2ShortNameOld: string | null; + child3Old: string | null; + child3OldId: string | null; + child3ShortNameOld: string | null; + child4Old: string | null; + child4OldId: string | null; + child4ShortNameOld: string | null; + posMasterNoOld: number | null; + posTypeOldId: string | null; + posTypeNameOld: string | null; + posLevelOldId: string | null; + posLevelNameOld: string | null; +} From 8665eb15437f0a4e25244399caff40d3f56b357a Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 12 Jun 2024 14:18:55 +0700 Subject: [PATCH 6/9] list employee temp report --- src/controllers/ProfileEmployeeController.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index ba6c374e..3cc72654 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2805,4 +2805,18 @@ export class ProfileEmployeeController extends Controller { await this.profileRepo.save(_profiles); return new HttpSuccess(); } + + /** + * API ออกคำสั่งลูกจ้าง + * + * @summary ORG_038 - ออกคำสั่งลูกจ้าง (ADMIN) # + * + */ + @Get("report") + async getReport(@Request() request: RequestWithUser) { + const profiles = await this.profileRepo.find({ + where: { statusTemp: "REPORT", employeeClass: "TEMP" }, + }); + return new HttpSuccess(profiles); + } } From bd9dee6da2eec8f6bf9cc947325d57d72f14ef38 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Wed, 12 Jun 2024 14:41:16 +0700 Subject: [PATCH 7/9] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A7=20isDirecter=20isOfficer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/EmployeePositionController.ts | 4 ++++ src/controllers/PositionController.ts | 6 ++++++ src/entities/EmployeePosMaster.ts | 6 ++++++ src/entities/PosMaster.ts | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 33ad2684..0bbbca38 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -255,6 +255,8 @@ export class EmployeePositionController extends Controller { ? null : `${position.posType.posTypeShortName} ${position.posLevel.posLevelName}`, positionIsSelected: position.positionIsSelected, + isOfficer: posMaster.isOfficer, + isDirecter: posMaster.isDirector, })), }; return new HttpSuccess(formattedData); @@ -611,6 +613,8 @@ export class EmployeePositionController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง"); } posMaster.posMasterNo = requestBody.posMasterNo; + posMaster.isDirector = requestBody.isDirector; + posMaster.isOfficer = requestBody.isOfficer; posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix; posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix; posMaster.reason = requestBody.reason == null ? "" : requestBody.reason; diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 0061aecb..bfca037b 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -797,6 +797,8 @@ export class PositionController extends Controller { if (!posMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง"); } + posMaster.isDirector = requestBody.isDirector; + posMaster.isOfficer = requestBody.isOfficer; posMaster.posMasterNo = requestBody.posMasterNo; posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix; posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix; @@ -949,6 +951,8 @@ export class PositionController extends Controller { position.positionExecutiveField = x.posDictExecutiveField; position.positionArea = x.posDictArea; position.isSpecial = x.isSpecial; + position.isOfficer = x.isOfficer; + position.isDirector = x.isDirector; position.positionIsSelected = x.positionIsSelected; position.posMasterId = posMaster.id; position.createdUserId = request.user.sub; @@ -1001,6 +1005,8 @@ export class PositionController extends Controller { positionArea: position.positionArea, positionIsSelected: position.positionIsSelected, isSpecial: position.isSpecial, + isOfficer: posMaster.isOfficer, + isDirecter: posMaster.isDirector, })), }; return new HttpSuccess(formattedData); diff --git a/src/entities/EmployeePosMaster.ts b/src/entities/EmployeePosMaster.ts index 22c21dac..6c47e067 100644 --- a/src/entities/EmployeePosMaster.ts +++ b/src/entities/EmployeePosMaster.ts @@ -237,6 +237,12 @@ export class CreateEmployeePosMaster { @Column() reason: string | null; + + @Column() + isDirector: boolean; + + @Column() + isOfficer: boolean; } export type UpdateEmployeePosMaster = Partial; diff --git a/src/entities/PosMaster.ts b/src/entities/PosMaster.ts index ca8da472..5fc8d032 100644 --- a/src/entities/PosMaster.ts +++ b/src/entities/PosMaster.ts @@ -236,6 +236,12 @@ export class CreatePosMaster { @Column() reason: string | null; + + @Column() + isDirector: boolean; + + @Column() + isOfficer: boolean; } export type UpdatePosMaster = Partial; From 140bb6dbbc2a9916a9ad780417fb145c7493331c Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Wed, 12 Jun 2024 14:44:18 +0700 Subject: [PATCH 8/9] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20Upload=20sql=20=E0=B8=82=E0=B8=AD=E0=B8=87=20posTyp?= =?UTF-8?q?e=20=E0=B9=80=E0=B9=80=E0=B8=A5=E0=B8=B0=20posLevel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ImportDataController.ts | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index fcebcf7b..f9230ec8 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -28,6 +28,8 @@ import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; import { ProfileFamilyMother } from "../entities/ProfileFamilyMother"; import { ProfileFamilyFather } from "../entities/ProfileFamilyFather"; import { ProfileEmployee } from "../entities/ProfileEmployee"; +import { PosLevel } from "../entities/PosLevel"; +import { PosType } from "../entities/PosType"; @Route("api/v1/org/upload") @Tags("UPLOAD") @@ -40,6 +42,8 @@ export class ImportDataController extends Controller { private salaryRepository = AppDataSource.getRepository(ProfileSalary); private profileRepo = AppDataSource.getRepository(Profile); private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); + private posLevelRepo = AppDataSource.getRepository(PosLevel); + private posTypeRepo = AppDataSource.getRepository(PosType); /** * API upload EDU * @@ -594,4 +598,58 @@ export class ImportDataController extends Controller { await this.salaryRepository.save(profiles); return new HttpSuccess(allData); } + + @Post("uploadposSQL") + @UseInterceptors(FileInterceptor("file")) + async UploadPOSFileSQL(@UploadedFile() file: Express.Multer.File) { + const workbook = xlsx.read(file.buffer, { type: "buffer" }); + const sheetName = workbook.SheetNames[0]; + const sheet = workbook.Sheets[sheetName]; + const getProFile = xlsx.utils.sheet_to_json(sheet); + let profiles: any = []; + await Promise.all( + getProFile.map(async (item: any) => { + // Find profile by ID + let profile = await this.profileRepo.findOne({ + where: { citizenId: item["ID"] }, + }); + if (!profile) { + return; // Skip processing this item + } + + if (item["MP_CEE_TYPE"] === "NULL") { + profile.posTypeId = null; + } else { + // Find posType by posTypeName + const posType = await this.posTypeRepo.findOne({ + where: { posTypeName: item["MP_CEE_TYPE"] }, + }); + if (!posType) { + return; // Skip processing this item + } + profile.posTypeId = posType.id; + } + // Check if posLevelName is "NULL" + if (item["MP_CEE_POSITION"] === "NULL") { + profile.posLevelId = null; + } else { + // Find posLevel by posLevelName + const posLevel = await this.posLevelRepo.findOne({ + where: { posLevelName: item["MP_CEE_POSITION"] }, + }); + if (!posLevel) { + console.error( + `posLevel with name ${item["MP_CEE_POSITION"]} not found for profile ID ${profile.id}`, + ); + return; // Skip processing this item + } + profile.posLevelId = posLevel.id; + } + + profiles.push(profile); + }), + ); + await this.profileRepo.save(profiles); + return new HttpSuccess(getProFile); + } } From e7dd0e64cb931151ed937eaf22f1551e31c0a140 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 12 Jun 2024 14:50:20 +0700 Subject: [PATCH 9/9] limit commander --- src/controllers/ProfileController.ts | 32 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index aa1f0d0a..f4e53083 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -563,17 +563,27 @@ export class ProfileController extends Controller { where: { keycloak: request.user.sub }, }); - if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - - const _caregiver = await this.profileRepo.find({ - relations: { posLevel: true, posType: true }, - }); - const _commander = await this.profileRepo.find({ - relations: { posLevel: true, posType: true }, - }); - const _chairman = await this.profileRepo.find({ - relations: { posLevel: true, posType: true }, - }); + const _caregiver = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.posType", "posType") + .skip((1 - 1) * 20) + .take(20) + .getMany(); + const _commander = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.posType", "posType") + .skip((1 - 1) * 20) + .take(20) + .getMany(); + const _chairman = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.posType", "posType") + .skip((1 - 1) * 20) + .take(20) + .getMany(); const caregiver = _caregiver.map((_data) => ({ id: _data.id,