summaryrefslogtreecommitdiff
path: root/lib/bidding/service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bidding/service.ts')
-rw-r--r--lib/bidding/service.ts84
1 files changed, 80 insertions, 4 deletions
diff --git a/lib/bidding/service.ts b/lib/bidding/service.ts
index 14bed105..2474d464 100644
--- a/lib/bidding/service.ts
+++ b/lib/bidding/service.ts
@@ -865,8 +865,12 @@ export interface CreateBiddingInput extends CreateBiddingSchema {
meetingFiles: File[]
} | null
+ // 첨부파일들 (선택사항)
+ attachments?: File[]
+ vendorAttachments?: File[]
+
// noticeType 필드 명시적 추가 (CreateBiddingSchema에 포함되어 있지만 타입 추론 문제 해결)
- noticeType?: 'standard' | 'facility' | 'unit_price'
+ noticeType: 'standard' | 'facility' | 'unit_price'
// PR 아이템들 (선택사항)
prItems?: Array<{
@@ -1420,10 +1424,80 @@ export async function createBidding(input: CreateBiddingInput, userId: string) {
}
}
}
-
+
+ // 4. 첨부파일들 저장 (있는 경우)
+ if (input.attachments && input.attachments.length > 0) {
+ for (const file of input.attachments) {
+ try {
+ const saveResult = await saveFile({
+ file,
+ directory: `biddings/${biddingId}/attachments/shi`,
+ originalName: file.name,
+ userId
+ })
+
+ if (saveResult.success) {
+ await tx.insert(biddingDocuments).values({
+ biddingId,
+ documentType: 'evaluation_doc', // SHI용 문서 타입
+ fileName: saveResult.fileName!,
+ originalFileName: saveResult.originalName!,
+ fileSize: saveResult.fileSize!,
+ mimeType: file.type,
+ filePath: saveResult.publicPath!,
+ title: `SHI용 첨부파일 - ${file.name}`,
+ description: 'SHI용 첨부파일',
+ isPublic: true, // 발주처 문서이므로 공개
+ isRequired: false,
+ uploadedBy: userName,
+ })
+ } else {
+ console.error(`Failed to save SHI attachment file: ${file.name}`, saveResult.error)
+ }
+ } catch (error) {
+ console.error(`Error saving SHI attachment file: ${file.name}`, error)
+ }
+ }
+ }
+
+ // Vendor 첨부파일들 저장 (있는 경우)
+ if (input.vendorAttachments && input.vendorAttachments.length > 0) {
+ for (const file of input.vendorAttachments) {
+ try {
+ const saveResult = await saveFile({
+ file,
+ directory: `biddings/${biddingId}/attachments/vendor`,
+ originalName: file.name,
+ userId
+ })
+
+ if (saveResult.success) {
+ await tx.insert(biddingDocuments).values({
+ biddingId,
+ documentType: 'company_proposal', // 협력업체용 문서 타입
+ fileName: saveResult.fileName!,
+ originalFileName: saveResult.originalName!,
+ fileSize: saveResult.fileSize!,
+ mimeType: file.type,
+ filePath: saveResult.publicPath!,
+ title: `협력업체용 첨부파일 - ${file.name}`,
+ description: '협력업체용 첨부파일',
+ isPublic: true, // 발주처 문서이므로 공개
+ isRequired: false,
+ uploadedBy: userName,
+ })
+ } else {
+ console.error(`Failed to save vendor attachment file: ${file.name}`, saveResult.error)
+ }
+ } catch (error) {
+ console.error(`Error saving vendor attachment file: ${file.name}`, error)
+ }
+ }
+ }
+
// 캐시 무효화
revalidatePath('/evcp/bid')
-
+
return {
success: true,
message: '입찰이 성공적으로 생성되었습니다.',
@@ -3200,13 +3274,15 @@ export async function increaseRoundOrRebid(biddingId: number, userId: string | u
newBiddingNumber = `${baseNumber}-${String(currentRound + 1).padStart(2, '0')}`
}
}
+ //원입찰번호는 -0n 제외하고 저장
+ const originalBiddingNumber = existingBidding.biddingNumber.split('-')[0]
// 3. 새로운 입찰 생성 (기존 정보 복제)
const [newBidding] = await tx
.insert(biddings)
.values({
biddingNumber: newBiddingNumber,
- originalBiddingNumber: existingBidding.biddingNumber, // 원입찰번호 설정
+ originalBiddingNumber: originalBiddingNumber, // 원입찰번호 설정
revision: 0,
biddingSourceType: existingBidding.biddingSourceType,