summaryrefslogtreecommitdiff
path: root/lib/vendor-registration-status/repository.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vendor-registration-status/repository.ts')
-rw-r--r--lib/vendor-registration-status/repository.ts165
1 files changed, 0 insertions, 165 deletions
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<VendorBusinessContact[]> {
- 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<VendorBusinessContact, "id" | "vendorId" | "createdAt" | "updatedAt">[]
-): Promise<void> {
- 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<VendorAdditionalInfo | null> {
- 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<VendorAdditionalInfo, "id" | "vendorId" | "createdAt" | "updatedAt">
-): Promise<void> {
- 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<void> {
- 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<void> {
- try {
- await db
- .delete(vendorAdditionalInfo)
- .where(eq(vendorAdditionalInfo.vendorId, vendorId))
- } catch (error) {
- console.error("Error deleting additional info:", error)
- throw new Error("추가정보 삭제 중 오류가 발생했습니다.")
- }
-}