summaryrefslogtreecommitdiff
path: root/db/schema/techVendors.ts
diff options
context:
space:
mode:
Diffstat (limited to 'db/schema/techVendors.ts')
-rw-r--r--db/schema/techVendors.ts105
1 files changed, 10 insertions, 95 deletions
diff --git a/db/schema/techVendors.ts b/db/schema/techVendors.ts
index e34d3e60..582ff724 100644
--- a/db/schema/techVendors.ts
+++ b/db/schema/techVendors.ts
@@ -1,6 +1,8 @@
import { pgTable, serial, varchar, text, timestamp, integer, boolean, pgView } from "drizzle-orm/pg-core";
-import { sql, eq } from "drizzle-orm";
-import { items } from "./items";
+import { sql } from "drizzle-orm";
+import { itemShipbuilding } from "./items";
+import { itemOffshoreTop } from "./items";
+import { itemOffshoreHull } from "./items";
// 벤더 타입 enum 정의
export const VENDOR_TYPES = ["조선", "해양TOP", "해양HULL"] as const;
@@ -53,6 +55,7 @@ export const techVendorContacts = pgTable("tech_vendor_contacts", {
vendorId: integer("vendor_id").notNull().references(() => techVendors.id),
contactName: varchar("contact_name", { length: 255 }).notNull(),
contactPosition: varchar("contact_position", { length: 100 }),
+ contactTitle: varchar("contact_title", { length: 100 }),
contactEmail: varchar("contact_email", { length: 255 }).notNull(),
contactPhone: varchar("contact_phone", { length: 50 }),
contactCountry: varchar("contact_country", { length: 100 }),
@@ -65,16 +68,9 @@ export const techVendorPossibleItems = pgTable("tech_vendor_possible_items", {
// 벤더 정보
vendorId: integer("vendor_id").notNull().references(() => techVendors.id),
- vendorCode: varchar("vendor_code", { length: 100 }), // 검색/필터용 중복 저장
- vendorEmail: varchar("vendor_email", { length: 255 }), // 검색/필터용 중복 저장
-
- // 아이템 정보 (itemCode도 nullable로 변경 - 해양 HULL 등에서 없을 수 있음)
- itemCode: varchar("item_code", { length: 100 }).notNull(),
- workType: varchar("work_type", { length: 100 }), // 공종 (nullable)
- shipTypes: varchar("ship_types", { length: 255 }), // 선종 (nullable)
- itemList: varchar("item_list", { length: 500 }), // 아이템 리스트 (nullable)
- subItemList: varchar("sub_item_list", { length: 500 }), // 서브 아이템 리스트 (nullable)
-
+ shipbuildingItemId: integer("shipbuilding_item_id").references(() => itemShipbuilding.id),
+ offshoreTopItemId: integer("offshore_top_item_id").references(() => itemOffshoreTop.id),
+ offshoreHullItemId: integer("offshore_hull_item_id").references(() => itemOffshoreHull.id),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
@@ -90,19 +86,6 @@ export const techVendorAttachments = pgTable("tech_vendor_attachments", {
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
-// 뷰: 벤더 + 아이템 정보 조인
-export const techVendorItemsView = pgView("tech_vendor_items_view").as((qb) => {
- return qb
- .select({
- vendorItemId: techVendorPossibleItems.id,
- vendorId: techVendorPossibleItems.vendorId,
- itemCode: items.itemCode,
- createdAt: techVendorPossibleItems.createdAt,
- updatedAt: techVendorPossibleItems.updatedAt,
- })
- .from(techVendorPossibleItems)
- .leftJoin(items, eq(techVendorPossibleItems.itemCode, items.itemCode));
-});
// 벤더 상세 정보 뷰 (연락처 정보 포함)
export const techVendorDetailView = pgView("tech_vendor_detail_view").as((qb) => {
@@ -140,6 +123,7 @@ export const techVendorDetailView = pgView("tech_vendor_detail_view").as((qb) =>
'id', c.id,
'contactName', c.contact_name,
'contactPosition', c.contact_position,
+ 'contactTitle', c.contact_title,
'contactEmail', c.contact_email,
'contactPhone', c.contact_phone,
'isPrimary', c.is_primary
@@ -147,7 +131,7 @@ export const techVendorDetailView = pgView("tech_vendor_detail_view").as((qb) =>
),
'[]'::json
)
- FROM vendor_contacts c
+ FROM tech_vendor_contacts c
WHERE c.vendor_id = tech_vendors.id)
`.as("contacts"),
// 첨부파일 정보 (수정된 버전)
@@ -181,21 +165,6 @@ export const techVendorDetailView = pgView("tech_vendor_detail_view").as((qb) =>
WHERE c.vendor_id = tech_vendors.id)
`.as("contact_count"),
- // 가능 아이템 목록 JSON
- possibleItems: sql<string>`
- (SELECT COALESCE(
- json_agg(
- json_build_object(
- 'itemCode', i.item_code
- )
- ),
- '[]'::json
- )
- FROM tech_vendor_possible_items i
- LEFT JOIN items it ON i.item_code = it.item_code
- WHERE i.vendor_id = tech_vendors.id)
- `.as("possible_items"),
-
// 아이템 수
itemCount: sql<number>`
(SELECT COUNT(*)
@@ -207,65 +176,11 @@ export const techVendorDetailView = pgView("tech_vendor_detail_view").as((qb) =>
});
-export const techVendorCandidates = pgTable("tech_vendor_candidates", {
- id: serial("id").primaryKey(),
- companyName: varchar("company_name", { length: 255 }).notNull(),
- contactEmail: varchar("contact_email", { length: 255 }),
- contactPhone: varchar("contact_phone", { length: 50 }),
- taxId: varchar("tax_id", { length: 100 }),
- country: varchar("country", { length: 100 }),
- status: varchar("status", {
- length: 30,
- enum: [
- "COLLECTED", // 단순 데이터 수집 완료
- "INVITED", // 초청 메일 발송
- "DISCARDED", // 불필요, 검토 후 배제됨
- ],
- })
- .notNull()
- .default("COLLECTED"),
- remark: text("remark"),
- vendorId: integer("vendor_id")
- .references(() => techVendors.id, { onDelete: "cascade" }),
- createdAt: timestamp("created_at").defaultNow().notNull(),
- updatedAt: timestamp("updated_at").defaultNow().notNull(),
-});
-export const techVendorCandidatesWithVendorInfo = pgView("tech_vendor_candidates_with_vendor_info").as((qb) => {
- return qb
- .select({
- // ----------------------------------------
- // 1) techVendorCandidates 기본 필드
- id: techVendorCandidates.id,
- companyName: techVendorCandidates.companyName,
- contactEmail: techVendorCandidates.contactEmail,
- contactPhone: techVendorCandidates.contactPhone,
- taxId: techVendorCandidates.taxId,
- country: techVendorCandidates.country,
- status: techVendorCandidates.status,
- remark: techVendorCandidates.remark,
- createdAt: techVendorCandidates.createdAt,
- updatedAt: techVendorCandidates.updatedAt,
-
- // ----------------------------------------
- // 2) techVendors 조인해서 가져올 필드
- vendorName: techVendors.vendorName,
- vendorCode: techVendors.vendorCode,
- vendorCreatedAt: sql<Date>`${techVendors.createdAt}`.as("vendor_created_at"),
-
- })
- .from(techVendorCandidates)
- .leftJoin(techVendors, eq(techVendorCandidates.vendorId, techVendors.id));
-});
-
-export type TechVendorCandidatesWithVendorInfo = typeof techVendorCandidatesWithVendorInfo.$inferSelect;
-
export type TechVendor = typeof techVendors.$inferSelect
export type TechVendorContact = typeof techVendorContacts.$inferSelect
export type TechVendorItem = typeof techVendorPossibleItems.$inferSelect
export type TechVendorAttach = typeof techVendorAttachments.$inferSelect
-export type TechVendorItemsView = typeof techVendorItemsView.$inferSelect
export type TechVendorDetailView = typeof techVendorDetailView.$inferSelect
-export type TechVendorCandidate = typeof techVendorCandidates.$inferSelect
export type TechVendorWithAttachments = TechVendor & {
hasAttachments?: boolean;
attachmentsList?: TechVendorAttach[];