summaryrefslogtreecommitdiff
path: root/lib/basic-contract/actions/check-gtc-comments.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-11-25 11:48:21 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-11-25 11:48:21 +0000
commit6160e8bd61360ada9e8e0574671c38292eaba9e7 (patch)
tree57857b8cd7f1b858deb68622d69feba11fda20a8 /lib/basic-contract/actions/check-gtc-comments.ts
parent6fcb8eda80c5ccac7eb985d3efb2aaafa0711988 (diff)
(임수민) 준법/gtc 코멘트 수정
Diffstat (limited to 'lib/basic-contract/actions/check-gtc-comments.ts')
-rw-r--r--lib/basic-contract/actions/check-gtc-comments.ts62
1 files changed, 10 insertions, 52 deletions
diff --git a/lib/basic-contract/actions/check-gtc-comments.ts b/lib/basic-contract/actions/check-gtc-comments.ts
index 1ce998bc..6d523cb0 100644
--- a/lib/basic-contract/actions/check-gtc-comments.ts
+++ b/lib/basic-contract/actions/check-gtc-comments.ts
@@ -4,11 +4,9 @@ import db from "@/db/db";
import { eq, and, desc, isNull, isNotNull, ne, or } from "drizzle-orm";
import {
gtcDocuments,
- gtcVendorDocuments,
- gtcVendorClauses,
- gtcNegotiationHistory,
projects,
- BasicContractView
+ BasicContractView,
+ agreementComments
} from "@/db/schema";
/**
@@ -27,7 +25,7 @@ function extractProjectCodeFromTemplateName(templateName: string): string | null
// 프로젝트 코드는 보통 첫 번째 단어
if (words.length > 1 && words[words.length - 1].toLowerCase() === 'gtc') {
- return words[words.length - 1];
+ return words[0]; // 첫 번째 단어가 프로젝트 코드
}
return null;
@@ -105,14 +103,16 @@ async function checkGTCCommentsForContract(
// gtcDocumentId가 없어도 새로운 코멘트 시스템은 작동해야 함
if (basicContractId) {
console.log(`🔍 [checkGTCCommentsForContract] basicContractId: ${basicContractId} 로 코멘트 조회`);
- const { agreementComments } = await import("@/db/schema");
+ // 기존 방식과 동일하게 빈 코멘트는 제외
const newComments = await db
.select({ id: agreementComments.id })
.from(agreementComments)
.where(
and(
eq(agreementComments.basicContractId, basicContractId),
- eq(agreementComments.isDeleted, false)
+ eq(agreementComments.isDeleted, false),
+ isNotNull(agreementComments.comment),
+ ne(agreementComments.comment, '')
)
)
.limit(1);
@@ -130,51 +130,9 @@ async function checkGTCCommentsForContract(
console.log(`⚠️ [checkGTCCommentsForContract] basicContractId ${basicContractId}: agreementComments 없음`);
}
- // GTC Document를 찾지 못한 경우 (기존 방식도 체크할 수 없음)
- if (!gtcDocumentId) {
- console.log(`⚠️ [checkGTCCommentsForContract] gtcDocumentId null - 기존 방식 체크 불가`);
- return { gtcDocumentId: null, hasComments: false };
- }
-
- // 2-2. 기존 방식: gtcDocumentId로 해당 벤더의 vendor documents 찾기
- const vendorDocuments = await db
- .select({ id: gtcVendorDocuments.id })
- .from(gtcVendorDocuments)
- .where(
- and(
- eq(gtcVendorDocuments.baseDocumentId, gtcDocumentId),
- eq(gtcVendorDocuments.vendorId, vendorId),
- eq(gtcVendorDocuments.isActive, true)
- )
- )
- .limit(1)
-
- if (vendorDocuments.length === 0) {
- return { gtcDocumentId, hasComments: false };
- }
-
- // vendor document에 연결된 clauses에서 negotiation history 확인
- const commentsExist = await db
- .select({ count: gtcNegotiationHistory.id })
- .from(gtcNegotiationHistory)
- .innerJoin(
- gtcVendorClauses,
- eq(gtcNegotiationHistory.vendorClauseId, gtcVendorClauses.id)
- )
- .where(
- and(
- eq(gtcVendorClauses.vendorDocumentId, vendorDocuments[0].id),
- eq(gtcVendorClauses.isActive, true),
- isNotNull(gtcNegotiationHistory.comment),
- ne(gtcNegotiationHistory.comment, '')
- )
- )
- .limit(1)
-
- return {
- gtcDocumentId,
- hasComments: commentsExist.length > 0
- };
+ // GTC 조항 기능은 더 이상 사용하지 않으므로, agreement_comments만 체크
+ // agreement_comments에 코멘트가 없으면 hasComments = false 반환
+ return { gtcDocumentId, hasComments: false };
} catch (error) {
console.error('Error checking GTC comments for contract:', error);