summaryrefslogtreecommitdiff
path: root/lib/pq/helper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pq/helper.ts')
-rw-r--r--lib/pq/helper.ts96
1 files changed, 96 insertions, 0 deletions
diff --git a/lib/pq/helper.ts b/lib/pq/helper.ts
new file mode 100644
index 00000000..16aed0e4
--- /dev/null
+++ b/lib/pq/helper.ts
@@ -0,0 +1,96 @@
+import {
+ vendorPQSubmissions,
+ vendors,
+ projects,
+ users,
+ vendorInvestigations
+} from "@/db/schema"
+import { CustomColumnMapping } from "../filter-columns"
+
+/**
+ * Helper function to create custom column mapping for PQ submissions
+ */
+export function createPQFilterMapping(): CustomColumnMapping {
+ return {
+ // PQ 제출 관련
+ pqNumber: { table: vendorPQSubmissions, column: "pqNumber" },
+ status: { table: vendorPQSubmissions, column: "status" },
+ type: { table: vendorPQSubmissions, column: "type" },
+ createdAt: { table: vendorPQSubmissions, column: "createdAt" },
+ updatedAt: { table: vendorPQSubmissions, column: "updatedAt" },
+ submittedAt: { table: vendorPQSubmissions, column: "submittedAt" },
+ approvedAt: { table: vendorPQSubmissions, column: "approvedAt" },
+ rejectedAt: { table: vendorPQSubmissions, column: "rejectedAt" },
+
+ // 협력업체 관련
+ vendorName: { table: vendors, column: "vendorName" },
+ vendorCode: { table: vendors, column: "vendorCode" },
+ taxId: { table: vendors, column: "taxId" },
+ vendorStatus: { table: vendors, column: "status" },
+
+ // 프로젝트 관련
+ projectName: { table: projects, column: "name" },
+ projectCode: { table: projects, column: "code" },
+
+ // 요청자 관련
+ requesterName: { table: users, column: "name" },
+ requesterEmail: { table: users, column: "email" },
+
+ // 실사 관련
+ evaluationResult: { table: vendorInvestigations, column: "evaluationResult" },
+ evaluationType: { table: vendorInvestigations, column: "evaluationType" },
+ investigationStatus: { table: vendorInvestigations, column: "investigationStatus" },
+ investigationAddress: { table: vendorInvestigations, column: "investigationAddress" },
+ qmManagerId: { table: vendorInvestigations, column: "qmManagerId" },
+ }
+}
+
+/**
+ * PQ 관련 조인 테이블들
+ */
+export function getPQJoinedTables() {
+ return {
+ vendors,
+ projects,
+ users,
+ vendorInvestigations,
+ }
+}
+
+/**
+ * 직접 컬럼 참조 방식의 매핑 (더 타입 안전)
+ */
+export function createPQDirectColumnMapping(): CustomColumnMapping {
+ return {
+ // PQ 제출 관련 - 직접 컬럼 참조
+ pqNumber: vendorPQSubmissions.pqNumber,
+ status: vendorPQSubmissions.status,
+ type: vendorPQSubmissions.type,
+ createdAt: vendorPQSubmissions.createdAt,
+ updatedAt: vendorPQSubmissions.updatedAt,
+ submittedAt: vendorPQSubmissions.submittedAt,
+ approvedAt: vendorPQSubmissions.approvedAt,
+ rejectedAt: vendorPQSubmissions.rejectedAt,
+
+ // 협력업체 관련
+ vendorName: vendors.vendorName,
+ vendorCode: vendors.vendorCode,
+ taxId: vendors.taxId,
+ vendorStatus: vendors.status,
+
+ // 프로젝트 관련
+ projectName: projects.name,
+ projectCode: projects.code,
+
+ // 요청자 관련
+ requesterName: users.name,
+ requesterEmail: users.email,
+
+ // 실사 관련
+ evaluationResult: vendorInvestigations.evaluationResult,
+ evaluationType: vendorInvestigations.evaluationType,
+ investigationStatus: vendorInvestigations.investigationStatus,
+ investigationAddress: vendorInvestigations.investigationAddress,
+ qmManagerId: vendorInvestigations.qmManagerId,
+ }
+} \ No newline at end of file