summaryrefslogtreecommitdiff
path: root/lib/bidding/pre-quote/service.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-09-11 11:21:35 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-09-11 11:21:35 +0000
commit47e527f5f763658600696ee58451fb666e692f5a (patch)
tree67f159fd0cbad5e0553c7958caa3075127121e76 /lib/bidding/pre-quote/service.ts
parentee77f36b1ceece1236d45fba102c3ea410acebc1 (diff)
(최겸) 구매 입찰 세부기능 수정
Diffstat (limited to 'lib/bidding/pre-quote/service.ts')
-rw-r--r--lib/bidding/pre-quote/service.ts48
1 files changed, 37 insertions, 11 deletions
diff --git a/lib/bidding/pre-quote/service.ts b/lib/bidding/pre-quote/service.ts
index 3f1b916c..e1df986e 100644
--- a/lib/bidding/pre-quote/service.ts
+++ b/lib/bidding/pre-quote/service.ts
@@ -3,10 +3,28 @@
import db from '@/db/db'
import { biddingCompanies, companyConditionResponses, biddings, prItemsForBidding, biddingDocuments, companyPrItemBids, priceAdjustmentForms } from '@/db/schema/bidding'
import { vendors } from '@/db/schema/vendors'
+import { users } from '@/db/schema'
import { sendEmail } from '@/lib/mail/sendEmail'
import { eq, inArray, and } from 'drizzle-orm'
import { saveFile } from '@/lib/file-stroage'
import { downloadFile } from '@/lib/file-download'
+import { revalidateTag, revalidatePath } from 'next/cache'
+
+// userId를 user.name으로 변환하는 유틸리티 함수
+async function getUserNameById(userId: string): Promise<string> {
+ try {
+ const user = await db
+ .select({ name: users.name })
+ .from(users)
+ .where(eq(users.id, parseInt(userId)))
+ .limit(1)
+
+ return user[0]?.name || userId // user.name이 없으면 userId를 그대로 반환
+ } catch (error) {
+ console.error('Failed to get user name:', error)
+ return userId // 에러 시 userId를 그대로 반환
+ }
+}
interface CreateBiddingCompanyInput {
biddingId: number
@@ -130,6 +148,13 @@ export async function updateBiddingCompany(id: number, input: UpdateBiddingCompa
// 본입찰 등록 상태 업데이트 (복수 업체 선택 가능)
export async function updatePreQuoteSelection(companyIds: number[], isSelected: boolean, userId: string) {
try {
+ // 업체들의 입찰 ID 조회 (캐시 무효화를 위해)
+ const companies = await db
+ .select({ biddingId: biddingCompanies.biddingId })
+ .from(biddingCompanies)
+ .where(inArray(biddingCompanies.id, companyIds))
+ .limit(1)
+
await db.update(biddingCompanies)
.set({
isPreQuoteSelected: isSelected,
@@ -138,6 +163,16 @@ export async function updatePreQuoteSelection(companyIds: number[], isSelected:
})
.where(inArray(biddingCompanies.id, companyIds))
+ // 캐시 무효화
+ if (companies.length > 0) {
+ const biddingId = companies[0].biddingId
+ revalidateTag(`bidding-${biddingId}`)
+ revalidateTag('bidding-detail')
+ revalidateTag('quotation-vendors')
+ revalidateTag('quotation-details')
+ revalidatePath(`/evcp/bid/${biddingId}`)
+ }
+
const message = isSelected
? `${companyIds.length}개 업체가 본입찰 대상으로 선정되었습니다.`
: `${companyIds.length}개 업체의 본입찰 선정이 취소되었습니다.`
@@ -913,6 +948,7 @@ export async function uploadPreQuoteDocument(
userId: string
) {
try {
+ const userName = await getUserNameById(userId)
// 파일 저장
const saveResult = await saveFile({
file,
@@ -943,7 +979,7 @@ export async function uploadPreQuoteDocument(
description: '협력업체 제출 견적서',
isPublic: false,
isRequired: false,
- uploadedBy: userId,
+ uploadedBy: userName,
uploadedAt: new Date()
})
.returning()
@@ -1107,21 +1143,11 @@ export async function deletePreQuoteDocument(
const doc = document[0]
- // 권한 확인 (업로드한 사용자만 삭제 가능)
- if (doc.uploadedBy !== userId) {
- return {
- success: false,
- error: '삭제 권한이 없습니다.'
- }
- }
-
// 데이터베이스에서 문서 정보 삭제
await db
.delete(biddingDocuments)
.where(eq(biddingDocuments.id, documentId))
- // TODO: 실제 파일도 삭제하는 로직 추가 (필요시)
-
return {
success: true,
message: '문서가 성공적으로 삭제되었습니다.'