diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-01 13:52:21 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-01 13:52:21 +0000 |
| commit | bac0228d21b7195065e9cddcc327ae33659c7bcc (patch) | |
| tree | 8f3016ae4533c8706d0c00a605d9b1d41968c2bc /lib/vendors/repository.ts | |
| parent | 2fdce8d7a57c792bba0ac36fa554dca9c9cc31e3 (diff) | |
(대표님) 20250601까지 작업사항
Diffstat (limited to 'lib/vendors/repository.ts')
| -rw-r--r-- | lib/vendors/repository.ts | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/lib/vendors/repository.ts b/lib/vendors/repository.ts index 1f59aac0..04d6322a 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, vendorsWithTypesView, type Vendor } from "@/db/schema/vendors"; +import { VendorContact, vendorContacts, vendorItemsView, vendorMaterialsView, 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"; @@ -225,6 +225,44 @@ export async function countVendorItems( return res[0]?.count ?? 0; } +export async function selectVendorMaterials( + tx: PgTransaction<any, any, any>, + params: { + where?: any; // drizzle-orm의 조건식 (and, eq...) 등 + orderBy?: (ReturnType<typeof asc> | ReturnType<typeof desc>)[]; + offset?: number; + limit?: number; + } +) { + const { where, orderBy, offset = 0, limit = 10 } = params; + + return tx + .select({ + // vendor_possible_items cols + vendorItemId: vendorMaterialsView.vendorItemId, + vendorId: vendorMaterialsView.vendorId, + itemCode: vendorMaterialsView.itemCode, + createdAt: vendorMaterialsView.createdAt, + updatedAt: vendorMaterialsView.updatedAt, + itemName: vendorMaterialsView.itemName, + description: vendorMaterialsView.description, + }) + .from(vendorMaterialsView) + .where(where ?? undefined) + .orderBy(...(orderBy ?? [])) + .offset(offset) + .limit(limit); +} + +export async function countVendorMaterials( + tx: PgTransaction<any, any, any>, + where?: any +) { + const res = await tx.select({ count: count() }).from(vendorMaterialsView).where(where); + return res[0]?.count ?? 0; +} + + export async function insertVendorItem( tx: PgTransaction<any, any, any>, data: NewVendorItem // DB와 동일한 insert 가능한 타입 @@ -236,6 +274,17 @@ export async function insertVendorItem( .returning({ id: vendorPossibleItems.id, createdAt: vendorPossibleItems.createdAt }); } +export async function insertVendorMaterial( + tx: PgTransaction<any, any, any>, + data: NewVendorItem // DB와 동일한 insert 가능한 타입 +) { + // returning() 사용 시 배열로 돌아오므로 [0]만 리턴 + return tx + .insert(vendorPossibleMateirals) + .values(data) + .returning({ id: vendorPossibleMateirals.id, createdAt: vendorPossibleMateirals.createdAt }); +} + export async function selectRfqHistory( tx: PgTransaction<any, any, any>, { where, orderBy, offset, limit }: SelectVendorsOptions |
