summaryrefslogtreecommitdiff
path: root/lib/bidding
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-11-26 18:09:18 +0900
committerjoonhoekim <26rote@gmail.com>2025-11-26 18:09:18 +0900
commit8547034e6d82e4d1184f35af2dbff67180d89dc8 (patch)
tree2e1835040f39adc7d0c410a108ebb558f9971a8b /lib/bidding
parent3131dce1f0c90d960f53bd384045b41023064bc4 (diff)
(김준회) dolce: 동기화 기능 추가, 로컬 다운로드, 삭제 추가, 동기화 dialog 개선 등
Diffstat (limited to 'lib/bidding')
-rw-r--r--lib/bidding/detail/service.ts34
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/bidding/detail/service.ts b/lib/bidding/detail/service.ts
index e49c0628..c9ad43ff 100644
--- a/lib/bidding/detail/service.ts
+++ b/lib/bidding/detail/service.ts
@@ -9,6 +9,7 @@ import { unstable_cache } from "@/lib/unstable-cache";
import { sendEmail } from '@/lib/mail/sendEmail'
import { saveFile } from '@/lib/file-stroage'
import { sendBiddingNoticeSms } from '@/lib/users/auth/passwordUtil'
+import { debugLog, debugError, debugSuccess } from '@/lib/debug-utils'
// userId를 user.name으로 변환하는 유틸리티 함수
async function getUserNameById(userId: string): Promise<string> {
@@ -786,6 +787,7 @@ export async function markAsDisposal(biddingId: number, userId: string) {
// 입찰 등록 ( 본입찰 초대 발송)
export async function registerBidding(biddingId: number, userId: string) {
+ debugLog('registerBidding started', { biddingId, userId })
try {
// 본입찰에서 개별적으로 추가한 업체들 조회
const selectedCompanies = await db
@@ -800,6 +802,8 @@ export async function registerBidding(biddingId: number, userId: string) {
eq(biddingCompanies.biddingId, biddingId)
)
+ debugLog('registerBidding: selectedCompanies fetched', { count: selectedCompanies.length, selectedCompanies })
+
// 입찰 정보 조회
const biddingInfo = await db
.select()
@@ -808,14 +812,18 @@ export async function registerBidding(biddingId: number, userId: string) {
.limit(1)
if (biddingInfo.length === 0) {
+ debugError('registerBidding: Bidding info not found', { biddingId })
return { success: false, error: '입찰 정보를 찾을 수 없습니다.' }
}
const bidding = biddingInfo[0]
+ debugLog('registerBidding: bidding info fetched', { bidding })
const userName = await getUserNameById(userId)
+ debugLog('registerBidding: userName fetched', { userName })
await db.transaction(async (tx) => {
+ debugLog('registerBidding: Transaction started')
// 1. 입찰 상태를 오픈으로 변경
await tx
.update(biddings)
@@ -840,9 +848,11 @@ export async function registerBidding(biddingId: number, userId: string) {
eq(biddingCompanies.companyId, company.companyId)
))
}
+ debugLog('registerBidding: Transaction completed (status updated, companies invited)')
})
// 3. 선정된 업체들에게 본입찰 초대 메일 발송
+ debugLog('registerBidding: Sending emails...')
for (const company of selectedCompanies) {
if (company.contactEmail) {
try {
@@ -864,12 +874,14 @@ export async function registerBidding(biddingId: number, userId: string) {
language: 'ko'
}
})
+ debugLog(`registerBidding: Email sent to ${company.contactEmail}`)
} catch (emailError) {
- console.error(`Failed to send bidding invitation email to ${company.contactEmail}:`, emailError)
+ debugError(`Failed to send bidding invitation email to ${company.contactEmail}:`, emailError)
}
}
}
// 4. 입찰 공고 SMS 알림 전송
+ debugLog('registerBidding: Sending SMS...')
for (const company of selectedCompanies) {
// biddingCompaniesContacts에서 모든 연락처 전화번호 조회
const contactInfos = await db
@@ -890,12 +902,12 @@ export async function registerBidding(biddingId: number, userId: string) {
try {
const smsResult = await sendBiddingNoticeSms(contactPhone, bidding.title);
if (smsResult.success) {
- console.log(`입찰 공고 SMS 전송 성공: ${contactPhone} - ${bidding.title}`);
+ debugLog(`입찰 공고 SMS 전송 성공: ${contactPhone} - ${bidding.title}`);
} else {
- console.error(`입찰 공고 SMS 전송 실패: ${contactPhone} - ${smsResult.error}`);
+ debugError(`입찰 공고 SMS 전송 실패: ${contactPhone} - ${smsResult.error}`);
}
} catch (smsError) {
- console.error(`Failed to send bidding notice SMS to ${contactPhone}:`, smsError)
+ debugError(`Failed to send bidding notice SMS to ${contactPhone}:`, smsError)
}
}
}
@@ -908,21 +920,25 @@ export async function registerBidding(biddingId: number, userId: string) {
revalidateTag('pr-items')
revalidatePath(`/evcp/bid/${biddingId}`)
+ debugSuccess(`registerBidding: Success. Invited ${selectedCompanies.length} companies.`)
return {
success: true,
message: `입찰이 성공적으로 등록되었습니다. ${selectedCompanies.length}개 업체에 초대 메일을 발송했습니다.`
}
} catch (error) {
- console.error('Failed to register bidding:', error)
- return { success: false, error: '입찰 등록에 실패했습니다.' }
+ debugError('Failed to register bidding:', error)
+ return { success: false, error: `입찰 등록에 실패했습니다. ${error}` }
}
}
// 업체 선정 사유 업데이트
export async function updateVendorSelectionReason(biddingId: number, selectedCompanyId: number, selectionReason: string, userId: string) {
+ debugLog('updateVendorSelectionReason started', { biddingId, selectedCompanyId, selectionReason, userId })
try {
const userName = await getUserNameById(userId)
+ debugLog('updateVendorSelectionReason: userName fetched', { userName })
+
// vendorSelectionResults 테이블에 삽입 또는 업데이트
await db
.insert(vendorSelectionResults)
@@ -946,13 +962,17 @@ export async function updateVendorSelectionReason(biddingId: number, selectedCom
}
})
+ debugLog('updateVendorSelectionReason: DB updated')
+
// 캐시 무효화
revalidateTag(`bidding-${biddingId}`)
revalidateTag('quotation-vendors')
revalidatePath(`/evcp/bid/${biddingId}`)
+
+ debugSuccess('updateVendorSelectionReason: Success')
return { success: true, message: '업체 선정 사유가 성공적으로 업데이트되었습니다.' }
} catch (error) {
- console.error('Failed to update vendor selection reason:', error)
+ debugError('Failed to update vendor selection reason:', error)
return { success: false, error: '업체 선정 사유 업데이트에 실패했습니다.' }
}
}