summaryrefslogtreecommitdiff
path: root/lib/vendors
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-10-27 10:03:06 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-10-27 10:03:06 +0000
commita3525f8bdfcf849cc1716fab81cb8facadbe9a8e (patch)
tree0b5b534e92bcfe188d4906db7d16c37044262c2f /lib/vendors
parente87b7b06d92dc7e7235ecda24c212169f30e82ec (diff)
(최겸) 구매 협력업체 관리(PQ/실사관리, 정기평가 협력업체 제출 상세 dialog 개발,
Diffstat (limited to 'lib/vendors')
-rw-r--r--lib/vendors/service.ts60
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) => {