summaryrefslogtreecommitdiff
path: root/lib/vendors/repository.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vendors/repository.ts')
-rw-r--r--lib/vendors/repository.ts34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/vendors/repository.ts b/lib/vendors/repository.ts
index ff195932..1f59aac0 100644
--- a/lib/vendors/repository.ts
+++ b/lib/vendors/repository.ts
@@ -2,7 +2,7 @@
import { and, eq, inArray, count, gt, AnyColumn, SQLWrapper, SQL} from "drizzle-orm";
import { PgTransaction } from "drizzle-orm/pg-core";
-import { VendorContact, vendorContacts, vendorItemsView, vendorPossibleItems, vendors, type Vendor } from "@/db/schema/vendors";
+import { VendorContact, vendorContacts, vendorItemsView, vendorPossibleItems, vendors, vendorsWithTypesView, type Vendor } from "@/db/schema/vendors";
import db from '@/db/db';
import { items } from "@/db/schema/items";
import { rfqs,rfqItems, rfqEvaluations, vendorResponses } from "@/db/schema/rfq";
@@ -47,8 +47,33 @@ export async function countVendors(
}
+ export async function selectVendorsWithTypes (
+ tx: PgTransaction<any, any, any>,
+ { where, orderBy, offset, limit }: SelectVendorsOptions
+) {
+ return tx
+ .select()
+ .from(vendorsWithTypesView)
+ .where(where ?? undefined)
+ .orderBy(...(orderBy ?? []))
+ .offset(offset ?? 0)
+ .limit(limit ?? 20);
+}
+
/**
- * 3) INSERT (단일 벤더 생성)
+ * 2) COUNT
+ */
+export async function countVendorsWithTypes(
+ tx: PgTransaction<any, any, any>,
+ where?: any
+ ) {
+ const res = await tx.select({ count: count() }).from(vendorsWithTypesView).where(where);
+ return res[0]?.count ?? 0;
+ }
+
+
+/**
+ * 3) INSERT (단일 협력업체 생성)
* - id/createdAt/updatedAt은 DB default 사용
* - 반환값은 "생성된 레코드" 배열 ([newVendor])
*/
@@ -60,7 +85,7 @@ export async function insertVendor(
}
/**
- * 4) UPDATE (단일 벤더)
+ * 4) UPDATE (단일 협력업체)
*/
export async function updateVendor(
tx: PgTransaction<any, any, any>,
@@ -75,7 +100,7 @@ export async function updateVendor(
}
/**
- * 5) UPDATE (복수 벤더)
+ * 5) UPDATE (복수 협력업체)
* - 여러 개의 id를 받아 일괄 업데이트
*/
export async function updateVendors(
@@ -280,3 +305,4 @@ export async function countRfqHistory(
return count;
}
+