feat: 견적 품목 추가 시 단가 자동 조회 기능

- fetchItemPrices 클라이언트 API 함수 추가 (items.ts)
- 품목 선택 시 /api/proxy/quotes/items/prices를 통해 단가 조회
- 조회된 단가로 견적금액요약에 즉시 반영
This commit is contained in:
2026-01-29 08:05:08 +09:00
parent 15b4350051
commit 32a1ed2de7
2 changed files with 77 additions and 5 deletions

View File

@@ -759,4 +759,59 @@ export async function revalidateItems(): Promise<void> {
const { revalidatePath } = await import('next/cache');
revalidatePath('/items');
}
}
// ===== 품목 단가 조회 =====
/** 품목 단가 조회 결과 */
export interface ItemPriceResult {
item_code: string;
unit_price: number;
}
/**
* 품목 단가 조회 (견적 품목 추가 시 사용)
*
* @param itemCodes - 조회할 품목 코드 배열
* @returns 품목 코드별 단가 정보
*
* @example
* const prices = await fetchItemPrices(['N71807', 'N71808']);
* console.log(prices['N71807']?.unit_price); // 1320000
*/
export async function fetchItemPrices(
itemCodes: string[]
): Promise<Record<string, ItemPriceResult>> {
if (!itemCodes.length) {
return {};
}
try {
// 프록시 경유: /api/proxy/quotes/items/prices → /api/v1/quotes/items/prices
const response = await fetch('/api/proxy/quotes/items/prices', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ item_codes: itemCodes }),
credentials: 'include',
});
if (!response.ok) {
console.error('[fetchItemPrices] API 에러:', response.status);
return {};
}
const result = await response.json();
console.log('[fetchItemPrices] API 응답:', result);
if (result.success && result.data) {
return result.data as Record<string, ItemPriceResult>;
}
return {};
} catch (error) {
console.error('[fetchItemPrices] 에러:', error);
return {};
}
}