From 153502b67da990c92973f1f8af416f9a81ec3abb Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Tue, 4 Nov 2025 16:28:49 +0900 Subject: (김준회) 데이터입력(EDP): 조선/해양 프로젝트 목록 필터링해 구분 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/vendor-data/services.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib/vendor-data') 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 { // 세션에서 도메인 정보 가져오기 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 -- cgit v1.2.3