From 02b1cf005cf3e1df64183d20ba42930eb2767a9f Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 21 Aug 2025 06:57:36 +0000 Subject: (대표님, 최겸) 설계메뉴추가, 작업사항 업데이트 설계메뉴 - 문서관리 설계메뉴 - 벤더 데이터 gtc 메뉴 업데이트 정보시스템 - 메뉴리스트 및 정보 업데이트 파일 라우트 업데이트 엑셀임포트 개선 기본계약 개선 벤더 가입과정 변경 및 개선 벤더 기본정보 - pq 돌체 오류 수정 및 개선 벤더 로그인 과정 이메일 오류 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/basic-contract/service.ts | 88 +++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 29 deletions(-) (limited to 'lib/basic-contract/service.ts') diff --git a/lib/basic-contract/service.ts b/lib/basic-contract/service.ts index 03b27f96..64a50d14 100644 --- a/lib/basic-contract/service.ts +++ b/lib/basic-contract/service.ts @@ -4,13 +4,14 @@ import { revalidateTag, unstable_noStore } from "next/cache"; import db from "@/db/db"; import { getErrorMessage } from "@/lib/handle-error"; import { unstable_cache } from "@/lib/unstable-cache"; -import { asc, desc, ilike, inArray, and, gte, lte, not, or, sql, eq, isNull, ne, isNotNull, count } from "drizzle-orm"; +import { asc, desc, ilike, inArray, and, gte, lte, not, or, sql, eq, isNull, ne, isNotNull, count,like } from "drizzle-orm"; import { v4 as uuidv4 } from "uuid"; import { basicContract, BasicContractTemplate, basicContractTemplates, basicContractView, + vendorAttachments, vendors, type BasicContractTemplate as DBBasicContractTemplate, } from "@/db/schema"; @@ -195,15 +196,6 @@ export async function createBasicContractTemplate(input: CreateBasicContractTemp const [row] = await insertBasicContractTemplate(tx, { templateName: input.templateName, revision: input.revision || 1, - legalReviewRequired: input.legalReviewRequired, - shipBuildingApplicable: input.shipBuildingApplicable, - windApplicable: input.windApplicable, - pcApplicable: input.pcApplicable, - nbApplicable: input.nbApplicable, - rcApplicable: input.rcApplicable, - gyApplicable: input.gyApplicable, - sysApplicable: input.sysApplicable, - infraApplicable: input.infraApplicable, status: input.status || "ACTIVE", // 📝 null 처리 추가 @@ -675,8 +667,8 @@ export async function getBasicContractsByVendorId( input: GetBasciContractsSchema, vendorId: number ) { - return unstable_cache( - async () => { + // return unstable_cache( + // async () => { try { const offset = (input.page - 1) * input.perPage; @@ -743,13 +735,13 @@ export async function getBasicContractsByVendorId( // 에러 발생 시 디폴트 return { data: [], pageCount: 0 }; } - }, - [JSON.stringify(input), String(vendorId)], // 캐싱 키에 vendorId 추가 - { - revalidate: 3600, - tags: ["basicContractView-vendor"], // revalidateTag("basicContractView") 호출 시 무효화 - } - )(); + // }, + // [JSON.stringify(input), String(vendorId)], // 캐싱 키에 vendorId 추가 + // { + // revalidate: 3600, + // tags: ["basicContractView-vendor"], // revalidateTag("basicContractView") 호출 시 무효화 + // } + // )(); } export async function getAllTemplates(): Promise { @@ -1120,15 +1112,25 @@ export async function getALLBasicContractTemplates() { // 2) 등록된 templateName만 중복 없이 가져오기 export async function getExistingTemplateNames(): Promise { - const rows = await db - .select({ - templateName: basicContractTemplates.templateName, - }) - .from(basicContractTemplates) - .where(eq(basicContractTemplates.status,"ACTIVE")) - .groupBy(basicContractTemplates.templateName); - - return rows.map((r) => r.templateName); + try { + const templates = await db + .select({ + templateName: basicContractTemplates.templateName + }) + .from(basicContractTemplates) + .where( + and( + eq(basicContractTemplates.status, 'ACTIVE'), + // GTC가 아닌 것들만 중복 체크 (GTC는 프로젝트별로 여러 개 허용) + not(like(basicContractTemplates.templateName, '% GTC')) + ) + ); + + return templates.map(t => t.templateName); + } catch (error) { + console.error('Failed to fetch existing template names:', error); + throw new Error('기존 템플릿 이름을 가져오는데 실패했습니다.'); + } } export async function getExistingTemplateNamesById(id:number): Promise { @@ -1141,4 +1143,32 @@ export async function getExistingTemplateNamesById(id:number): Promise { .limit(1) return rows[0].templateName; -} \ No newline at end of file +} + +export async function getVendorAttachments(vendorId: number) { + try { + const attachments = await db + .select() + .from(vendorAttachments) + .where( + and( + eq(vendorAttachments.vendorId, vendorId), + eq(vendorAttachments.attachmentType, "NDA_ATTACHMENT") + ) + ); + + console.log(attachments,"attachments") + + return { + success: true, + data: attachments + }; + } catch (error) { + console.error("Error fetching vendor attachments:", error); + return { + success: false, + data: [], + error: "Failed to fetch vendor attachments" + }; + } +} -- cgit v1.2.3