diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-17 10:00:07 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-17 10:00:07 +0000 |
| commit | 213b995271edfbe7604d07ba4b71fcc20038a894 (patch) | |
| tree | 41540fafa74d18755bccd00d4368e5652d8f6092 /lib/bidding/selection/actions.ts | |
| parent | f1676f41e6edadd5841bff6a097dc93fbd195b92 (diff) | |
(최겸) 구매 입찰 수정
Diffstat (limited to 'lib/bidding/selection/actions.ts')
| -rw-r--r-- | lib/bidding/selection/actions.ts | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/lib/bidding/selection/actions.ts b/lib/bidding/selection/actions.ts index e17e9292..16b2c083 100644 --- a/lib/bidding/selection/actions.ts +++ b/lib/bidding/selection/actions.ts @@ -127,7 +127,8 @@ export async function getQuotationHistory(biddingId: number, vendorId: number) { )) .limit(1) - if (!companyData.length || !companyData[0].quotationSnapshots) { + // 데이터 존재 여부 및 유효성 체크 + if (!companyData.length || !companyData[0]?.quotationSnapshots) { return { success: true, data: { @@ -136,7 +137,33 @@ export async function getQuotationHistory(biddingId: number, vendorId: number) { } } - const snapshots = companyData[0].quotationSnapshots as any[] + let snapshots = companyData[0].quotationSnapshots + + // quotationSnapshots가 JSONB 타입이므로 파싱이 필요할 수 있음 + if (typeof snapshots === 'string') { + try { + snapshots = JSON.parse(snapshots) + } catch (parseError) { + console.error('Failed to parse quotationSnapshots:', parseError) + return { + success: true, + data: { + history: [] + } + } + } + } + + // snapshots가 배열인지 확인 + if (!Array.isArray(snapshots)) { + console.error('quotationSnapshots is not an array:', typeof snapshots) + return { + success: true, + data: { + history: [] + } + } + } // PR 항목 정보 조회 (스냅샷의 prItemId로 매핑하기 위해) const prItemIds = snapshots.flatMap(snapshot => @@ -146,12 +173,11 @@ export async function getQuotationHistory(biddingId: number, vendorId: number) { const prItems = prItemIds.length > 0 ? await db .select({ id: prItemsForBidding.id, - itemCode: prItemsForBidding.itemCode, - itemName: prItemsForBidding.itemName, - specification: prItemsForBidding.specification, + itemNumber: prItemsForBidding.itemNumber, + itemInfo: prItemsForBidding.itemInfo, quantity: prItemsForBidding.quantity, - unit: prItemsForBidding.unit, - deliveryDate: prItemsForBidding.deliveryDate + quantityUnit: prItemsForBidding.quantityUnit, + requestedDeliveryDate: prItemsForBidding.requestedDeliveryDate }) .from(prItemsForBidding) .where(sql`${prItemsForBidding.id} IN ${prItemIds}`) : [] @@ -181,14 +207,13 @@ export async function getQuotationHistory(biddingId: number, vendorId: number) { const items = snapshot.items?.map((item: any) => { const prItem = prItemMap.get(item.prItemId) return { - itemCode: prItem?.itemCode || `ITEM${item.prItemId}`, - itemName: prItem?.itemName || '품목 정보 없음', - specification: prItem?.specification || item.technicalSpecification || '-', + itemCode: prItem?.itemNumber || `ITEM${item.prItemId}`, + itemName: prItem?.itemInfo || '품목 정보 없음', quantity: prItem?.quantity || 0, - unit: prItem?.unit || 'EA', + unit: prItem?.quantityUnit || 'EA', unitPrice: item.bidUnitPrice, totalPrice: item.bidAmount, - deliveryDate: item.proposedDeliveryDate ? new Date(item.proposedDeliveryDate) : prItem?.deliveryDate ? new Date(prItem.deliveryDate) : new Date() + deliveryDate: item.proposedDeliveryDate ? new Date(item.proposedDeliveryDate) : prItem?.requestedDeliveryDate ? new Date(prItem.requestedDeliveryDate) : new Date() } }) || [] |
