From 02b1cf005cf3e1df64183d20ba42930eb2767a9f Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 21 Aug 2025 06:57:36 +0000 Subject: (대표님, 최겸) 설계메뉴추가, 작업사항 업데이트 설계메뉴 - 문서관리 설계메뉴 - 벤더 데이터 gtc 메뉴 업데이트 정보시스템 - 메뉴리스트 및 정보 업데이트 파일 라우트 업데이트 엑셀임포트 개선 기본계약 개선 벤더 가입과정 변경 및 개선 벤더 기본정보 - pq 돌체 오류 수정 및 개선 벤더 로그인 과정 이메일 오류 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/vendor-registration-status/repository.ts | 165 ----------------- lib/vendor-registration-status/service.ts | 260 --------------------------- 2 files changed, 425 deletions(-) delete mode 100644 lib/vendor-registration-status/repository.ts delete mode 100644 lib/vendor-registration-status/service.ts (limited to 'lib/vendor-registration-status') diff --git a/lib/vendor-registration-status/repository.ts b/lib/vendor-registration-status/repository.ts deleted file mode 100644 index f9c3d63f..00000000 --- a/lib/vendor-registration-status/repository.ts +++ /dev/null @@ -1,165 +0,0 @@ -import { db } from "@/db" -import { - vendorBusinessContacts, - vendorAdditionalInfo, - vendors -} from "@/db/schema" -import { eq, and, inArray } from "drizzle-orm" - -// 업무담당자 정보 타입 -export interface VendorBusinessContact { - id: number - vendorId: number - contactType: "sales" | "design" | "delivery" | "quality" | "tax_invoice" - contactName: string - position: string - department: string - responsibility: string - email: string - createdAt: Date - updatedAt: Date -} - -// 추가정보 타입 -export interface VendorAdditionalInfo { - id: number - vendorId: number - businessType?: string - industryType?: string - companySize?: string - revenue?: string - factoryEstablishedDate?: Date - preferredContractTerms?: string - createdAt: Date - updatedAt: Date -} - -// 업무담당자 정보 조회 -export async function getBusinessContactsByVendorId(vendorId: number): Promise { - try { - return await db - .select() - .from(vendorBusinessContacts) - .where(eq(vendorBusinessContacts.vendorId, vendorId)) - .orderBy(vendorBusinessContacts.contactType) - } catch (error) { - console.error("Error fetching business contacts:", error) - throw new Error("업무담당자 정보를 가져오는 중 오류가 발생했습니다.") - } -} - -// 업무담당자 정보 저장/업데이트 -export async function upsertBusinessContacts( - vendorId: number, - contacts: Omit[] -): Promise { - try { - // 기존 데이터 삭제 - await db - .delete(vendorBusinessContacts) - .where(eq(vendorBusinessContacts.vendorId, vendorId)) - - // 새 데이터 삽입 - if (contacts.length > 0) { - await db - .insert(vendorBusinessContacts) - .values(contacts.map(contact => ({ - ...contact, - vendorId, - }))) - } - } catch (error) { - console.error("Error upserting business contacts:", error) - throw new Error("업무담당자 정보 저장 중 오류가 발생했습니다.") - } -} - -// 추가정보 조회 -export async function getAdditionalInfoByVendorId(vendorId: number): Promise { - try { - const result = await db - .select() - .from(vendorAdditionalInfo) - .where(eq(vendorAdditionalInfo.vendorId, vendorId)) - .limit(1) - - return result[0] || null - } catch (error) { - console.error("Error fetching additional info:", error) - throw new Error("추가정보를 가져오는 중 오류가 발생했습니다.") - } -} - -// 추가정보 저장/업데이트 -export async function upsertAdditionalInfo( - vendorId: number, - info: Omit -): Promise { - try { - const existing = await getAdditionalInfoByVendorId(vendorId) - - if (existing) { - // 업데이트 - await db - .update(vendorAdditionalInfo) - .set({ - ...info, - updatedAt: new Date(), - }) - .where(eq(vendorAdditionalInfo.vendorId, vendorId)) - } else { - // 신규 삽입 - await db - .insert(vendorAdditionalInfo) - .values({ - ...info, - vendorId, - }) - } - } catch (error) { - console.error("Error upserting additional info:", error) - throw new Error("추가정보 저장 중 오류가 발생했습니다.") - } -} - -// 특정 벤더의 모든 추가정보 조회 (업무담당자 + 추가정보) -export async function getVendorAllAdditionalData(vendorId: number) { - try { - const [businessContacts, additionalInfo] = await Promise.all([ - getBusinessContactsByVendorId(vendorId), - getAdditionalInfoByVendorId(vendorId) - ]) - - return { - businessContacts, - additionalInfo - } - } catch (error) { - console.error("Error fetching vendor additional data:", error) - throw new Error("벤더 추가정보를 가져오는 중 오류가 발생했습니다.") - } -} - -// 업무담당자 정보 삭제 -export async function deleteBusinessContactsByVendorId(vendorId: number): Promise { - try { - await db - .delete(vendorBusinessContacts) - .where(eq(vendorBusinessContacts.vendorId, vendorId)) - } catch (error) { - console.error("Error deleting business contacts:", error) - throw new Error("업무담당자 정보 삭제 중 오류가 발생했습니다.") - } -} - -// 추가정보 삭제 -export async function deleteAdditionalInfoByVendorId(vendorId: number): Promise { - try { - await db - .delete(vendorAdditionalInfo) - .where(eq(vendorAdditionalInfo.vendorId, vendorId)) - } catch (error) { - console.error("Error deleting additional info:", error) - throw new Error("추가정보 삭제 중 오류가 발생했습니다.") - } -} diff --git a/lib/vendor-registration-status/service.ts b/lib/vendor-registration-status/service.ts deleted file mode 100644 index 97503a13..00000000 --- a/lib/vendor-registration-status/service.ts +++ /dev/null @@ -1,260 +0,0 @@ -import { revalidateTag, unstable_cache } from "next/cache" -import { - getBusinessContactsByVendorId, - upsertBusinessContacts, - getAdditionalInfoByVendorId, - upsertAdditionalInfo, - getVendorAllAdditionalData, - deleteBusinessContactsByVendorId, - deleteAdditionalInfoByVendorId, - type VendorBusinessContact, - type VendorAdditionalInfo -} from "./repository" - -// 업무담당자 정보 조회 -export async function fetchBusinessContacts(vendorId: number) { - return unstable_cache( - async () => { - try { - const contacts = await getBusinessContactsByVendorId(vendorId) - return { - success: true, - data: contacts, - } - } catch (error) { - console.error("Error in fetchBusinessContacts:", error) - return { - success: false, - error: error instanceof Error ? error.message : "업무담당자 정보를 가져오는 중 오류가 발생했습니다.", - } - } - }, - [`business-contacts-${vendorId}`], - { - revalidate: 300, // 5분 캐시 - tags: ["business-contacts", `vendor-${vendorId}`], - } - )() -} - -// 업무담당자 정보 저장 -export async function saveBusinessContacts( - vendorId: number, - contacts: Omit[] -) { - try { - await upsertBusinessContacts(vendorId, contacts) - - // 캐시 무효화 - revalidateTag("business-contacts") - revalidateTag(`vendor-${vendorId}`) - - return { - success: true, - message: "업무담당자 정보가 저장되었습니다.", - } - } catch (error) { - console.error("Error in saveBusinessContacts:", error) - return { - success: false, - error: error instanceof Error ? error.message : "업무담당자 정보 저장 중 오류가 발생했습니다.", - } - } -} - -// 추가정보 조회 -export async function fetchAdditionalInfo(vendorId: number) { - return unstable_cache( - async () => { - try { - const additionalInfo = await getAdditionalInfoByVendorId(vendorId) - return { - success: true, - data: additionalInfo, - } - } catch (error) { - console.error("Error in fetchAdditionalInfo:", error) - return { - success: false, - error: error instanceof Error ? error.message : "추가정보를 가져오는 중 오류가 발생했습니다.", - } - } - }, - [`additional-info-${vendorId}`], - { - revalidate: 300, // 5분 캐시 - tags: ["additional-info", `vendor-${vendorId}`], - } - )() -} - -// 추가정보 저장 -export async function saveAdditionalInfo( - vendorId: number, - info: Omit -) { - try { - await upsertAdditionalInfo(vendorId, info) - - // 캐시 무효화 - revalidateTag("additional-info") - revalidateTag(`vendor-${vendorId}`) - - return { - success: true, - message: "추가정보가 저장되었습니다.", - } - } catch (error) { - console.error("Error in saveAdditionalInfo:", error) - return { - success: false, - error: error instanceof Error ? error.message : "추가정보 저장 중 오류가 발생했습니다.", - } - } -} - -// 모든 추가정보 조회 (업무담당자 + 추가정보) -export async function fetchAllAdditionalData(vendorId: number) { - return unstable_cache( - async () => { - try { - const data = await getVendorAllAdditionalData(vendorId) - return { - success: true, - data, - } - } catch (error) { - console.error("Error in fetchAllAdditionalData:", error) - return { - success: false, - error: error instanceof Error ? error.message : "벤더 추가정보를 가져오는 중 오류가 발생했습니다.", - } - } - }, - [`all-additional-data-${vendorId}`], - { - revalidate: 300, // 5분 캐시 - tags: ["business-contacts", "additional-info", `vendor-${vendorId}`], - } - )() -} - -// 업무담당자 + 추가정보 한 번에 저장 -export async function saveAllAdditionalData( - vendorId: number, - data: { - businessContacts: Omit[] - additionalInfo: Omit - } -) { - try { - // 두 작업을 순차적으로 실행 - await Promise.all([ - upsertBusinessContacts(vendorId, data.businessContacts), - upsertAdditionalInfo(vendorId, data.additionalInfo) - ]) - - // 캐시 무효화 - revalidateTag("business-contacts") - revalidateTag("additional-info") - revalidateTag(`vendor-${vendorId}`) - - return { - success: true, - message: "모든 추가정보가 저장되었습니다.", - } - } catch (error) { - console.error("Error in saveAllAdditionalData:", error) - return { - success: false, - error: error instanceof Error ? error.message : "추가정보 저장 중 오류가 발생했습니다.", - } - } -} - -// 업무담당자 정보 삭제 -export async function removeBusinessContacts(vendorId: number) { - try { - await deleteBusinessContactsByVendorId(vendorId) - - // 캐시 무효화 - revalidateTag("business-contacts") - revalidateTag(`vendor-${vendorId}`) - - return { - success: true, - message: "업무담당자 정보가 삭제되었습니다.", - } - } catch (error) { - console.error("Error in removeBusinessContacts:", error) - return { - success: false, - error: error instanceof Error ? error.message : "업무담당자 정보 삭제 중 오류가 발생했습니다.", - } - } -} - -// 추가정보 삭제 -export async function removeAdditionalInfo(vendorId: number) { - try { - await deleteAdditionalInfoByVendorId(vendorId) - - // 캐시 무효화 - revalidateTag("additional-info") - revalidateTag(`vendor-${vendorId}`) - - return { - success: true, - message: "추가정보가 삭제되었습니다.", - } - } catch (error) { - console.error("Error in removeAdditionalInfo:", error) - return { - success: false, - error: error instanceof Error ? error.message : "추가정보 삭제 중 오류가 발생했습니다.", - } - } -} - -// 입력 완성도 체크 -export async function checkAdditionalDataCompletion(vendorId: number) { - try { - const result = await fetchAllAdditionalData(vendorId) - - if (!result.success || !result.data) { - return { - success: false, - error: "추가정보를 확인할 수 없습니다.", - } - } - - const { businessContacts, additionalInfo } = result.data - - // 필수 업무담당자 5개 타입이 모두 입력되었는지 체크 - const requiredContactTypes = ["sales", "design", "delivery", "quality", "tax_invoice"] - const existingContactTypes = businessContacts.map(contact => contact.contactType) - const missingContactTypes = requiredContactTypes.filter(type => !existingContactTypes.includes(type)) - - // 업무담당자 완성도 - const businessContactsComplete = missingContactTypes.length === 0 - - // 추가정보 완성도 (선택사항이므로 존재 여부만 체크) - const additionalInfoExists = !!additionalInfo - - return { - success: true, - data: { - businessContactsComplete, - missingContactTypes, - additionalInfoExists, - totalCompletion: businessContactsComplete && additionalInfoExists - } - } - } catch (error) { - console.error("Error in checkAdditionalDataCompletion:", error) - return { - success: false, - error: error instanceof Error ? error.message : "완성도 확인 중 오류가 발생했습니다.", - } - } -} -- cgit v1.2.3