feat: Implement orphan record deletion logic based on edit mode

- Updated the DataService to conditionally delete orphan records only when in EDIT mode, controlled by the deleteOrphans flag.
- Enhanced the SelectedItemsDetailInputComponent to determine the mode (EDIT or CREATE) based on the presence of existing database IDs, ensuring that orphan records are only deleted when necessary.
- Improved data integrity by preventing unintended deletions during the CREATE process.
This commit is contained in:
DDD1542
2026-02-09 15:50:53 +09:00
parent d7f900d8ae
commit 7118a723f3
4 changed files with 30 additions and 7158 deletions

View File

@@ -686,11 +686,15 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
});
});
// 레코드에 id(기존 DB PK)가 있으면 EDIT 모드 → 고아 삭제
// id 없으면 CREATE 모드 → 기존 레코드 건드리지 않음
const mappingHasDbIds = mappingRecords.some((r) => !!r.id);
try {
const mappingResult = await dataApi.upsertGroupedRecords(
mainTable,
itemParentKeys,
mappingRecords,
{ deleteOrphans: mappingHasDbIds },
);
} catch (err) {
console.error(`${mainTable} 저장 실패:`, err);
@@ -751,11 +755,13 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
priceRecords.push(emptyRecord);
}
const priceHasDbIds = priceRecords.some((r) => !!r.id);
try {
const detailResult = await dataApi.upsertGroupedRecords(
detailTable,
itemParentKeys,
priceRecords,
{ deleteOrphans: priceHasDbIds },
);
if (!detailResult.success) {
@@ -767,12 +773,14 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
}
}
// 저장 성공 이벤트
// 저장 성공 이벤트 + 테이블 새로고침 (모든 아이템 저장 완료 후)
window.dispatchEvent(
new CustomEvent("formSaveSuccess", {
detail: { message: "데이터가 저장되었습니다." },
}),
);
// 분할 패널 우측 데이터 새로고침
window.dispatchEvent(new CustomEvent("refreshTable"));
} else {
// ============================================================
// 단일 테이블 저장 (기존 로직 - detailTable 없는 경우)