summaryrefslogtreecommitdiff
path: root/lib/sedp/sync-form.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-23 09:08:03 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-23 09:08:03 +0000
commita50bc9baea332f996e6bc3a5d70c69f6d2d0f194 (patch)
tree7493b8a4d9cc7cc3375068f1aa10b0067e85988f /lib/sedp/sync-form.ts
parent7402e759857d511add0d3eb19f1fa13cb957c1df (diff)
(대표님, 최겸) 기본계약 템플릿 및 에디터, 기술영업 벤더정보, 파일 보안다운로드, 벤더 document sync 상태 서비스, 메뉴 Config, 기술영업 미사용 제거
Diffstat (limited to 'lib/sedp/sync-form.ts')
-rw-r--r--lib/sedp/sync-form.ts17
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 */