feat: Add savedIds to UPSERT response and update related components
- Enhanced the UPSERT process in DataService to include savedIds in the response, allowing tracking of newly saved record IDs. - Updated the dataApi to reflect the new savedIds field in the Promise return type. - Modified the SelectedItemsDetailInputComponent to handle and inject saved mapping IDs into detail records, improving data integrity and management during the save process. - Added logging for savedIds to facilitate debugging and tracking of saved records.
This commit is contained in:
@@ -689,6 +689,8 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
|
||||
// 레코드에 id(기존 DB PK)가 있으면 EDIT 모드 → 고아 삭제
|
||||
// id 없으면 CREATE 모드 → 기존 레코드 건드리지 않음
|
||||
const mappingHasDbIds = mappingRecords.some((r) => !!r.id);
|
||||
// 저장된 매핑 ID를 추적 (디테일 테이블에 mapping_id 주입용)
|
||||
let savedMappingIds: string[] = [];
|
||||
try {
|
||||
const mappingResult = await dataApi.upsertGroupedRecords(
|
||||
mainTable,
|
||||
@@ -696,6 +698,11 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
|
||||
mappingRecords,
|
||||
{ deleteOrphans: mappingHasDbIds },
|
||||
);
|
||||
// 백엔드에서 반환된 저장된 레코드 ID 목록
|
||||
if (mappingResult.success && mappingResult.savedIds) {
|
||||
savedMappingIds = mappingResult.savedIds;
|
||||
console.log(`✅ ${mainTable} 저장 완료, savedIds:`, savedMappingIds);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`❌ ${mainTable} 저장 실패:`, err);
|
||||
}
|
||||
@@ -755,6 +762,18 @@ export const SelectedItemsDetailInputComponent: React.FC<SelectedItemsDetailInpu
|
||||
priceRecords.push(emptyRecord);
|
||||
}
|
||||
|
||||
// Step1에서 저장된 매핑 ID를 디테일 레코드에 주입
|
||||
// (customer_item_prices.mapping_id ← customer_item_mapping.id)
|
||||
if (savedMappingIds.length > 0) {
|
||||
const mappingId = savedMappingIds[0]; // 일반적으로 1:N (매핑 1개 : 단가 N개)
|
||||
priceRecords.forEach((record) => {
|
||||
if (!record.mapping_id) {
|
||||
record.mapping_id = mappingId;
|
||||
}
|
||||
});
|
||||
console.log(`🔗 디테일 레코드에 mapping_id 주입: ${mappingId}`);
|
||||
}
|
||||
|
||||
const priceHasDbIds = priceRecords.some((r) => !!r.id);
|
||||
try {
|
||||
const detailResult = await dataApi.upsertGroupedRecords(
|
||||
|
||||
Reference in New Issue
Block a user