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 {
// CheckQueueInProgress
// const [isBusyDraft, isBusyPublish] = await Promise.all([
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
// ]);
const [isBusyDraft, isBusyPublish] = await Promise.all([
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
]);
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
// if (isBusyDraft || isBusyPublish) {
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
// throw new HttpError(
// HttpStatusCode.CONFLICT,
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
// );
// }
if (isBusyDraft || isBusyPublish) {
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
);
}
//new main revision
const before = null;
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
@ -3209,19 +3209,19 @@ export class OrganizationController extends Controller {
try {
// CheckQueueInProgress
// console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว");
// const [isBusyDraft, isBusyPublish] = await Promise.all([
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
// ]);
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
// if (isBusyDraft || isBusyPublish) {
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
// throw new HttpError(
// HttpStatusCode.CONFLICT,
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
// );
// }
const [isBusyDraft, isBusyPublish] = await Promise.all([
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
]);
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
if (isBusyDraft || isBusyPublish) {
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
);
}
const today = new Date();
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();
await this.posMasterRepository.save(posMaster, { data: request });
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(
requestBody.positions.map(async (x: any) => {
const position = Object.assign(new Position());
position.positionName = x.posDictName;
position.positionField = x.posDictField;
position.posTypeId = x.posTypeId == "" ? null : x.posTypeId;
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 });
posMaster.positions.map(async (x:any) => {
const match = requestBody.positions.find((p:any) => p.id == x.id);
if(!match){
//delete
await this.positionRepository.remove(x);
}
}),
);
return new HttpSuccess(posMaster.id);