set null ตำแหน่งติดเงื่อนไข
This commit is contained in:
parent
f307484707
commit
dda4488409
4 changed files with 198 additions and 113 deletions
|
|
@ -58,10 +58,10 @@ export async function init() {
|
|||
console.log(channel ? "[AMQ] Create channel success" : "[AMQ] Create channel failed");
|
||||
|
||||
channel.assertQueue(queue, { durable: true }), //----> (1.5) assert queue and set durable (if "true" save to disk on RabbitMQ)
|
||||
channel.assertQueue(queue_org, { durable: true }),
|
||||
channel.assertQueue(queue_org_draft, { durable: true }),
|
||||
channel.assertQueue(queue_command_noti, { durable: true }),
|
||||
channel.prefetch(1);
|
||||
channel.assertQueue(queue_org, { durable: true }),
|
||||
channel.assertQueue(queue_org_draft, { durable: true }),
|
||||
channel.assertQueue(queue_command_noti, { durable: true }),
|
||||
channel.prefetch(1);
|
||||
|
||||
sendToQueue = (payload: any, persistent = true) => {
|
||||
//----> (2) sendQueue To RabbitMQ and set persistent (if "true" redo the failed queue when server run again)
|
||||
|
|
@ -84,7 +84,7 @@ export async function init() {
|
|||
|
||||
console.log("[AMQ] Listening for message...");
|
||||
createConsumer(queue, channel, handler), //----> (3) Process Consumer
|
||||
createConsumer(queue_org, channel, handler_org);
|
||||
createConsumer(queue_org, channel, handler_org);
|
||||
createConsumer(queue_org_draft, channel, handler_org_draft);
|
||||
createConsumer(queue_command_noti, channel, handler_command_noti);
|
||||
// createConsumer(queue2, channel, handler2);
|
||||
|
|
@ -168,7 +168,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
console.log("[AMQ] Excecute Command Success");
|
||||
Object.assign(command, { status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt });
|
||||
const result = await repo.save(command).catch((e) => console.log(e));
|
||||
if(user){
|
||||
if (user) {
|
||||
sendWebSocket(
|
||||
"send-command-notification",
|
||||
{
|
||||
|
|
@ -176,14 +176,14 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} เสร็จสิ้น`,
|
||||
payload: command,
|
||||
},
|
||||
{ userId: user?.sub},
|
||||
{ userId: user?.sub },
|
||||
).catch(console.error);
|
||||
}
|
||||
return !!result;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
if(user){
|
||||
if (user) {
|
||||
sendWebSocket(
|
||||
"send-command-notification",
|
||||
{
|
||||
|
|
@ -191,7 +191,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} ผิดพลาด`,
|
||||
payload: command,
|
||||
},
|
||||
{ userId: user?.sub},
|
||||
{ userId: user?.sub },
|
||||
).catch(console.error);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -306,12 +306,12 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise<boolean>
|
|||
subject: `${command.issue}`,
|
||||
body: `${command.issue}`,
|
||||
receiverUserIds: profiles,
|
||||
payload: "",// แนบไฟล์ (ถ้าจำเป็น)
|
||||
payload: "", // แนบไฟล์ (ถ้าจำเป็น)
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
isSendNotification: true,
|
||||
},
|
||||
false
|
||||
false,
|
||||
)
|
||||
.catch((error) => {
|
||||
if (error.response) {
|
||||
|
|
@ -329,17 +329,18 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise<boolean>
|
|||
console.error("Full error object:", error);
|
||||
});
|
||||
|
||||
let profilesSend = command && command.commandSends.length > 0
|
||||
? command.commandSends
|
||||
.filter((x: any) => x.profileId != null)
|
||||
.map((x: any) => ({
|
||||
receiverUserId: x.profileId,
|
||||
notiLink: "",
|
||||
isSendMail: x.commandSendCCs.map((x: any) => x.name == "EMAIL").length > 0,
|
||||
isSendInbox: x.commandSendCCs.map((x: any) => x.name == "INBOX").length > 0,
|
||||
isSendNotification: true,
|
||||
}))
|
||||
: [];
|
||||
let profilesSend =
|
||||
command && command.commandSends.length > 0
|
||||
? command.commandSends
|
||||
.filter((x: any) => x.profileId != null)
|
||||
.map((x: any) => ({
|
||||
receiverUserId: x.profileId,
|
||||
notiLink: "",
|
||||
isSendMail: x.commandSendCCs.map((x: any) => x.name == "EMAIL").length > 0,
|
||||
isSendInbox: x.commandSendCCs.map((x: any) => x.name == "INBOX").length > 0,
|
||||
isSendNotification: true,
|
||||
}))
|
||||
: [];
|
||||
|
||||
const profilesSendRequest = new CallAPI()
|
||||
.PostData(
|
||||
|
|
@ -349,10 +350,11 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise<boolean>
|
|||
subject: `${command.issue}`,
|
||||
body: `${command.issue}`,
|
||||
receiverUserIds: profilesSend,
|
||||
payload: "", // แนบไฟล์ (ถ้าจำเป็น)
|
||||
payload: "", // แนบไฟล์ (ถ้าจำเป็น)
|
||||
},
|
||||
false
|
||||
).catch((error) => {
|
||||
false,
|
||||
)
|
||||
.catch((error) => {
|
||||
if (error.response) {
|
||||
// Server ตอบกลับ (มี status code 4xx หรือ 5xx)
|
||||
console.error("Error status:", error.response.status);
|
||||
|
|
@ -372,14 +374,12 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise<boolean>
|
|||
|
||||
console.log("[AMQ] Send Notification Success");
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
console.error("[AMQ] Error:", error);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||
//----> condition before process consume
|
||||
const repoPosmaster = AppDataSource.getRepository(PosMaster);
|
||||
|
|
@ -397,7 +397,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
|
||||
const orgRevisionPublish = await repoOrgRevision
|
||||
.createQueryBuilder("orgRevision")
|
||||
.where("orgRevision.orgRevisionIsDraft = false")
|
||||
.where("orgRevision.orgRevisionIsDraft = false")
|
||||
.andWhere("orgRevision.orgRevisionIsCurrent = true")
|
||||
.getOne();
|
||||
|
||||
|
|
@ -406,12 +406,14 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
.where("orgRevision.orgRevisionIsDraft = true")
|
||||
.andWhere("orgRevision.orgRevisionIsCurrent = false")
|
||||
.getOne();
|
||||
if (orgRevisionPublish) { //เข้าเงื่อนไขจะเปลี่ยนสถานะ orgRevisionPublish เป็นไม่ใช่ current และไม่เป็น daft
|
||||
if (orgRevisionPublish) {
|
||||
//เข้าเงื่อนไขจะเปลี่ยนสถานะ orgRevisionPublish เป็นไม่ใช่ current และไม่เป็น daft
|
||||
orgRevisionPublish.orgRevisionIsDraft = false;
|
||||
orgRevisionPublish.orgRevisionIsCurrent = false;
|
||||
await repoOrgRevision.save(orgRevisionPublish);
|
||||
}
|
||||
if (orgRevisionDraft) { //เข้าเงื่อนไขจะเปลี่ยนสถานะ orgRevisionDraft เป็นไม่ใช่ daft และเป็น current
|
||||
if (orgRevisionDraft) {
|
||||
//เข้าเงื่อนไขจะเปลี่ยนสถานะ orgRevisionDraft เป็นไม่ใช่ daft และเป็น current
|
||||
orgRevisionDraft.orgRevisionIsCurrent = true;
|
||||
orgRevisionDraft.orgRevisionIsDraft = false;
|
||||
await repoOrgRevision.save(orgRevisionDraft);
|
||||
|
|
@ -449,7 +451,8 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
}
|
||||
}
|
||||
item.current_holderId = item.next_holderId;
|
||||
if(item.current_holderId){
|
||||
item.conditionReason = _null;
|
||||
if (item.current_holderId) {
|
||||
item.conditionReason = _null;
|
||||
}
|
||||
item.next_holderId = null;
|
||||
|
|
@ -461,7 +464,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
if (orgRevisionPublish != null && orgRevisionDraft != null) {
|
||||
//new main revision
|
||||
const before = null;
|
||||
|
||||
|
||||
//ทุก orgRoot และ orgChild ข้างล่างนี้จะเป็นตัวเก่าที่ไม่ได้เป็น current revision
|
||||
//cone tree
|
||||
// if (
|
||||
|
|
@ -475,7 +478,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
const orgRoot = await orgRootRepository.find({
|
||||
where: { orgRevisionId: orgRevisionPublish.id },
|
||||
});
|
||||
|
||||
|
||||
const orgChild1 = await child1Repository.find({
|
||||
where: { orgRevisionId: orgRevisionPublish.id },
|
||||
});
|
||||
|
|
@ -537,11 +540,11 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
}));
|
||||
await repoEmployeeTempPosmaster.save(_orgemployeeTempPosMaster);
|
||||
// }
|
||||
|
||||
|
||||
//create org
|
||||
orgRoot.forEach(async (x: any) => {
|
||||
var dataId = x.id;
|
||||
|
||||
|
||||
const orgRootCurrent = await orgRootRepository.find({
|
||||
where: { orgRevisionId: orgRevisionDraft.id },
|
||||
});
|
||||
|
|
@ -549,18 +552,20 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
const matchedOrgRoot = orgRootCurrent.find((i: OrgRoot) => {
|
||||
if (
|
||||
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
) {
|
||||
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
|
||||
return (
|
||||
i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
);
|
||||
}
|
||||
return i.ancestorDNA === x.ancestorDNA;
|
||||
});
|
||||
|
||||
|
||||
// if (
|
||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
||||
// ) {
|
||||
//create employeePosmaster
|
||||
|
|
@ -590,7 +595,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
// }
|
||||
// employeePosMaster.current_holderId = null;
|
||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null
|
||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeePosMaster.createdUserId = "";
|
||||
employeePosMaster.createdFullName = "System Administrator";
|
||||
employeePosMaster.createdAt = new Date();
|
||||
|
|
@ -697,10 +702,12 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
const matchedOrgChild1 = orgChild1Current.find((i: OrgChild1) => {
|
||||
if (
|
||||
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
) {
|
||||
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
|
||||
return (
|
||||
i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
);
|
||||
}
|
||||
return i.ancestorDNA === x.ancestorDNA;
|
||||
});
|
||||
|
|
@ -782,7 +789,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
||||
employeeTempPosMaster.positions = [];
|
||||
employeeTempPosMaster.positions = [];
|
||||
// if (
|
||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
||||
|
|
@ -846,14 +853,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
const orgChild2Current = await child2Repository.find({
|
||||
where: { orgRevisionId: orgRevisionDraft.id },
|
||||
});
|
||||
|
||||
|
||||
const matchedOrgChild2 = orgChild2Current.find((i: OrgChild2) => {
|
||||
if (
|
||||
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
) {
|
||||
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
|
||||
return (
|
||||
i.ancestorDNA === null ||
|
||||
i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
);
|
||||
}
|
||||
return i.ancestorDNA === x.ancestorDNA;
|
||||
});
|
||||
|
|
@ -1007,14 +1017,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
const orgChild3Current = await child3Repository.find({
|
||||
where: { orgRevisionId: orgRevisionDraft.id },
|
||||
});
|
||||
|
||||
|
||||
const matchedOrgChild3 = orgChild3Current.find((i: OrgChild3) => {
|
||||
if (
|
||||
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
) {
|
||||
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
|
||||
return (
|
||||
i.ancestorDNA === null ||
|
||||
i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
);
|
||||
}
|
||||
return i.ancestorDNA === x.ancestorDNA;
|
||||
});
|
||||
|
|
@ -1171,14 +1184,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
const orgChild4Current = await child4Repository.find({
|
||||
where: { orgRevisionId: orgRevisionDraft.id },
|
||||
});
|
||||
|
||||
|
||||
const matchedOrgChild4 = orgChild4Current.find((i: OrgChild4) => {
|
||||
if (
|
||||
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === null ||
|
||||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
) {
|
||||
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
|
||||
return (
|
||||
i.ancestorDNA === null ||
|
||||
i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
);
|
||||
}
|
||||
return i.ancestorDNA === x.ancestorDNA;
|
||||
});
|
||||
|
|
@ -1560,7 +1576,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
)
|
||||
) {
|
||||
posMaster.next_holderId = item.current_holderId;
|
||||
if(posMaster.next_holderId){
|
||||
if (posMaster.next_holderId) {
|
||||
posMaster.conditionReason = _null;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1655,7 +1671,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
)
|
||||
) {
|
||||
posMaster.next_holderId = item.current_holderId;
|
||||
if(posMaster.next_holderId){
|
||||
if (posMaster.next_holderId) {
|
||||
posMaster.conditionReason = _null;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1752,7 +1768,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
)
|
||||
) {
|
||||
posMaster.next_holderId = item.current_holderId;
|
||||
if(posMaster.next_holderId){
|
||||
if (posMaster.next_holderId) {
|
||||
posMaster.conditionReason = _null;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1851,7 +1867,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
)
|
||||
) {
|
||||
posMaster.next_holderId = item.current_holderId;
|
||||
if(posMaster.next_holderId){
|
||||
if (posMaster.next_holderId) {
|
||||
posMaster.conditionReason = _null;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1953,7 +1969,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
)
|
||||
) {
|
||||
posMaster.next_holderId = item.current_holderId;
|
||||
if(posMaster.next_holderId){
|
||||
if (posMaster.next_holderId) {
|
||||
posMaster.conditionReason = _null;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -2024,7 +2040,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
}
|
||||
//ลบ daft เก่าที่ค้างแล้วยังไม่ได้เผยแพร่
|
||||
const _orgRevisions = await orgRevisionRepository.find({
|
||||
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
|
||||
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
|
||||
});
|
||||
const _roots = await orgRootRepository.find({
|
||||
where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue