diff options
| author | joonhoekim <26rote@gmail.com> | 2025-11-03 16:53:58 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-11-03 16:53:58 +0900 |
| commit | 6653a4bdf9ac9d12037ac62cfe8c8d31d60cadd3 (patch) | |
| tree | fd6a4272caff6de82f71dc8adb51d3cdd803083c /lib/vendor-document-list/enhanced-document-service.ts | |
| parent | c2938cf488c131243c4f9f8ce3a56fad4b025f68 (diff) | |
(김준회) dolce: 프로젝트 필터 오류 수정
Diffstat (limited to 'lib/vendor-document-list/enhanced-document-service.ts')
| -rw-r--r-- | lib/vendor-document-list/enhanced-document-service.ts | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/lib/vendor-document-list/enhanced-document-service.ts b/lib/vendor-document-list/enhanced-document-service.ts index 96a5ecff..bafa61dc 100644 --- a/lib/vendor-document-list/enhanced-document-service.ts +++ b/lib/vendor-document-list/enhanced-document-service.ts @@ -1158,14 +1158,21 @@ export async function getDocumentDetails(documentId: number) { const companyId = session?.user?.companyId; if (!companyId) { - return { stats: {}, totalDocuments: 0, primaryDrawingKind: null, b4Stats: { gttDeliverableCount: 0, shiInputCount: 0 } } + return { + stats: {}, + totalDocuments: 0, + primaryDrawingKind: null, + b4Stats: { gttDeliverableCount: 0, shiInputCount: 0 }, + projectCodeStats: [] + } } - // DrawingKind별 통계 조회 (B4의 경우 drawingMoveGbn도 함께 조회) + // DrawingKind별 통계 조회 (B4의 경우 drawingMoveGbn도 함께 조회, projectCode도 추가) const documents = await db .select({ drawingKind: simplifiedDocumentsView.drawingKind, drawingMoveGbn: simplifiedDocumentsView.drawingMoveGbn, + projectCode: simplifiedDocumentsView.projectCode, }) .from(simplifiedDocumentsView) .where(eq(simplifiedDocumentsView.vendorId, Number(companyId))) @@ -1188,6 +1195,18 @@ export async function getDocumentDetails(documentId: number) { ).length, } + // 🔥 프로젝트 코드별 통계 계산 + const projectCodeMap = new Map<string, number>() + documents.forEach(doc => { + const code = doc.projectCode || 'Unknown' + projectCodeMap.set(code, (projectCodeMap.get(code) || 0) + 1) + }) + + // 정렬된 배열로 변환 (프로젝트 코드 알파벳순) + const projectCodeStats = Array.from(projectCodeMap.entries()) + .sort((a, b) => a[0].localeCompare(b[0])) + .map(([code, count]) => ({ code, count })) + // 가장 많은 DrawingKind 찾기 const primaryDrawingKind = Object.entries(stats) .sort(([,a], [,b]) => b - a)[0]?.[0] as 'B3' | 'B4' | 'B5' | undefined @@ -1197,10 +1216,17 @@ export async function getDocumentDetails(documentId: number) { totalDocuments: documents.length, primaryDrawingKind: primaryDrawingKind || null, b4Stats, // B4 세부 통계 추가 + projectCodeStats, // 🔥 프로젝트 코드 통계 추가 } } catch (err) { console.error("Error fetching user vendor document stats:", err) - return { stats: {}, totalDocuments: 0, primaryDrawingKind: null, b4Stats: { gttDeliverableCount: 0, shiInputCount: 0 } } + return { + stats: {}, + totalDocuments: 0, + primaryDrawingKind: null, + b4Stats: { gttDeliverableCount: 0, shiInputCount: 0 }, + projectCodeStats: [] + } } } |
