diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-13 11:05:09 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-13 11:05:09 +0000 |
| commit | 33be47506f0aa62b969d82521580a29e95080268 (patch) | |
| tree | 6b7e232f2d78ef8775944ea085a36b3ccbce7d95 /lib/vendor-document-list/import-service.ts | |
| parent | 2ac95090157c355ea1bd0b8eb1e1e5e2bd56faf4 (diff) | |
(대표님) 입찰, 법무검토, EDP 변경사항 대응, dolce 개선, form-data 개선, 정규업체 등록관리 추가
(최겸) pq 미사용 컴포넌트 및 페이지 제거, 파일 라우트에 pq 적용
Diffstat (limited to 'lib/vendor-document-list/import-service.ts')
| -rw-r--r-- | lib/vendor-document-list/import-service.ts | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/vendor-document-list/import-service.ts b/lib/vendor-document-list/import-service.ts index 84e4263c..216e373e 100644 --- a/lib/vendor-document-list/import-service.ts +++ b/lib/vendor-document-list/import-service.ts @@ -9,6 +9,8 @@ import { v4 as uuidv4 } from "uuid" import { extname } from "path" import * as crypto from "crypto" import { debugError, debugWarn, debugSuccess, debugProcess } from "@/lib/debug-utils" +import { getServerSession } from "next-auth/next" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" export interface ImportResult { success: boolean @@ -155,11 +157,11 @@ class ImportService { throw new Error(`Project code or vendor code not found for contract ${projectId}`) } - debugLog(`계약 정보 조회 완료`, { - projectId, - projectCode: contractInfo.projectCode, - vendorCode: contractInfo.vendorCode - }) + // debugLog(`계약 정보 조회 완료`, { + // projectId, + // projectCode: contractInfo.projectCode, + // vendorCode: contractInfo.vendorCode + // }) // 2. 각 drawingKind별로 데이터 조회 const allDocuments: DOLCEDocument[] = [] @@ -324,6 +326,13 @@ class ImportService { projectCode: string; vendorCode: string; } | null> { + + const session = await getServerSession(authOptions) + if (!session?.user?.companyId) { + throw new Error("인증이 필요합니다.") + } + + const [result] = await db .select({ projectCode: projects.code, @@ -332,7 +341,7 @@ class ImportService { .from(contracts) .innerJoin(projects, eq(contracts.projectId, projects.id)) .innerJoin(vendors, eq(contracts.vendorId, vendors.id)) - .where(eq(contracts.projectId, projectId)) + .where(and(eq(contracts.projectId, projectId),eq(contracts.vendorId, Number(session.user.companyId)))) .limit(1) return result?.projectCode && result?.vendorCode @@ -633,6 +642,15 @@ class ImportService { dolceDoc: DOLCEDocument, sourceSystem: string ): Promise<'NEW' | 'UPDATED' | 'SKIPPED'> { + + const session = await getServerSession(authOptions) + if (!session?.user?.companyId) { + throw new Error("인증이 필요합니다.") + } + + const vendorId = Number(session.user.companyId) + + // 기존 문서 조회 (문서 번호로) const existingDoc = await db .select() @@ -646,6 +664,7 @@ class ImportService { // DOLCE 문서를 DB 스키마에 맞게 변환 const documentData = { projectId, + vendorId, docNumber: dolceDoc.DrawingNo, title: dolceDoc.DrawingName, status: 'ACTIVE', |
