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; +} diff --git a/src/migration/1718176873613-update_table_role_add_sys1.ts b/src/migration/1718176873613-update_table_role_add_sys1.ts new file mode 100644 index 00000000..bb163097 --- /dev/null +++ b/src/migration/1718176873613-update_table_role_add_sys1.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableRoleAddSys11718176873613 implements MigrationInterface { + name = 'UpdateTableRoleAddSys11718176873613' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileChangePosition\` ADD \`status\` text NULL COMMENT 'สถานะ'`); + await queryRunner.query(`ALTER TABLE \`profileChangePosition\` CHANGE \`organizationPositionOld\` \`organizationPositionOld\` varchar(255) NULL COMMENT 'สังกัดเดิม ตำแหน่ง'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileChangePosition\` CHANGE \`organizationPositionOld\` \`organizationPositionOld\` varchar(255) NULL COMMENT 'สังกัดเดิม'`); + await queryRunner.query(`ALTER TABLE \`profileChangePosition\` DROP COLUMN \`status\``); + } + +}