diff options
Diffstat (limited to 'lib/vendors')
| -rw-r--r-- | lib/vendors/service.ts | 60 |
1 files changed, 22 insertions, 38 deletions
diff --git a/lib/vendors/service.ts b/lib/vendors/service.ts index 6813f717..0c61c270 100644 --- a/lib/vendors/service.ts +++ b/lib/vendors/service.ts @@ -2935,6 +2935,9 @@ export async function requestPQVendors(input: ApproveVendorsInput & { const session = await getServerSession(authOptions); const requesterId = session?.user?.id ? Number(session.user.id) : null; + // 타입 기본값 설정 + const pqType = input.type || "GENERAL"; + try { let projectInfo = null; if (input.projectId) { @@ -2954,7 +2957,6 @@ export async function requestPQVendors(input: ApproveVendorsInput & { } // PQ 리스트 정보 조회 및 문항 검사 - const pqType = input.type || "GENERAL"; const pqListConditions = [ eq(pqLists.type, pqType), eq(pqLists.isDeleted, false) @@ -3008,48 +3010,30 @@ export async function requestPQVendors(input: ApproveVendorsInput & { .from(vendors) .where(inArray(vendors.id, input.ids)); - const pqType = input.type; const currentDate = new Date(); - const existingSubmissions = await tx - .select({ vendorId: vendorPQSubmissions.vendorId }) - .from(vendorPQSubmissions) - .where( - and( - inArray(vendorPQSubmissions.vendorId, input.ids), - pqType ? eq(vendorPQSubmissions.type, pqType) : undefined, - input.projectId - ? eq(vendorPQSubmissions.projectId, input.projectId) - : isNull(vendorPQSubmissions.projectId) - ) - ); - - const existingVendorIds = new Set(existingSubmissions.map((s) => s.vendorId)); - const newVendorIds = input.ids.filter((id) => !existingVendorIds.has(id)); - - if (newVendorIds.length > 0) { - const vendorPQDataPromises = newVendorIds.map(async (vendorId) => { - const pqNumber = await generatePQNumber(pqType === "PROJECT"); + // 중복 체크 제거 - 같은 벤더에게 같은 타입의 PQ를 여러 번 요청 가능 + const vendorPQDataPromises = input.ids.map(async (vendorId) => { + const pqNumber = await generatePQNumber(pqType === "PROJECT"); - return { - vendorId, - pqNumber, - projectId: input.projectId || null, - type: pqType, - status: "REQUESTED", - requesterId: input.userId || requesterId, - dueDate: input.dueDate ? new Date(input.dueDate) : null, - agreements: input.agreements ?? {}, - pqItems: input.pqItems || null, - createdAt: currentDate, - updatedAt: currentDate, - }; - }); + return { + vendorId, + pqNumber, + projectId: input.projectId || null, + type: pqType, + status: "REQUESTED", + requesterId: input.userId || requesterId, + dueDate: input.dueDate ? new Date(input.dueDate) : null, + agreements: input.agreements ?? {}, + pqItems: input.pqItems || null, + createdAt: currentDate, + updatedAt: currentDate, + }; + }); - const vendorPQData = await Promise.all(vendorPQDataPromises); + const vendorPQData = await Promise.all(vendorPQDataPromises); - await tx.insert(vendorPQSubmissions).values(vendorPQData); - } + await tx.insert(vendorPQSubmissions).values(vendorPQData); await Promise.all( vendorsBeforeUpdate.map(async (vendorBefore) => { |
