validate draft and publish

This commit is contained in:
AdisakKanthawilang 2025-08-21 18:25:24 +07:00
parent cc7c5c26ae
commit 6f57be2fe9
5 changed files with 80 additions and 63 deletions

View file

@ -125,19 +125,19 @@ export class OrganizationController extends Controller {
) { ) {
try { try {
// CheckQueueInProgress // CheckQueueInProgress
// const [isBusyDraft, isBusyPublish] = await Promise.all([ const [isBusyDraft, isBusyPublish] = await Promise.all([
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`), checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`), checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
// ]); ]);
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft); // console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish); // console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
// if (isBusyDraft || isBusyPublish) { if (isBusyDraft || isBusyPublish) {
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error") // console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
// throw new HttpError( throw new HttpError(
// HttpStatusCode.CONFLICT, HttpStatusCode.CONFLICT,
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน", "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
// ); );
// } }
//new main revision //new main revision
const before = null; const before = null;
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision; const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
@ -3209,19 +3209,19 @@ export class OrganizationController extends Controller {
try { try {
// CheckQueueInProgress // CheckQueueInProgress
// console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว"); // console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว");
// const [isBusyDraft, isBusyPublish] = await Promise.all([ const [isBusyDraft, isBusyPublish] = await Promise.all([
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`), checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`), checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
// ]); ]);
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft); // console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish); // console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
// if (isBusyDraft || isBusyPublish) { if (isBusyDraft || isBusyPublish) {
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error") // console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
// throw new HttpError( throw new HttpError(
// HttpStatusCode.CONFLICT, HttpStatusCode.CONFLICT,
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน", "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
// ); );
// } }
const today = new Date(); const today = new Date();
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day today.setHours(0, 0, 0, 0); // Set time to the beginning of the day

View file

@ -1391,32 +1391,32 @@ export class PositionController extends Controller {
posMaster.lastUpdatedAt = new Date(); posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster, { data: request }); await this.posMasterRepository.save(posMaster, { data: request });
setLogDataDiff(request, { before, after: posMaster }); setLogDataDiff(request, { before, after: posMaster });
await this.positionRepository.delete({ posMasterId: posMaster.id });
const result = await Promise.all(
requestBody.positions.map(async (x:any) => {
const match = posMaster.positions.find((p:any) => p.id == x.id);
if(match){
match.positionIsSelected = x.positionIsSelected??false;
return match
}else{
x.createdUserId = request.user.sub;
x.createdFullName = request.user.name;
x.lastUpdateUserId = request.user.sub;
x.lastUpdateFullName = request.user.name;
x.createdAt = new Date();
x.lastUpdatedAt = new Date();
return x
}
}),
);
await this.positionRepository.save(result, { data: request });
await Promise.all( await Promise.all(
requestBody.positions.map(async (x: any) => { posMaster.positions.map(async (x:any) => {
const position = Object.assign(new Position()); const match = requestBody.positions.find((p:any) => p.id == x.id);
position.positionName = x.posDictName; if(!match){
position.positionField = x.posDictField; //delete
position.posTypeId = x.posTypeId == "" ? null : x.posTypeId; await this.positionRepository.remove(x);
position.posLevelId = x.posLevelId == "" ? null : x.posLevelId; }
position.posExecutiveId = x.posExecutiveId == "" ? null : x.posExecutiveId;
position.positionExecutiveField = x.posDictExecutiveField;
position.positionArea = x.posDictArea;
position.isSpecial = x.isSpecial;
position.isOfficer = x.isOfficer;
position.isStaff = x.isStaff;
position.isDirector = x.isDirector;
position.positionSign = x.positionSign;
position.positionIsSelected = x.positionIsSelected;
position.posMasterId = posMaster.id;
position.createdUserId = request.user.sub;
position.createdFullName = request.user.name;
position.lastUpdateUserId = request.user.sub;
position.lastUpdateFullName = request.user.name;
position.createdAt = new Date();
position.lastUpdatedAt = new Date();
await this.positionRepository.save(position, { data: request });
}), }),
); );
return new HttpSuccess(posMaster.id); return new HttpSuccess(posMaster.id);

View file

@ -266,6 +266,9 @@ export class PosMaster extends EntityBase {
} }
export class CreatePosMaster { export class CreatePosMaster {
@Column()
id: string | null;
@Column() @Column()
posMasterNoPrefix: string | null; posMasterNoPrefix: string | null;

View file

@ -534,23 +534,23 @@ export function editLogSequence(req: RequestWithUser, index: number, data: LogSe
} }
export async function checkQueueInProgress(queueName: string) { export async function checkQueueInProgress(queueName: string) {
// const axios = require('axios'); const axios = require('axios');
// console.log("Checking queue in progress"); // console.log("Checking queue in progress");
// const res = await axios.get(`${process.env.RABBIT_API_URL}/api/queues/%2F/${queueName}`, { const res = await axios.get(`${process.env.RABBIT_API_URL}/api/queues/%2F/${queueName}`, {
// auth: { username: process.env.RABBIT_USER , password: process.env.RABBIT_PASS }, auth: { username: process.env.RABBIT_USER , password: process.env.RABBIT_PASS },
// }); });
// const q = res.data; const q = res.data;
// console.log(`Queue "${queueName}" has:`); // console.log(`Queue "${queueName}" has:`);
// console.log(` - ${q.messages_ready} messages ready`); // console.log(` - ${q.messages_ready} messages ready`);
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`); // console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
// if (q.messages_unacknowledged > 0) { if (q.messages_unacknowledged > 0) {
// return true; return true;
// } }
// return false; return false;
} }
export function chunkArray(array: any, size: number) { export function chunkArray(array: any, size: number) {

View file

@ -622,14 +622,28 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" || // requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE" // requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
// ) { // ) {
// _orgemployeePosMaster = orgemployeePosMaster.map((x) => ({
// ...x,
// ancestorDNA:
// x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
// ? x.id
// : x.ancestorDNA,
// }));
// await repoEmployeePosmaster.save(_orgemployeePosMaster);
const validProfileIds = new Set(
(await repoProfileEmployee.find({ select: ["id"] })).map(p => p.id)
);
_orgemployeePosMaster = orgemployeePosMaster.map((x) => ({ _orgemployeePosMaster = orgemployeePosMaster.map((x) => ({
...x, ...x,
current_holderId: x.current_holderId && validProfileIds.has(x.current_holderId)
? x.current_holderId
: null,
ancestorDNA: ancestorDNA:
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000" !x.ancestorDNA || x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
? x.id ? x.id
: x.ancestorDNA, : x.ancestorDNA,
})); }));
// await repoEmployeePosmaster.save(_orgemployeePosMaster);
await repoEmployeePosmaster await repoEmployeePosmaster
.createQueryBuilder() .createQueryBuilder()
.insert() .insert()