diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-07 01:44:45 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-07 01:44:45 +0000 |
| commit | 90f79a7a691943a496f67f01c1e493256070e4de (patch) | |
| tree | 37275fde3ae08c2bca384fbbc8eb378de7e39230 /lib/vendors | |
| parent | fbb3b7f05737f9571b04b0a8f4f15c0928de8545 (diff) | |
(대표님) 변경사항 20250707 10시 43분 - unstaged 변경사항 추가
Diffstat (limited to 'lib/vendors')
| -rw-r--r-- | lib/vendors/service.ts | 47 | ||||
| -rw-r--r-- | lib/vendors/validations.ts | 1 |
2 files changed, 10 insertions, 38 deletions
diff --git a/lib/vendors/service.ts b/lib/vendors/service.ts index 7c6ac15d..2328752b 100644 --- a/lib/vendors/service.ts +++ b/lib/vendors/service.ts @@ -50,10 +50,6 @@ import type { import { asc, desc, ilike, inArray, and, or, gte, lte, eq, isNull, count, sql } from "drizzle-orm"; import { rfqItems, rfqs, vendorRfqView } from "@/db/schema/rfq"; import path from "path"; -import fs from "fs/promises"; -import { randomUUID } from "crypto"; -import JSZip from 'jszip'; -import { promises as fsPromises } from 'fs'; import { sendEmail } from "../mail/sendEmail"; import { PgTransaction } from "drizzle-orm/pg-core"; import { items, materials } from "@/db/schema/items"; @@ -61,7 +57,7 @@ import { roles, userRoles, users } from "@/db/schema/users"; import { getServerSession } from "next-auth"; import { authOptions } from "@/app/api/auth/[...nextauth]/route"; import { contracts, contractsDetailView, projects, vendorPQSubmissions, vendorProjectPQs, vendorsLogs } from "@/db/schema"; -import { Hospital } from "lucide-react"; +import { deleteFile, saveFile } from "../file-stroage"; /* ----------------------------------------------------- @@ -235,32 +231,17 @@ async function storeVendorFiles( files: File[], attachmentType: string ) { - const vendorDir = path.join( - process.cwd(), - "public", - "vendors", - String(vendorId) - ) - await fs.mkdir(vendorDir, { recursive: true }) + for (const file of files) { - // Convert file to buffer - const ab = await file.arrayBuffer() - const buffer = Buffer.from(ab) - // Generate a unique filename - const uniqueName = `${randomUUID()}-${file.name}` - const relativePath = path.join("vendors", String(vendorId), uniqueName) - const absolutePath = path.join(process.cwd(), "public", relativePath) - - // Write to disk - await fs.writeFile(absolutePath, buffer) + const saveResult = await saveFile({file, directory:`vendors/${vendorId}` }) // Insert attachment record await tx.insert(vendorAttachments).values({ vendorId, fileName: file.name, - filePath: "/" + relativePath.replace(/\\/g, "/"), + filePath: saveResult.publicPath, attachmentType, // "GENERAL", "CREDIT_RATING", "CASH_FLOW_RATING", ... }) } @@ -1440,17 +1421,8 @@ export async function cleanupTempFiles(fileName: string) { 'use server'; try { - const tempDir = path.join(process.cwd(), 'tmp'); - const filePath = path.join(tempDir, fileName); - - try { - // 파일 존재 확인 - await fsPromises.access(filePath, fs.constants.F_OK); - // 파일 삭제 - await fsPromises.unlink(filePath); - } catch { - // 파일이 없으면 무시 - } + + await deleteFile(`tmp/${fileName}`) return { success: true }; } catch (error) { @@ -2318,10 +2290,9 @@ export async function updateVendorInfo(params: { // 3-2. 파일 시스템에서 파일 삭제 for (const attachment of attachmentsToDelete) { try { - // 파일 경로는 /public 기준이므로 process.cwd()/public을 앞에 붙임 - const filePath = path.join(process.cwd(), 'public', attachment.filePath.replace(/^\//, '')) - await fs.access(filePath, fs.constants.F_OK) // 파일 존재 확인 - await fs.unlink(filePath) // 파일 삭제 + + await deleteFile(attachment.filePath) + } catch (error) { console.warn(`Failed to delete file for attachment ${attachment.id}:`, error) // 파일 삭제 실패해도 DB에서는 삭제 진행 diff --git a/lib/vendors/validations.ts b/lib/vendors/validations.ts index 07eaae83..6c106600 100644 --- a/lib/vendors/validations.ts +++ b/lib/vendors/validations.ts @@ -208,6 +208,7 @@ export const createVendorSchema = z .max(255, "Max length 255"), vendorTypeId: z.number({ required_error: "업체유형을 선택해주세요" }), + representativeWorkExpirence: z.boolean(), email: z.string().email("Invalid email").max(255), |
