diff options
Diffstat (limited to 'lib/sedp/sync-form.ts')
| -rw-r--r-- | lib/sedp/sync-form.ts | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/sedp/sync-form.ts b/lib/sedp/sync-form.ts index f9e63caf..559c09a2 100644 --- a/lib/sedp/sync-form.ts +++ b/lib/sedp/sync-form.ts @@ -835,6 +835,7 @@ async function getUomById(projectCode: string, uomId: string): Promise<UOM | nul } // contractItemId 조회 함수 +// contractItemId 조회 함수 (수정됨) async function getContractItemsByItemCodes(itemCodes: string[], projectId: number): Promise<Map<string, number[]>> { try { if (!itemCodes.length) return new Map(); @@ -870,7 +871,7 @@ async function getContractItemsByItemCodes(itemCodes: string[], projectId: numbe ) ); - // itemCode와 contractItemId 배열의 매핑 생성 + // itemCode와 contractItemId 배열의 매핑 생성 (수정된 부분) const itemCodeToContractItemIds = new Map<string, number[]>(); for (const item of itemRecords) { @@ -878,9 +879,17 @@ async function getContractItemsByItemCodes(itemCodes: string[], projectId: numbe if (item.packageCode) { const matchedContractItems = contractItemRecords.filter(ci => ci.itemId === item.id); if (matchedContractItems.length > 0) { - // 일치하는 모든 contractItem을 배열로 저장 const contractItemIds = matchedContractItems.map(ci => ci.id); - itemCodeToContractItemIds.set(item.packageCode, contractItemIds); + + // 기존에 해당 packageCode가 있다면 배열에 추가, 없다면 새로 생성 + if (itemCodeToContractItemIds.has(item.packageCode)) { + const existing = itemCodeToContractItemIds.get(item.packageCode)!; + // 중복 제거하면서 합치기 + const combined = [...new Set([...existing, ...contractItemIds])]; + itemCodeToContractItemIds.set(item.packageCode, combined); + } else { + itemCodeToContractItemIds.set(item.packageCode, contractItemIds); + } } } } @@ -927,7 +936,7 @@ export async function saveFormMappingsAndMetas( /* 2. Contract‑item look‑up (TOOL_TYPE) - 수정된 부분 */ /* ------------------------------------------------------------------ */ const uniqueItemCodes = [...new Set(newRegisters.filter(nr => nr.TOOL_TYPE).map(nr => nr.TOOL_TYPE as string))]; - const itemCodeToContractItemIds = await getContractItemsByItemCodes(uniqueItemCodes, projectId); + const itemCodeToContractItemIds = await getContractItemsByItemCodes(uniqueItemCodes, projectId, projectCode); /* ------------------------------------------------------------------ */ /* 3. Buffers for bulk insert */ |
