diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 830f6299..7ccf2203 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -167,12 +167,9 @@ export class CommandController extends Controller { new Brackets((qb) => { qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, - }).orWhere( - keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", - { - keyword: `%${keyword}%`, - }, - ); + }).orWhere(keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }); }), ) .orderBy("command.createdAt", "DESC") @@ -292,7 +289,7 @@ export class CommandController extends Controller { detailFooter: string | null; commandAffectDate: Date | null; commandExcecuteDate: Date | null; - isBangkok: boolean | null; + isBangkok: string | null; isAttachment: boolean | null; }, @Request() request: RequestWithUser, @@ -942,12 +939,12 @@ export class CommandController extends Controller { .filter((x) => x.profileId != null) .map(async (x) => x.profileId); - await new CallAPI() + await new CallAPI() .PostData(request, "/placement/noti/profiles", { subject: `${command.issue}`, body: `${command.issue}`, receiverUserId: profiles, - payload: "",//แนบไฟล์ + payload: "", //แนบไฟล์ isSendMail: true, isSendInbox: true, receiveDate: command.commandExcecuteDate, @@ -1109,7 +1106,7 @@ export class CommandController extends Controller { commandExcecuteDate?: Date | null; persons: { refId: string; - profileId?: string|null; + profileId?: string | null; citizenId: string; prefix: string; firstName: string; @@ -2038,20 +2035,22 @@ export class CommandController extends Controller { @Body() body: { data: { - bodyProfile: CreateProfileAllFields - bodyEducations: CreateProfileEducation[] - bodyCertificates: CreateProfileCertificate[] - bodySalarys: CreateProfileSalary + bodyProfile: CreateProfileAllFields; + bodyEducations: CreateProfileEducation[]; + bodyCertificates: CreateProfileCertificate[]; + bodySalarys: CreateProfileSalary; bodyPosition: { posmasterId: string; positionId: string; - } + }; }[]; }, ) { await Promise.all( body.data.map(async (item) => { - const profile = await this.profileRepository.findOneBy({ citizenId: item.bodyProfile.citizenId }); + const profile = await this.profileRepository.findOneBy({ + citizenId: item.bodyProfile.citizenId, + }); if (profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "พบ profile ซ้ำ"); } @@ -2067,22 +2066,35 @@ export class CommandController extends Controller { if (item.bodyProfile.posLevelId === "") item.bodyProfile.posLevelId = null; if (item.bodyProfile.posTypeId === "") item.bodyProfile.posTypeId = null; - if (item.bodyProfile.posLevelId && !(await this.posLevelRepo.findOneBy({ id: item.bodyProfile.posLevelId }))) { + if ( + item.bodyProfile.posLevelId && + !(await this.posLevelRepo.findOneBy({ id: item.bodyProfile.posLevelId })) + ) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้"); } - if (item.bodyProfile.posTypeId && !(await this.posTypeRepo.findOneBy({ id: item.bodyProfile.posTypeId }))) { + if ( + item.bodyProfile.posTypeId && + !(await this.posTypeRepo.findOneBy({ id: item.bodyProfile.posTypeId })) + ) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } const profile_: Profile = Object.assign({ ...item.bodyProfile, ...meta }); const _null: any = null; - profile_.dateRetire = item.bodyProfile.birthDate == null ? _null : calculateRetireDate(item.bodyProfile.birthDate); - profile_.dateRetireLaw = item.bodyProfile.birthDate == null ? _null : calculateRetireLaw(item.bodyProfile.birthDate); + profile_.dateRetire = + item.bodyProfile.birthDate == null + ? _null + : calculateRetireDate(item.bodyProfile.birthDate); + profile_.dateRetireLaw = + item.bodyProfile.birthDate == null + ? _null + : calculateRetireLaw(item.bodyProfile.birthDate); await this.profileRepository.save(profile_); // setLogDataDiff(req, { before, after: profile_ }); - if(profile_ && profile_.id) { - const userKeycloakId = await createUser(profile_.citizenId, profile_.citizenId, { //User, Password + if (profile_ && profile_.id) { + const userKeycloakId = await createUser(profile_.citizenId, profile_.citizenId, { + //User, Password firstName: profile_.firstName, lastName: profile_.lastName, email: profile_.email, @@ -2092,7 +2104,8 @@ export class CommandController extends Controller { throw new Error(userKeycloakId.errorMessage); } const list = await getRoles(); - if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server."); + if (!Array.isArray(list)) + throw new Error("Failed. Cannot get role(s) data from the server."); const result = await addUserRoles( userKeycloakId, list @@ -2100,10 +2113,10 @@ export class CommandController extends Controller { .map((x) => ({ id: x.id, name: x.name, - })) + })), ); if (!result) throw new Error("Failed. Cannot set user's role."); - + //Educations await Promise.all( item.bodyEducations.map(async (education) => { @@ -2116,7 +2129,7 @@ export class CommandController extends Controller { setLogDataDiff(req, { before, after: profileEdu }); eduHistory.profileEducationId = profileEdu.id; await this.profileEducationHistoryRepo.save(eduHistory, { data: req }); - }) + }), ); //Certificates @@ -2126,36 +2139,37 @@ export class CommandController extends Controller { Object.assign(profileCer, { ...cer, ...meta }); const cerHistory = new ProfileCertificateHistory(); Object.assign(cerHistory, { ...profileCer, id: undefined }); - profileCer.profileId = profile_.id + profileCer.profileId = profile_.id; await this.certificateRepo.save(profileCer, { data: req }); setLogDataDiff(req, { before, after: profileCer }); cerHistory.profileCertificateId = profileCer.id; await this.certificateHistoryRepo.save(cerHistory, { data: req }); - }) + }), ); //Salary - const dest_item = await this.salaryRepo.findOne({ - where: { profileId: profile_.id }, - order: { order: "DESC" }, - }); - const profileSal = new ProfileSalary(); - Object.assign(profileSal, { ...item.bodySalarys, ...meta }); - const salaryHistory = new ProfileSalaryHistory(); - Object.assign(history, { ...profileSal, id: undefined }); - profileSal.order = dest_item == null ? 1 : dest_item.order + 1, - profileSal.profileId = profile_.id - await this.salaryRepo.save(profileSal, { data: req }); - setLogDataDiff(req, { before, after: profileSal }); - salaryHistory.profileSalaryId = profileSal.id; - await this.salaryHistoryRepo.save(salaryHistory, { data: req }); + const dest_item = await this.salaryRepo.findOne({ + where: { profileId: profile_.id }, + order: { order: "DESC" }, + }); + const profileSal = new ProfileSalary(); + Object.assign(profileSal, { ...item.bodySalarys, ...meta }); + const salaryHistory = new ProfileSalaryHistory(); + Object.assign(history, { ...profileSal, id: undefined }); + (profileSal.order = dest_item == null ? 1 : dest_item.order + 1), + (profileSal.profileId = profile_.id); + await this.salaryRepo.save(profileSal, { data: req }); + setLogDataDiff(req, { before, after: profileSal }); + salaryHistory.profileSalaryId = profileSal.id; + await this.salaryHistoryRepo.save(salaryHistory, { data: req }); //Position const posMaster = await this.posMasterRepository.findOne({ where: { id: item.bodyPosition.posmasterId }, }); - if (posMaster == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); - + if (posMaster == null) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); + const posMasterOld = await this.posMasterRepository.findOne({ where: { current_holderId: profile_.id, @@ -2163,7 +2177,7 @@ export class CommandController extends Controller { }, }); if (posMasterOld != null) posMasterOld.current_holderId = null; - + const positionOld = await this.positionRepository.findOne({ where: { posMasterId: posMasterOld?.id, @@ -2174,7 +2188,7 @@ export class CommandController extends Controller { positionOld.positionIsSelected = false; await this.positionRepository.save(positionOld); } - + const checkPosition = await this.positionRepository.find({ where: { posMasterId: item.bodyPosition.posmasterId, @@ -2188,11 +2202,11 @@ export class CommandController extends Controller { })); await this.positionRepository.save(clearPosition); } - + posMaster.current_holderId = profile_.id; if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld); await this.posMasterRepository.save(posMaster); - + const positionNew = await this.positionRepository.findOne({ where: { id: item.bodyPosition.positionId, @@ -2204,13 +2218,13 @@ export class CommandController extends Controller { profile_.posLevelId = positionNew.posLevelId; profile_.posTypeId = positionNew.posTypeId; profile_.position = positionNew.positionName; - profile_.keycloak = userKeycloakId; // Update KeyCloak - await this.profileRepository.save(profile_, { data: req }); + profile_.keycloak = userKeycloakId; // Update KeyCloak + await this.profileRepository.save(profile_, { data: req }); setLogDataDiff(req, { before, after: profile_ }); await this.positionRepository.save(positionNew, { data: req }); } } - }) + }), ); return new HttpSuccess(); } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e24a7cad..100f375a 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -63,6 +63,7 @@ import { updateName } from "../keycloak"; import permission from "../interfaces/permission"; import { PosMasterAct } from "../entities/PosMasterAct"; import axios from "axios"; +import { OrgChild1 } from "../entities/OrgChild1"; @Route("api/v1/org/profile") @Tags("Profile") @Security("bearerAuth") @@ -101,6 +102,7 @@ export class ProfileController extends Controller { private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory); private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave); private posMasterActRepository = AppDataSource.getRepository(PosMasterAct); + private orgChild1Repository = AppDataSource.getRepository(OrgChild1); /** * report ประวัติแบบย่อ ข้าราชการ @@ -3407,6 +3409,32 @@ export class ProfileController extends Controller { return new HttpSuccess(_profile); } + /** + * API เช็ค สกจ + * + * @summary เช็ค สกจ + * + */ + @Get("keycloak/idofficer") + async getIsOfficerByKeycloak(@Request() request: RequestWithUser) { + const posMasters = await this.posMasterRepo.findOne({ + where: { + current_holder: { + keycloak: request.user.sub, + }, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + }, + relations: ["orgChild1"], + }); + if (!posMasters) { + return new HttpSuccess(false); + } + return new HttpSuccess(posMasters.orgChild1.isOfficer); + } + /** * API ข้อมูลทะเบียนประวัติตาม keycloakid * diff --git a/src/entities/Command.ts b/src/entities/Command.ts index 2819176d..3254aac7 100644 --- a/src/entities/Command.ts +++ b/src/entities/Command.ts @@ -94,11 +94,11 @@ export class Command extends EntityBase { @Column({ nullable: true, - default: null, - type: "boolean", comment: "คำสั่งกรุงเทพมหานคร", + length: 20, + default: null, }) - isBangkok: boolean; + isBangkok: string; @Column({ comment: "สถานะบัญชีแนบท้าย", diff --git a/src/entities/State.ts b/src/entities/State.ts index 3bef1d7c..949f0167 100644 --- a/src/entities/State.ts +++ b/src/entities/State.ts @@ -24,10 +24,9 @@ export class State extends EntityBase { @Column({ nullable: true, comment: "ลำดับ", - length: 255, default: null, }) - order: string; + order: number; @Column({ nullable: true, diff --git a/src/entities/Workflow.ts b/src/entities/Workflow.ts index 8b81b00d..4b1ffa1b 100644 --- a/src/entities/Workflow.ts +++ b/src/entities/Workflow.ts @@ -1,9 +1,6 @@ -import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm"; +import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { State } from "./State"; -import { CommandSys } from "./CommandSys"; -import { PosLevel } from "./PosLevel"; -import { PosType } from "./PosType"; @Entity("workflow") export class Workflow extends EntityBase { @@ -17,7 +14,7 @@ export class Workflow extends EntityBase { @Column({ nullable: true, - comment: "ระบบ", + comment: "ระบบ", //PLACEMENT length: 255, default: null, }) @@ -26,49 +23,13 @@ export class Workflow extends EntityBase { @OneToMany(() => State, (state) => state.workflow) states: State[]; - // @Column({ - // nullable: true, - // length: 40, - // comment: "คีย์นอก(FK)ของตาราง commandSys", - // default: null, - // }) - // commandSysId: string; - - // @ManyToOne(() => CommandSys, (commandSys) => commandSys.workflows) - // @JoinColumn({ name: "commandSysId" }) - // commandSys: CommandSys; - - // @Column({ - // nullable: true, - // length: 40, - // comment: "คีย์นอก(FK)ของตาราง posLevel", - // default: null, - // }) - // posLevelId: string; - - // @ManyToOne(() => PosLevel, (posLevel) => posLevel.workflows) - // @JoinColumn({ name: "posLevelId" }) - // posLevel: PosLevel; - - // @Column({ - // nullable: true, - // length: 40, - // comment: "คีย์นอก(FK)ของตาราง posType", - // default: null, - // }) - // posTypeId: string; - - // @ManyToOne(() => PosType, (posType) => posType.workflows) - // @JoinColumn({ name: "posTypeId" }) - // posType: PosType; - @Column({ nullable: true, - comment: "ชื่อระบบ", + comment: "ชื่อระบบ", //สอบคัดเลือก length: 100, default: null, }) - commandSysName: string; + sysName: string; @Column({ nullable: true,