diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-28 11:44:16 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-28 11:44:16 +0000 |
| commit | c228a89c2834ee63b209bad608837c39643f350e (patch) | |
| tree | 39c9a121b556af872072dd80750dedf2d2d62335 /lib/gtc-contract/service.ts | |
| parent | 50ae0b8f02c034e60d4cbb504620dfa1575a836f (diff) | |
(대표님) 의존성 docx 추가, basicContract API, gtc(계약일반조건), 벤더평가 esg 평가데이터 내보내기 개선, S-EDP 피드백 대응(CLS_ID, ITEM NO 등)
Diffstat (limited to 'lib/gtc-contract/service.ts')
| -rw-r--r-- | lib/gtc-contract/service.ts | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/lib/gtc-contract/service.ts b/lib/gtc-contract/service.ts index 23cdd422..308c52bf 100644 --- a/lib/gtc-contract/service.ts +++ b/lib/gtc-contract/service.ts @@ -1,7 +1,7 @@ 'use server' -import { unstable_cache } from "next/cache" -import { and, desc, asc, eq, or, ilike, count, max } from "drizzle-orm" +import { revalidateTag, unstable_cache } from "next/cache" +import { and, desc, asc, eq, or, ilike, count, max , inArray} from "drizzle-orm" import db from "@/db/db" import { gtcDocuments, gtcDocumentsView, type GtcDocument, type GtcDocumentWithRelations } from "@/db/schema/gtc" import { projects } from "@/db/schema/projects" @@ -164,6 +164,8 @@ export async function createGtcDocument( }) .returning() + revalidateTag("gtc-documents") + return newDocument } @@ -174,6 +176,9 @@ export async function updateGtcDocument( id: number, data: UpdateGtcDocumentSchema & { updatedById: number } ): Promise<GtcDocument | null> { + + console.log(data, "data") + const [updatedDocument] = await db .update(gtcDocuments) .set({ @@ -183,6 +188,8 @@ export async function updateGtcDocument( .where(eq(gtcDocuments.id, id)) .returning() + revalidateTag("gtc-documents") + return updatedDocument || null } @@ -241,33 +248,6 @@ export async function deleteGtcDocument( return !!updated } -/** - * 프로젝트별 GTC 문서 목록 조회 - */ -export async function getGtcDocumentsByProject(projectId: number): Promise<GtcDocumentWithRelations[]> { - return await selectGtcDocumentsWithRelations() - .where( - and( - eq(gtcDocuments.projectId, projectId), - eq(gtcDocuments.isActive, true) - ) - ) - .orderBy(desc(gtcDocuments.revision)) -} - -/** - * 표준 GTC 문서 목록 조회 - */ -export async function getStandardGtcDocuments(): Promise<GtcDocumentWithRelations[]> { - return await selectGtcDocumentsWithRelations() - .where( - and( - eq(gtcDocuments.type, "standard"), - eq(gtcDocuments.isActive, true) - ) - ) - .orderBy(desc(gtcDocuments.revision)) -} // 타입 정의 export type ProjectForFilter = { @@ -323,4 +303,31 @@ export async function getUsersForFilter(): Promise<UserForFilter[]> { .from(users) .where(eq(users.isActive, true)) // 활성 사용자만 .orderBy(users.name) +} + +/** + * GTC 문서 단일 조회 + */ +export async function getGtcDocumentById(id: number) { + return unstable_cache( + async () => { + try { + const [document] = await db + .select() + .from(gtcDocumentsView) + .where(eq(gtcDocumentsView.id, id)) + .limit(1) + + return document || null + } catch (err) { + console.error("Error fetching GTC document by ID:", err) + return null + } + }, + [`gtc-document-${id}`], + { + revalidate: 3600, + tags: [`gtc-document-${id}`, "gtc-documents"], + } + )() }
\ No newline at end of file |
