diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-28 02:13:30 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-28 02:13:30 +0000 |
| commit | ef4c533ebacc2cdc97e518f30e9a9350004fcdfb (patch) | |
| tree | 345251a3ed0f4429716fa5edaa31024d8f4cb560 /lib/vendors/repository.ts | |
| parent | 9ceed79cf32c896f8a998399bf1b296506b2cd4a (diff) | |
~20250428 작업사항
Diffstat (limited to 'lib/vendors/repository.ts')
| -rw-r--r-- | lib/vendors/repository.ts | 34 |
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; } + |
