From 5036cf2908792cef45f06256e71f10920f647f49 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 28 May 2025 19:03:21 +0000 Subject: (김준회) 기술영업 조선 RFQ (SHI/벤더) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/vendors/service.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'lib/vendors/service.ts') diff --git a/lib/vendors/service.ts b/lib/vendors/service.ts index c9ee55be..16f57b57 100644 --- a/lib/vendors/service.ts +++ b/lib/vendors/service.ts @@ -2131,4 +2131,46 @@ export async function exportVendorDetails(vendorIds: number[]) { console.error("Failed to export vendor details:", error); return []; } +} + +/** + * 벤더 검색 (검색어 기반, 최대 100개) + * RFQ 벤더 추가 시 사용 + */ +export async function searchVendors(searchTerm: string = "", limit: number = 100) { + try { + let whereCondition; + + if (searchTerm.trim()) { + const s = `%${searchTerm.trim()}%`; + whereCondition = or( + ilike(vendorsWithTypesView.vendorName, s), + ilike(vendorsWithTypesView.vendorCode, s) + ); + } + + const vendors = await db + .select({ + id: vendorsWithTypesView.id, + vendorName: vendorsWithTypesView.vendorName, + vendorCode: vendorsWithTypesView.vendorCode, + status: vendorsWithTypesView.status, + country: vendorsWithTypesView.country, + }) + .from(vendorsWithTypesView) + .where( + and( + whereCondition, + // ACTIVE 상태인 벤더만 검색 + // eq(vendorsWithTypesView.status, "ACTIVE"), + ) + ) + .orderBy(asc(vendorsWithTypesView.vendorName)) + .limit(limit); + + return vendors; + } catch (error) { + console.error("벤더 검색 오류:", error); + return []; + } } \ No newline at end of file -- cgit v1.2.3