validate draft and publish
This commit is contained in:
parent
cc7c5c26ae
commit
6f57be2fe9
5 changed files with 80 additions and 63 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -266,6 +266,9 @@ export class PosMaster extends EntityBase {
|
|||
}
|
||||
|
||||
export class CreatePosMaster {
|
||||
@Column()
|
||||
id: string | null;
|
||||
|
||||
@Column()
|
||||
posMasterNoPrefix: string | null;
|
||||
|
||||
|
|
|
|||
|
|
@ -534,23 +534,23 @@ export function editLogSequence(req: RequestWithUser, index: number, data: LogSe
|
|||
}
|
||||
|
||||
export async function checkQueueInProgress(queueName: string) {
|
||||
// const axios = require('axios');
|
||||
// console.log("Checking queue in progress");
|
||||
// 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 },
|
||||
// });
|
||||
const axios = require('axios');
|
||||
// console.log("Checking queue in progress");
|
||||
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 },
|
||||
});
|
||||
|
||||
// const q = res.data;
|
||||
const q = res.data;
|
||||
|
||||
// console.log(`Queue "${queueName}" has:`);
|
||||
// console.log(` - ${q.messages_ready} messages ready`);
|
||||
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
|
||||
// console.log(`Queue "${queueName}" has:`);
|
||||
// console.log(` - ${q.messages_ready} messages ready`);
|
||||
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
|
||||
|
||||
// if (q.messages_unacknowledged > 0) {
|
||||
// return true;
|
||||
// }
|
||||
if (q.messages_unacknowledged > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function chunkArray(array: any, size: number) {
|
||||
|
|
|
|||
|
|
@ -622,14 +622,28 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_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) => ({
|
||||
...x,
|
||||
current_holderId: x.current_holderId && validProfileIds.has(x.current_holderId)
|
||||
? x.current_holderId
|
||||
: null,
|
||||
ancestorDNA:
|
||||
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
!x.ancestorDNA || x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.ancestorDNA,
|
||||
}));
|
||||
// await repoEmployeePosmaster.save(_orgemployeePosMaster);
|
||||
await repoEmployeePosmaster
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue