summaryrefslogtreecommitdiff
path: root/lib/vendors/service.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-05-28 19:03:21 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-05-28 19:03:21 +0000
commit5036cf2908792cef45f06256e71f10920f647f49 (patch)
tree3116e7419e872d45025d1d48e6ddaffe2ba2dd38 /lib/vendors/service.ts
parent7ae037e9c2fc0be1fe68cecb461c5e1e837cb0da (diff)
(김준회) 기술영업 조선 RFQ (SHI/벤더)
Diffstat (limited to 'lib/vendors/service.ts')
-rw-r--r--lib/vendors/service.ts42
1 files changed, 42 insertions, 0 deletions
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