From b7cd88af9e1da463abb3a094a218f6a69fe4ec6c Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Wed, 19 Mar 2025 18:16:58 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87?= =?UTF-8?q?=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/rabbitmq.ts | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index cfc26fb7..d47e0bd3 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -1186,7 +1186,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { //หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna const orgPosMaster = await posMasterRepository.find({ where: { orgRevisionId: requestBody.orgRevisionId }, - relations: ["positions", "posMasterAssigns"], + relations: ["positions"], }); let _orgPosMaster: PosMaster[] = []; @@ -1237,6 +1237,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { for await (const item of orgPosMaster.filter( (x: PosMaster) => x.orgRootId == dataId && x.orgChild1Id == null, ) as any) { + let posMasterAssign = await posMasterAssignRepository.find({ + where: { posMasterId: item.id }, + }); delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; @@ -1275,7 +1278,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { // Copy assignments await posMasterAssignRepository.save( - item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({ + posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({ ...rest, posMasterId: posMaster.id, })), @@ -1326,6 +1329,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { for await (const item of orgPosMaster.filter( (x: PosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null, ) as any) { + let posMasterAssign = await posMasterAssignRepository.find({ + where: { posMasterId: item.id }, + }); delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; @@ -1365,7 +1371,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { // Copy assignments await posMasterAssignRepository.save( - item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({ + posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({ ...rest, posMasterId: posMaster.id, })), @@ -1417,6 +1423,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { for await (const item of orgPosMaster.filter( (x: PosMaster) => x.orgChild2Id == data2Id && x.orgChild3Id == null, ) as any) { + let posMasterAssign = await posMasterAssignRepository.find({ + where: { posMasterId: item.id }, + }); delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; @@ -1457,7 +1466,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { // Copy assignments await posMasterAssignRepository.save( - item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({ + posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({ ...rest, posMasterId: posMaster.id, })), @@ -1510,6 +1519,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { for await (const item of orgPosMaster.filter( (x: PosMaster) => x.orgChild3Id == data3Id && x.orgChild4Id == null, ) as any) { + let posMasterAssign = await posMasterAssignRepository.find({ + where: { posMasterId: item.id }, + }); delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; @@ -1551,7 +1563,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { // Copy assignments await posMasterAssignRepository.save( - item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({ + posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({ ...rest, posMasterId: posMaster.id, })), @@ -1606,6 +1618,9 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { for await (const item of orgPosMaster.filter( (x: PosMaster) => x.orgChild4Id == data4Id, ) as any) { + let posMasterAssign = await posMasterAssignRepository.find({ + where: { posMasterId: item.id }, + }); delete item.id; const posMaster = Object.assign(new PosMaster(), item); posMaster.positions = []; @@ -1648,7 +1663,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { // Copy assignments await posMasterAssignRepository.save( - item.posMasterAssigns.map(({ id, ...rest }: PosMasterAssign) => ({ + posMasterAssign.map(({ id, ...rest }: PosMasterAssign) => ({ ...rest, posMasterId: posMaster.id, })), @@ -1711,7 +1726,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { }); // await posMasterRepository.remove(_posMasters); const batchSize = 1000; - const removeInBatches = async (repository:any, data:any, label:any) => { + const removeInBatches = async (repository: any, data: any, label: any) => { for (let i = 0; i < data.length; i += batchSize) { const batch = data.slice(i, i + batchSize); try { @@ -1724,7 +1739,11 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { }; await removeInBatches(posMasterRepository, _posMasters, "PosMaster"); await removeInBatches(employeePosMasterRepository, _employeePosMasters, "EmployeePosMaster"); - await removeInBatches(employeeTempPosMasterRepository, _employeeTempPosMasters, "EmployeeTempPosMaster"); + await removeInBatches( + employeeTempPosMasterRepository, + _employeeTempPosMasters, + "EmployeeTempPosMaster", + ); await child4Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }); await child3Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }); await child2Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });