From a462f2bdddf8200f24361e731da173f8bf0afa04 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 24 Jan 2025 17:52:24 +0700 Subject: [PATCH] command add position --- src/controllers/CommandController.ts | 64 ++++++++++++------- src/entities/CommandRecive.ts | 24 +++++++ .../1737715789621-UpdateCommandAddPosition.ts | 18 ++++++ 3 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 src/migration/1737715789621-UpdateCommandAddPosition.ts diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 561c79a9..1a562906 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -53,7 +53,15 @@ import { PosMasterAct } from "../entities/PosMasterAct"; import { sendToQueue } from "../services/rabbitmq"; import { PosLevel } from "../entities/PosLevel"; import { PosType } from "../entities/PosType"; -import { addUserRoles, createUser, getRoles, deleteUser, enableStatus, getUserByUsername, getRoleMappings } from "../keycloak"; +import { + addUserRoles, + createUser, + getRoles, + deleteUser, + enableStatus, + getUserByUsername, + getRoleMappings, +} from "../keycloak"; import { ProfileEducation, CreateProfileEducation } from "../entities/ProfileEducation"; import { ProfileEducationHistory } from "../entities/ProfileEducationHistory"; import { CreateProfileCertificate, ProfileCertificate } from "../entities/ProfileCertificate"; @@ -452,6 +460,9 @@ export class CommandController extends Controller { amountSpecial: x.amountSpecial, positionSalaryAmount: x.positionSalaryAmount, mouthSalaryAmount: x.mouthSalaryAmount, + position: x.position, + posType: x.posType, + posLevel: x.posLevel, })), }; return new HttpSuccess(_command); @@ -1819,6 +1830,9 @@ export class CommandController extends Controller { amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; + position?: string | null; + posType?: string | null; + posLevel?: string | null; }[]; }, @Request() request: RequestWithUser, @@ -2564,7 +2578,7 @@ export class CommandController extends Controller { //คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user if (returnWork && item.isGovernment) { let userKeycloakId; - const checkUser = await getUserByUsername(profile.citizenId) + const checkUser = await getUserByUsername(profile.citizenId); //ถ้ายังไม่มี user keycloak ให้สร้างใหม่ if (checkUser.length == 0) { userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { @@ -2585,16 +2599,18 @@ export class CommandController extends Controller { ); } profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : []; - profile.keycloak = userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";; + profile.keycloak = + userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : ""; } //ถ้ามีอยู่แล้วให้ใช้อันเดิม else { const rolesData = await getRoleMappings(checkUser[0].id); - if(rolesData) { + if (rolesData) { const _roleKeycloak = await this.roleKeycloakRepo.find({ - where: { name: In(rolesData.map((x:any) => x.name)) } + where: { name: In(rolesData.map((x: any) => x.name)) }, }); - profile.roleKeycloaks = _roleKeycloak && _roleKeycloak.length > 0 ? _roleKeycloak : []; + profile.roleKeycloaks = + _roleKeycloak && _roleKeycloak.length > 0 ? _roleKeycloak : []; } profile.keycloak = checkUser[0].id; } @@ -3925,9 +3941,9 @@ export class CommandController extends Controller { item.bodyProfile.birthDate == null ? _null : calculateRetireLaw(item.bodyProfile.birthDate); - - const checkUser = await getUserByUsername(profile.citizenId) - if(checkUser.length == 0) { + + const checkUser = await getUserByUsername(profile.citizenId); + if (checkUser.length == 0) { const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { firstName: profile.firstName, lastName: profile.lastName, @@ -3945,15 +3961,16 @@ export class CommandController extends Controller { })), ); profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : []; - profile.keycloak = userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : ""; - } - else { + profile.keycloak = + userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : ""; + } else { const rolesData = await getRoleMappings(checkUser[0].id); - if(rolesData) { + if (rolesData) { const _roleKeycloak = await this.roleKeycloakRepo.find({ - where: { name: In(rolesData.map((x:any) => x.name)) } + where: { name: In(rolesData.map((x: any) => x.name)) }, }); - profile.roleKeycloaks = _roleKeycloak && _roleKeycloak.length > 0 ? _roleKeycloak : []; + profile.roleKeycloaks = + _roleKeycloak && _roleKeycloak.length > 0 ? _roleKeycloak : []; } profile.keycloak = checkUser[0].id; } @@ -4325,8 +4342,8 @@ export class CommandController extends Controller { if (positionNew != null) { // Create Keycloak - const checkUser = await getUserByUsername(profile.citizenId) - if(checkUser.length == 0) { + const checkUser = await getUserByUsername(profile.citizenId); + if (checkUser.length == 0) { const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { firstName: profile.firstName, lastName: profile.lastName, @@ -4348,17 +4365,18 @@ export class CommandController extends Controller { })), ); // if (!result) throw new Error("Failed. Cannot set user's role."); - profile.keycloak = userKeycloakId && typeof userKeycloakId == "string" ? userKeycloakId : ""; + profile.keycloak = + userKeycloakId && typeof userKeycloakId == "string" ? userKeycloakId : ""; profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : []; // End Create Keycloak - } - else { + } else { const rolesData = await getRoleMappings(checkUser[0].id); - if(rolesData) { + if (rolesData) { const _roleKeycloak = await this.roleKeycloakRepo.find({ - where: { name: In(rolesData.map((x:any) => x.name)) } + where: { name: In(rolesData.map((x: any) => x.name)) }, }); - profile.roleKeycloaks = _roleKeycloak && _roleKeycloak.length > 0 ? _roleKeycloak : []; + profile.roleKeycloaks = + _roleKeycloak && _roleKeycloak.length > 0 ? _roleKeycloak : []; } profile.keycloak = checkUser[0].id; } diff --git a/src/entities/CommandRecive.ts b/src/entities/CommandRecive.ts index 2ed7d823..ef638fe5 100644 --- a/src/entities/CommandRecive.ts +++ b/src/entities/CommandRecive.ts @@ -36,6 +36,30 @@ export class CommandRecive extends EntityBase { }) lastName: string; + @Column({ + nullable: true, + comment: "ตำแหน่ง", + length: 255, + default: null, + }) + position: string; + + @Column({ + nullable: true, + comment: "ประเภท", + length: 255, + default: null, + }) + posType: string; + + @Column({ + nullable: true, + comment: "ระดับ", + length: 255, + default: null, + }) + posLevel: string; + @Column({ nullable: true, comment: "ลำดับแสดงผล", diff --git a/src/migration/1737715789621-UpdateCommandAddPosition.ts b/src/migration/1737715789621-UpdateCommandAddPosition.ts new file mode 100644 index 00000000..fa39b2ad --- /dev/null +++ b/src/migration/1737715789621-UpdateCommandAddPosition.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateCommandAddPosition1737715789621 implements MigrationInterface { + name = 'UpdateCommandAddPosition1737715789621' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`posType\` varchar(255) NULL COMMENT 'ประเภท'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`posLevel\` varchar(255) NULL COMMENT 'ระดับ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`posLevel\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`posType\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`position\``); + } + +}