diff options
Diffstat (limited to 'lib/bidding/service.ts')
| -rw-r--r-- | lib/bidding/service.ts | 74 |
1 files changed, 45 insertions, 29 deletions
diff --git a/lib/bidding/service.ts b/lib/bidding/service.ts index cbeeb24a..68ae016e 100644 --- a/lib/bidding/service.ts +++ b/lib/bidding/service.ts @@ -3177,22 +3177,28 @@ export async function increaseRoundOrRebid(biddingId: number, userId: string | u } } - // 2. 입찰번호 파싱 및 차수 증가 - const currentBiddingNumber = existingBidding.biddingNumber - - // 현재 입찰번호에서 차수 추출 (예: E00025-02 -> 02) - const match = currentBiddingNumber.match(/-(\d+)$/) - let currentRound = match ? parseInt(match[1]) : 1 - + // 2. 입찰번호 생성 (타입에 따라 다르게 처리) let newBiddingNumber: string - if (currentRound >= 3) { - // -03 이상이면 새로운 번호 생성 + if (type === 'rebidding') { + // 재입찰: 완전히 새로운 입찰번호 생성 newBiddingNumber = await generateBiddingNumber(existingBidding.contractType, userId, tx) } else { - // -02까지는 차수만 증가 - const baseNumber = currentBiddingNumber.split('-')[0] - newBiddingNumber = `${baseNumber}-${String(currentRound + 1).padStart(2, '0')}` + // 차수증가: 기존 입찰번호에서 차수 증가 + const currentBiddingNumber = existingBidding.biddingNumber + + // 현재 입찰번호에서 차수 추출 (예: E00025-02 -> 02) + const match = currentBiddingNumber.match(/-(\d+)$/) + let currentRound = match ? parseInt(match[1]) : 1 + + if (currentRound >= 3) { + // -03 이상이면 새로운 번호 생성 + newBiddingNumber = await generateBiddingNumber(existingBidding.contractType, userId, tx) + } else { + // -02까지는 차수만 증가 + const baseNumber = currentBiddingNumber.split('-')[0] + newBiddingNumber = `${baseNumber}-${String(currentRound + 1).padStart(2, '0')}` + } } // 3. 새로운 입찰 생성 (기존 정보 복제) @@ -3200,7 +3206,7 @@ export async function increaseRoundOrRebid(biddingId: number, userId: string | u .insert(biddings) .values({ biddingNumber: newBiddingNumber, - originalBiddingNumber: null, // 원입찰번호는 단순 정보이므로 null + originalBiddingNumber: existingBidding.biddingNumber, // 원입찰번호 설정 revision: 0, biddingSourceType: existingBidding.biddingSourceType, @@ -3419,26 +3425,36 @@ export async function increaseRoundOrRebid(biddingId: number, userId: string | u }) } } - // 8. 입찰공고문 정보 복제 (있는 경우) - if (existingBidding.hasBiddingNotice) { - const [existingNotice] = await tx - .select() - .from(biddingNoticeTemplate) - .where(eq(biddingNoticeTemplate.biddingId, biddingId)) - .limit(1) - if (existingNotice) { - await tx - .insert(biddingNoticeTemplate) - .values({ - biddingId: newBidding.id, - title: existingNotice.title, - content: existingNotice.content, - }) - } + // 9. 기존 입찰 상태 변경 (타입에 따라 다르게 설정) + await tx + .update(biddings) + .set({ + status: type === 'round_increase' ? 'round_increase' : 'rebidding', + updatedBy: userName, + updatedAt: new Date(), + }) + .where(eq(biddings.id, biddingId)) + + // 10. 입찰공고문 정보 복제 (있는 경우) + const [existingNotice] = await tx + .select() + .from(biddingNoticeTemplate) + .where(eq(biddingNoticeTemplate.biddingId, biddingId)) + .limit(1) + + if (existingNotice) { + await tx + .insert(biddingNoticeTemplate) + .values({ + biddingId: newBidding.id, + title: existingNotice.title, + content: existingNotice.content, + }) } revalidatePath('/bidding') + revalidatePath(`/bidding/${biddingId}`) // 기존 입찰 페이지도 갱신 revalidatePath(`/bidding/${newBidding.id}`) return { |
