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.ts41
1 files changed, 35 insertions, 6 deletions
diff --git a/lib/bidding/service.ts b/lib/bidding/service.ts
index c4904219..7d314841 100644
--- a/lib/bidding/service.ts
+++ b/lib/bidding/service.ts
@@ -10,7 +10,8 @@ import {
prItemsForBidding,
specificationMeetings,
prDocuments,
- biddingConditions
+ biddingConditions,
+ users
} from '@/db/schema'
import {
eq,
@@ -31,6 +32,22 @@ import { filterColumns } from '@/lib/filter-columns'
import { CreateBiddingSchema, GetBiddingsSchema, UpdateBiddingSchema } from './validation'
import { saveFile } from '../file-stroage'
+// 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를 그대로 반환
+ }
+}
+
export async function getBiddingNoticeTemplate() {
try {
@@ -368,6 +385,10 @@ export interface CreateBiddingInput extends CreateBiddingSchema {
itemInfo: string
quantity: string
quantityUnit: string
+ totalWeight: string
+ weightUnit: string
+ materialDescription: string
+ hasSpecDocument: boolean
requestedDeliveryDate: string
specFiles: File[]
isRepresentative: boolean
@@ -448,6 +469,7 @@ async function generateBiddingNumber(biddingType: string, tx?: any, maxRetries:
// 입찰 생성
export async function createBidding(input: CreateBiddingInput, userId: string) {
try {
+ const userName = await getUserNameById(userId)
return await db.transaction(async (tx) => {
// 자동 입찰번호 생성
const biddingNumber = await generateBiddingNumber(input.biddingType)
@@ -537,8 +559,8 @@ export async function createBidding(input: CreateBiddingInput, userId: string) {
managerPhone: input.managerPhone,
remarks: input.remarks,
- createdBy: userId,
- updatedBy: userId,
+ createdBy: userName,
+ updatedBy: userName,
})
.returning({ id: biddings.id })
@@ -589,7 +611,7 @@ export async function createBidding(input: CreateBiddingInput, userId: string) {
title: `사양설명회 - ${file.name}`,
isPublic: false,
isRequired: false,
- uploadedBy: userId,
+ uploadedBy: userName,
})
} else {
console.error(`Failed to save specification meeting file: ${file.name}`, saveResult.error)
@@ -672,7 +694,7 @@ export async function createBidding(input: CreateBiddingInput, userId: string) {
description: `PR ${prItem.prNumber}의 스펙 문서`,
isPublic: false,
isRequired: false,
- uploadedBy: userId,
+ uploadedBy: userName,
displayOrder: fileIndex + 1,
})
} else {
@@ -707,6 +729,7 @@ export async function createBidding(input: CreateBiddingInput, userId: string) {
// 입찰 수정
export async function updateBidding(input: UpdateBiddingInput, userId: string) {
try {
+ const userName = await getUserNameById(userId)
// 존재 여부 확인
const existing = await db
.select({ id: biddings.id })
@@ -750,7 +773,7 @@ export async function updateBidding(input: UpdateBiddingInput, userId: string) {
// 업데이트할 데이터 준비
const updateData: any = {
updatedAt: new Date(),
- updatedBy: userId,
+ updatedBy: userName,
}
// 정의된 필드들만 업데이트
@@ -1224,6 +1247,12 @@ export async function getBiddingBasicInfoAction(
// 입찰 조건 조회
export async function getBiddingConditions(biddingId: number) {
try {
+ // biddingId가 유효하지 않은 경우 early return
+ if (!biddingId || isNaN(biddingId) || biddingId <= 0) {
+ console.warn('Invalid biddingId provided to getBiddingConditions:', biddingId)
+ return null
+ }
+
const conditions = await db
.select()
.from(biddingConditions)