From 7548e2ad6948f1c6aa102fcac408bc6c9c0f9796 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 27 Aug 2025 12:06:26 +0000 Subject: (대표님, 최겸) 기본계약, 입찰, 파일라우트, 계약서명라우트, 인포메이션, 메뉴설정, PQ(메일템플릿 관련) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/basic-contract/repository.ts | 66 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'lib/basic-contract/repository.ts') diff --git a/lib/basic-contract/repository.ts b/lib/basic-contract/repository.ts index aab70106..237402d0 100644 --- a/lib/basic-contract/repository.ts +++ b/lib/basic-contract/repository.ts @@ -1,7 +1,7 @@ "use server"; import { asc, count,inArray ,eq} from "drizzle-orm"; -import { basicContractTemplates, basicContractView, type BasicContractTemplate } from "@/db/schema"; +import { basicContractTemplates, basicContractView,basicContractTemplateStatsView, type BasicContractTemplate } from "@/db/schema"; import { PgTransaction } from "drizzle-orm/pg-core"; import db from "@/db/db"; @@ -37,6 +37,47 @@ export async function selectBasicContracts( ) { const { where, orderBy, offset, limit } = options; + return tx + .select() + .from(basicContractTemplateStatsView) + .where(where || undefined) + .orderBy(...(orderBy || [asc(basicContractTemplateStatsView.lastActivityDate)])) + .offset(offset || 0) + .limit(limit || 50); +} + +export async function selectBasicContractsVendor( + tx: PgTransaction, + options: { + where?: any; + orderBy?: any[]; + offset?: number; + limit?: number; + } +) { + const { where, orderBy, offset, limit } = options; + + return tx + .select() + .from(basicContractView) + .where(where || undefined) + .orderBy(...(orderBy || [asc(basicContractView.createdAt)])) + .offset(offset || 0) + .limit(limit || 50); +} + + +export async function selectBasicContractsById( + tx: PgTransaction, + options: { + where?: any; + orderBy?: any[]; + offset?: number; + limit?: number; + } +) { + const { where, orderBy, offset, limit } = options; + return tx .select() .from(basicContractView) @@ -62,6 +103,18 @@ export async function countBasicContractTemplates( export async function countBasicContracts( tx: PgTransaction, where?: any +) { + const result = await tx + .select({ count: count() }) + .from(basicContractTemplateStatsView) + .where(where || undefined); + + return result[0]?.count || 0; +} + +export async function countBasicContractsVendor( + tx: PgTransaction, + where?: any ) { const result = await tx .select({ count: count() }) @@ -71,6 +124,17 @@ export async function countBasicContracts( return result[0]?.count || 0; } +export async function countBasicContractsById( + tx: PgTransaction, + where?: any +) { + const result = await tx + .select({ count: count() }) + .from(basicContractView) + .where(where || undefined); + + return result[0]?.count || 0; +} // 템플릿 생성 export async function insertBasicContractTemplate( -- cgit v1.2.3