summaryrefslogtreecommitdiff
path: root/lib/sedp/sync-form.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sedp/sync-form.ts')
-rw-r--r--lib/sedp/sync-form.ts61
1 files changed, 41 insertions, 20 deletions
diff --git a/lib/sedp/sync-form.ts b/lib/sedp/sync-form.ts
index 559c09a2..6ae2e675 100644
--- a/lib/sedp/sync-form.ts
+++ b/lib/sedp/sync-form.ts
@@ -129,6 +129,7 @@ interface newRegister {
REG_TYPE_ID: string;
TOOL_ID: string;
TOOL_TYPE: string;
+ SCOPES: string[];
MAP_CLS: {
TOOL_ATT_NAME: string;
ITEMS: ClassItmes[];
@@ -933,10 +934,15 @@ export async function saveFormMappingsAndMetas(
const defaultAttributes = await getDefaulTAttributes();
/* ------------------------------------------------------------------ */
- /* 2. Contract‑item look‑up (TOOL_TYPE) - 수정된 부분 */
+ /* 2. Contract‑item look‑up (SCOPES) - 수정된 부분 */
/* ------------------------------------------------------------------ */
- const uniqueItemCodes = [...new Set(newRegisters.filter(nr => nr.TOOL_TYPE).map(nr => nr.TOOL_TYPE as string))];
- const itemCodeToContractItemIds = await getContractItemsByItemCodes(uniqueItemCodes, projectId, projectCode);
+ // SCOPES 배열에서 모든 unique한 itemCode들을 추출
+ const uniqueItemCodes = [...new Set(
+ newRegisters
+ .filter(nr => nr.SCOPES && nr.SCOPES.length > 0)
+ .flatMap(nr => nr.SCOPES as string[])
+ )];
+ const itemCodeToContractItemIds = await getContractItemsByItemCodes(uniqueItemCodes, projectId);
/* ------------------------------------------------------------------ */
/* 3. Buffers for bulk insert */
@@ -1019,27 +1025,42 @@ export async function saveFormMappingsAndMetas(
if (!cls) { console.warn(`클래스 ${classId} 없음`); return; }
const tp = tagTypeMap.get(cls.tagTypeCode);
if (!tp) { console.warn(`태그 타입 ${cls.tagTypeCode} 없음`); return; }
- mappingsToSave.push({ projectId, tagTypeLabel: tp.description, classLabel: cls.label, formCode, formName: legacy?.DESC || formCode, remark: newReg.TOOL_TYPE || null, ep: newReg.EP_ID || legacy?.EP_ID || "", createdAt: new Date(), updatedAt: new Date() });
+ // SCOPES 배열을 문자열로 변환하여 remark에 저장
+ const scopesRemark = newReg.SCOPES && newReg.SCOPES.length > 0 ? newReg.SCOPES.join(', ') : null;
+ mappingsToSave.push({
+ projectId,
+ tagTypeLabel: tp.description,
+ classLabel: cls.label,
+ formCode,
+ formName: legacy?.DESC || formCode,
+ remark: scopesRemark,
+ ep: newReg.EP_ID || legacy?.EP_ID || "",
+ createdAt: new Date(),
+ updatedAt: new Date()
+ });
});
/* ---------- 4‑d. contractItem ↔ form - 수정된 부분 -------------- */
- if (newReg.TOOL_TYPE) {
- const contractItemIds = itemCodeToContractItemIds.get(newReg.TOOL_TYPE);
- if (contractItemIds && contractItemIds.length > 0) {
- // 모든 contractItemId에 대해 form 생성
- contractItemIds.forEach(cId => {
- contractItemIdsWithForms.add(cId);
- formsToSave.push({
- contractItemId: cId,
- formCode,
- formName: legacy?.DESC || formCode,
- eng: true,
- createdAt: new Date(),
- updatedAt: new Date()
+ if (newReg.SCOPES && newReg.SCOPES.length > 0) {
+ // SCOPES 배열의 각 itemCode에 대해 처리
+ for (const itemCode of newReg.SCOPES) {
+ const contractItemIds = itemCodeToContractItemIds.get(itemCode);
+ if (contractItemIds && contractItemIds.length > 0) {
+ // 모든 contractItemId에 대해 form 생성
+ contractItemIds.forEach(cId => {
+ contractItemIdsWithForms.add(cId);
+ formsToSave.push({
+ contractItemId: cId,
+ formCode,
+ formName: legacy?.DESC || formCode,
+ eng: true,
+ createdAt: new Date(),
+ updatedAt: new Date()
+ });
});
- });
- } else {
- console.warn(`itemCode ${newReg.TOOL_TYPE} 의 contractItemId 없음`);
+ } else {
+ console.warn(`itemCode ${itemCode} 의 contractItemId 없음`);
+ }
}
}
}