command add position

This commit is contained in:
kittapath 2025-01-24 17:52:24 +07:00
parent 388d6488f8
commit a462f2bddd
3 changed files with 83 additions and 23 deletions

View file

@ -53,7 +53,15 @@ import { PosMasterAct } from "../entities/PosMasterAct";
import { sendToQueue } from "../services/rabbitmq"; import { sendToQueue } from "../services/rabbitmq";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType"; 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 { ProfileEducation, CreateProfileEducation } from "../entities/ProfileEducation";
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory"; import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { CreateProfileCertificate, ProfileCertificate } from "../entities/ProfileCertificate"; import { CreateProfileCertificate, ProfileCertificate } from "../entities/ProfileCertificate";
@ -452,6 +460,9 @@ export class CommandController extends Controller {
amountSpecial: x.amountSpecial, amountSpecial: x.amountSpecial,
positionSalaryAmount: x.positionSalaryAmount, positionSalaryAmount: x.positionSalaryAmount,
mouthSalaryAmount: x.mouthSalaryAmount, mouthSalaryAmount: x.mouthSalaryAmount,
position: x.position,
posType: x.posType,
posLevel: x.posLevel,
})), })),
}; };
return new HttpSuccess(_command); return new HttpSuccess(_command);
@ -1819,6 +1830,9 @@ export class CommandController extends Controller {
amountSpecial?: Double | null; amountSpecial?: Double | null;
positionSalaryAmount?: Double | null; positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null;
position?: string | null;
posType?: string | null;
posLevel?: string | null;
}[]; }[];
}, },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
@ -2564,7 +2578,7 @@ export class CommandController extends Controller {
//คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user //คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user
if (returnWork && item.isGovernment) { if (returnWork && item.isGovernment) {
let userKeycloakId; let userKeycloakId;
const checkUser = await getUserByUsername(profile.citizenId) const checkUser = await getUserByUsername(profile.citizenId);
//ถ้ายังไม่มี user keycloak ให้สร้างใหม่ //ถ้ายังไม่มี user keycloak ให้สร้างใหม่
if (checkUser.length == 0) { if (checkUser.length == 0) {
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
@ -2585,16 +2599,18 @@ export class CommandController extends Controller {
); );
} }
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : []; profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
profile.keycloak = userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";; profile.keycloak =
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
} }
//ถ้ามีอยู่แล้วให้ใช้อันเดิม //ถ้ามีอยู่แล้วให้ใช้อันเดิม
else { else {
const rolesData = await getRoleMappings(checkUser[0].id); const rolesData = await getRoleMappings(checkUser[0].id);
if(rolesData) { if (rolesData) {
const _roleKeycloak = await this.roleKeycloakRepo.find({ 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; profile.keycloak = checkUser[0].id;
} }
@ -3925,9 +3941,9 @@ export class CommandController extends Controller {
item.bodyProfile.birthDate == null item.bodyProfile.birthDate == null
? _null ? _null
: calculateRetireLaw(item.bodyProfile.birthDate); : calculateRetireLaw(item.bodyProfile.birthDate);
const checkUser = await getUserByUsername(profile.citizenId) const checkUser = await getUserByUsername(profile.citizenId);
if(checkUser.length == 0) { if (checkUser.length == 0) {
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName, firstName: profile.firstName,
lastName: profile.lastName, lastName: profile.lastName,
@ -3945,15 +3961,16 @@ export class CommandController extends Controller {
})), })),
); );
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : []; profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
profile.keycloak = userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : ""; profile.keycloak =
} userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
else { } else {
const rolesData = await getRoleMappings(checkUser[0].id); const rolesData = await getRoleMappings(checkUser[0].id);
if(rolesData) { if (rolesData) {
const _roleKeycloak = await this.roleKeycloakRepo.find({ 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; profile.keycloak = checkUser[0].id;
} }
@ -4325,8 +4342,8 @@ export class CommandController extends Controller {
if (positionNew != null) { if (positionNew != null) {
// Create Keycloak // Create Keycloak
const checkUser = await getUserByUsername(profile.citizenId) const checkUser = await getUserByUsername(profile.citizenId);
if(checkUser.length == 0) { if (checkUser.length == 0) {
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName, firstName: profile.firstName,
lastName: profile.lastName, lastName: profile.lastName,
@ -4348,17 +4365,18 @@ export class CommandController extends Controller {
})), })),
); );
// if (!result) throw new Error("Failed. Cannot set user's role."); // 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] : []; profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
// End Create Keycloak // End Create Keycloak
} } else {
else {
const rolesData = await getRoleMappings(checkUser[0].id); const rolesData = await getRoleMappings(checkUser[0].id);
if(rolesData) { if (rolesData) {
const _roleKeycloak = await this.roleKeycloakRepo.find({ 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; profile.keycloak = checkUser[0].id;
} }

View file

@ -36,6 +36,30 @@ export class CommandRecive extends EntityBase {
}) })
lastName: string; 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({ @Column({
nullable: true, nullable: true,
comment: "ลำดับแสดงผล", comment: "ลำดับแสดงผล",

View file

@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateCommandAddPosition1737715789621 implements MigrationInterface {
name = 'UpdateCommandAddPosition1737715789621'
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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\``);
}
}