summaryrefslogtreecommitdiff
path: root/lib/vendor-data
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-11-04 16:28:49 +0900
committerjoonhoekim <26rote@gmail.com>2025-11-04 16:28:49 +0900
commit153502b67da990c92973f1f8af416f9a81ec3abb (patch)
tree825d207df95a68113b084d8392c3cf208f6449f5 /lib/vendor-data
parent7bf90e71ee98abe2d65e18eaf20a449cd1bd097c (diff)
(김준회) 데이터입력(EDP): 조선/해양 프로젝트 목록 필터링해 구분
Diffstat (limited to 'lib/vendor-data')
-rw-r--r--lib/vendor-data/services.ts24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/vendor-data/services.ts b/lib/vendor-data/services.ts
index e8ecd01c..8c8b21d2 100644
--- a/lib/vendor-data/services.ts
+++ b/lib/vendor-data/services.ts
@@ -3,7 +3,7 @@
import db from "@/db/db"
import { items } from "@/db/schema/items"
import { projects } from "@/db/schema/projects"
-import { eq } from "drizzle-orm"
+import { eq, and } from "drizzle-orm"
import { contractItems, contracts } from "@/db/schema/contract";
import { getServerSession } from "next-auth";
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
@@ -26,7 +26,8 @@ export interface ProjectWithContracts {
}
export async function getVendorProjectsAndContracts(
- vendorId?: number
+ vendorId?: number,
+ projectType?: "ship" | "plant"
): Promise<ProjectWithContracts[]> {
// 세션에서 도메인 정보 가져오기
const session = await getServerSession(authOptions)
@@ -34,6 +35,20 @@ export async function getVendorProjectsAndContracts(
// EVCP 도메인일 때만 전체 조회
const isEvcpDomain = session?.user?.domain === "evcp"
+ // where 조건들을 배열로 관리
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const whereConditions: any[] = []
+
+ // vendorId 조건 추가
+ if (!isEvcpDomain && vendorId) {
+ whereConditions.push(eq(contracts.vendorId, vendorId))
+ }
+
+ // projectType 조건 추가
+ if (projectType) {
+ whereConditions.push(eq(projects.type, projectType))
+ }
+
const query = db
.select({
projectId: projects.id,
@@ -53,8 +68,9 @@ export async function getVendorProjectsAndContracts(
.innerJoin(contractItems, eq(contractItems.contractId, contracts.id))
.innerJoin(items, eq(contractItems.itemId, items.id))
- if (!isEvcpDomain && vendorId) {
- query.where(eq(contracts.vendorId, vendorId))
+ // 조건이 있으면 where 절 추가
+ if (whereConditions.length > 0) {
+ query.where(and(...whereConditions))
}
const rows = await query