เช็ค สกจ

This commit is contained in:
kittapath 2024-10-09 12:53:13 +07:00
parent 87b6fdf0d2
commit 5440bce257
5 changed files with 101 additions and 99 deletions

View file

@ -167,12 +167,9 @@ export class CommandController extends Controller {
new Brackets((qb) => { new Brackets((qb) => {
qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", { qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", {
keyword: `%${keyword}%`, keyword: `%${keyword}%`,
}).orWhere( }).orWhere(keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", {
keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", keyword: `%${keyword}%`,
{ });
keyword: `%${keyword}%`,
},
);
}), }),
) )
.orderBy("command.createdAt", "DESC") .orderBy("command.createdAt", "DESC")
@ -292,7 +289,7 @@ export class CommandController extends Controller {
detailFooter: string | null; detailFooter: string | null;
commandAffectDate: Date | null; commandAffectDate: Date | null;
commandExcecuteDate: Date | null; commandExcecuteDate: Date | null;
isBangkok: boolean | null; isBangkok: string | null;
isAttachment: boolean | null; isAttachment: boolean | null;
}, },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
@ -942,12 +939,12 @@ export class CommandController extends Controller {
.filter((x) => x.profileId != null) .filter((x) => x.profileId != null)
.map(async (x) => x.profileId); .map(async (x) => x.profileId);
await new CallAPI() await new CallAPI()
.PostData(request, "/placement/noti/profiles", { .PostData(request, "/placement/noti/profiles", {
subject: `${command.issue}`, subject: `${command.issue}`,
body: `${command.issue}`, body: `${command.issue}`,
receiverUserId: profiles, receiverUserId: profiles,
payload: "",//แนบไฟล์ payload: "", //แนบไฟล์
isSendMail: true, isSendMail: true,
isSendInbox: true, isSendInbox: true,
receiveDate: command.commandExcecuteDate, receiveDate: command.commandExcecuteDate,
@ -1109,7 +1106,7 @@ export class CommandController extends Controller {
commandExcecuteDate?: Date | null; commandExcecuteDate?: Date | null;
persons: { persons: {
refId: string; refId: string;
profileId?: string|null; profileId?: string | null;
citizenId: string; citizenId: string;
prefix: string; prefix: string;
firstName: string; firstName: string;
@ -2038,20 +2035,22 @@ export class CommandController extends Controller {
@Body() @Body()
body: { body: {
data: { data: {
bodyProfile: CreateProfileAllFields bodyProfile: CreateProfileAllFields;
bodyEducations: CreateProfileEducation[] bodyEducations: CreateProfileEducation[];
bodyCertificates: CreateProfileCertificate[] bodyCertificates: CreateProfileCertificate[];
bodySalarys: CreateProfileSalary bodySalarys: CreateProfileSalary;
bodyPosition: { bodyPosition: {
posmasterId: string; posmasterId: string;
positionId: string; positionId: string;
} };
}[]; }[];
}, },
) { ) {
await Promise.all( await Promise.all(
body.data.map(async (item) => { 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) { if (profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "พบ 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.posLevelId === "") item.bodyProfile.posLevelId = null;
if (item.bodyProfile.posTypeId === "") item.bodyProfile.posTypeId = 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, "ไม่พบข้อมูลระดับตำแหน่งนี้"); 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, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
} }
const profile_: Profile = Object.assign({ ...item.bodyProfile, ...meta }); const profile_: Profile = Object.assign({ ...item.bodyProfile, ...meta });
const _null: any = null; const _null: any = null;
profile_.dateRetire = item.bodyProfile.birthDate == null ? _null : calculateRetireDate(item.bodyProfile.birthDate); profile_.dateRetire =
profile_.dateRetireLaw = item.bodyProfile.birthDate == null ? _null : calculateRetireLaw(item.bodyProfile.birthDate); 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_); await this.profileRepository.save(profile_);
// setLogDataDiff(req, { before, after: profile_ }); // setLogDataDiff(req, { before, after: profile_ });
if(profile_ && profile_.id) { if (profile_ && profile_.id) {
const userKeycloakId = await createUser(profile_.citizenId, profile_.citizenId, { //User, Password const userKeycloakId = await createUser(profile_.citizenId, profile_.citizenId, {
//User, Password
firstName: profile_.firstName, firstName: profile_.firstName,
lastName: profile_.lastName, lastName: profile_.lastName,
email: profile_.email, email: profile_.email,
@ -2092,7 +2104,8 @@ export class CommandController extends Controller {
throw new Error(userKeycloakId.errorMessage); throw new Error(userKeycloakId.errorMessage);
} }
const list = await getRoles(); 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( const result = await addUserRoles(
userKeycloakId, userKeycloakId,
list list
@ -2100,10 +2113,10 @@ export class CommandController extends Controller {
.map((x) => ({ .map((x) => ({
id: x.id, id: x.id,
name: x.name, name: x.name,
})) })),
); );
if (!result) throw new Error("Failed. Cannot set user's role."); if (!result) throw new Error("Failed. Cannot set user's role.");
//Educations //Educations
await Promise.all( await Promise.all(
item.bodyEducations.map(async (education) => { item.bodyEducations.map(async (education) => {
@ -2116,7 +2129,7 @@ export class CommandController extends Controller {
setLogDataDiff(req, { before, after: profileEdu }); setLogDataDiff(req, { before, after: profileEdu });
eduHistory.profileEducationId = profileEdu.id; eduHistory.profileEducationId = profileEdu.id;
await this.profileEducationHistoryRepo.save(eduHistory, { data: req }); await this.profileEducationHistoryRepo.save(eduHistory, { data: req });
}) }),
); );
//Certificates //Certificates
@ -2126,36 +2139,37 @@ export class CommandController extends Controller {
Object.assign(profileCer, { ...cer, ...meta }); Object.assign(profileCer, { ...cer, ...meta });
const cerHistory = new ProfileCertificateHistory(); const cerHistory = new ProfileCertificateHistory();
Object.assign(cerHistory, { ...profileCer, id: undefined }); Object.assign(cerHistory, { ...profileCer, id: undefined });
profileCer.profileId = profile_.id profileCer.profileId = profile_.id;
await this.certificateRepo.save(profileCer, { data: req }); await this.certificateRepo.save(profileCer, { data: req });
setLogDataDiff(req, { before, after: profileCer }); setLogDataDiff(req, { before, after: profileCer });
cerHistory.profileCertificateId = profileCer.id; cerHistory.profileCertificateId = profileCer.id;
await this.certificateHistoryRepo.save(cerHistory, { data: req }); await this.certificateHistoryRepo.save(cerHistory, { data: req });
}) }),
); );
//Salary //Salary
const dest_item = await this.salaryRepo.findOne({ const dest_item = await this.salaryRepo.findOne({
where: { profileId: profile_.id }, where: { profileId: profile_.id },
order: { order: "DESC" }, order: { order: "DESC" },
}); });
const profileSal = new ProfileSalary(); const profileSal = new ProfileSalary();
Object.assign(profileSal, { ...item.bodySalarys, ...meta }); Object.assign(profileSal, { ...item.bodySalarys, ...meta });
const salaryHistory = new ProfileSalaryHistory(); const salaryHistory = new ProfileSalaryHistory();
Object.assign(history, { ...profileSal, id: undefined }); Object.assign(history, { ...profileSal, id: undefined });
profileSal.order = dest_item == null ? 1 : dest_item.order + 1, (profileSal.order = dest_item == null ? 1 : dest_item.order + 1),
profileSal.profileId = profile_.id (profileSal.profileId = profile_.id);
await this.salaryRepo.save(profileSal, { data: req }); await this.salaryRepo.save(profileSal, { data: req });
setLogDataDiff(req, { before, after: profileSal }); setLogDataDiff(req, { before, after: profileSal });
salaryHistory.profileSalaryId = profileSal.id; salaryHistory.profileSalaryId = profileSal.id;
await this.salaryHistoryRepo.save(salaryHistory, { data: req }); await this.salaryHistoryRepo.save(salaryHistory, { data: req });
//Position //Position
const posMaster = await this.posMasterRepository.findOne({ const posMaster = await this.posMasterRepository.findOne({
where: { id: item.bodyPosition.posmasterId }, 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({ const posMasterOld = await this.posMasterRepository.findOne({
where: { where: {
current_holderId: profile_.id, current_holderId: profile_.id,
@ -2163,7 +2177,7 @@ export class CommandController extends Controller {
}, },
}); });
if (posMasterOld != null) posMasterOld.current_holderId = null; if (posMasterOld != null) posMasterOld.current_holderId = null;
const positionOld = await this.positionRepository.findOne({ const positionOld = await this.positionRepository.findOne({
where: { where: {
posMasterId: posMasterOld?.id, posMasterId: posMasterOld?.id,
@ -2174,7 +2188,7 @@ export class CommandController extends Controller {
positionOld.positionIsSelected = false; positionOld.positionIsSelected = false;
await this.positionRepository.save(positionOld); await this.positionRepository.save(positionOld);
} }
const checkPosition = await this.positionRepository.find({ const checkPosition = await this.positionRepository.find({
where: { where: {
posMasterId: item.bodyPosition.posmasterId, posMasterId: item.bodyPosition.posmasterId,
@ -2188,11 +2202,11 @@ export class CommandController extends Controller {
})); }));
await this.positionRepository.save(clearPosition); await this.positionRepository.save(clearPosition);
} }
posMaster.current_holderId = profile_.id; posMaster.current_holderId = profile_.id;
if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld); if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld);
await this.posMasterRepository.save(posMaster); await this.posMasterRepository.save(posMaster);
const positionNew = await this.positionRepository.findOne({ const positionNew = await this.positionRepository.findOne({
where: { where: {
id: item.bodyPosition.positionId, id: item.bodyPosition.positionId,
@ -2204,13 +2218,13 @@ export class CommandController extends Controller {
profile_.posLevelId = positionNew.posLevelId; profile_.posLevelId = positionNew.posLevelId;
profile_.posTypeId = positionNew.posTypeId; profile_.posTypeId = positionNew.posTypeId;
profile_.position = positionNew.positionName; profile_.position = positionNew.positionName;
profile_.keycloak = userKeycloakId; // Update KeyCloak profile_.keycloak = userKeycloakId; // Update KeyCloak
await this.profileRepository.save(profile_, { data: req }); await this.profileRepository.save(profile_, { data: req });
setLogDataDiff(req, { before, after: profile_ }); setLogDataDiff(req, { before, after: profile_ });
await this.positionRepository.save(positionNew, { data: req }); await this.positionRepository.save(positionNew, { data: req });
} }
} }
}) }),
); );
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -63,6 +63,7 @@ import { updateName } from "../keycloak";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { PosMasterAct } from "../entities/PosMasterAct"; import { PosMasterAct } from "../entities/PosMasterAct";
import axios from "axios"; import axios from "axios";
import { OrgChild1 } from "../entities/OrgChild1";
@Route("api/v1/org/profile") @Route("api/v1/org/profile")
@Tags("Profile") @Tags("Profile")
@Security("bearerAuth") @Security("bearerAuth")
@ -101,6 +102,7 @@ export class ProfileController extends Controller {
private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory); private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory);
private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave); private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave);
private posMasterActRepository = AppDataSource.getRepository(PosMasterAct); private posMasterActRepository = AppDataSource.getRepository(PosMasterAct);
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
/** /**
* report * report
@ -3407,6 +3409,32 @@ export class ProfileController extends Controller {
return new HttpSuccess(_profile); 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 * API keycloakid
* *

View file

@ -94,11 +94,11 @@ export class Command extends EntityBase {
@Column({ @Column({
nullable: true, nullable: true,
default: null,
type: "boolean",
comment: "คำสั่งกรุงเทพมหานคร", comment: "คำสั่งกรุงเทพมหานคร",
length: 20,
default: null,
}) })
isBangkok: boolean; isBangkok: string;
@Column({ @Column({
comment: "สถานะบัญชีแนบท้าย", comment: "สถานะบัญชีแนบท้าย",

View file

@ -24,10 +24,9 @@ export class State extends EntityBase {
@Column({ @Column({
nullable: true, nullable: true,
comment: "ลำดับ", comment: "ลำดับ",
length: 255,
default: null, default: null,
}) })
order: string; order: number;
@Column({ @Column({
nullable: true, nullable: true,

View file

@ -1,9 +1,6 @@
import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm"; import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { State } from "./State"; import { State } from "./State";
import { CommandSys } from "./CommandSys";
import { PosLevel } from "./PosLevel";
import { PosType } from "./PosType";
@Entity("workflow") @Entity("workflow")
export class Workflow extends EntityBase { export class Workflow extends EntityBase {
@ -17,7 +14,7 @@ export class Workflow extends EntityBase {
@Column({ @Column({
nullable: true, nullable: true,
comment: "ระบบ", comment: "ระบบ", //PLACEMENT
length: 255, length: 255,
default: null, default: null,
}) })
@ -26,49 +23,13 @@ export class Workflow extends EntityBase {
@OneToMany(() => State, (state) => state.workflow) @OneToMany(() => State, (state) => state.workflow)
states: State[]; 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({ @Column({
nullable: true, nullable: true,
comment: "ชื่อระบบ", comment: "ชื่อระบบ", //สอบคัดเลือก
length: 100, length: 100,
default: null, default: null,
}) })
commandSysName: string; sysName: string;
@Column({ @Column({
nullable: true, nullable: true,