summaryrefslogtreecommitdiff
path: root/lib/vendors/service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vendors/service.ts')
-rw-r--r--lib/vendors/service.ts40
1 files changed, 39 insertions, 1 deletions
diff --git a/lib/vendors/service.ts b/lib/vendors/service.ts
index de88ae72..98c72349 100644
--- a/lib/vendors/service.ts
+++ b/lib/vendors/service.ts
@@ -2,7 +2,7 @@
import { revalidatePath, revalidateTag, unstable_noStore } from "next/cache";
import db from "@/db/db";
-import { vendorAttachments, VendorContact, vendorContacts, vendorDetailView, vendorItemsView, vendorMaterialsView, vendorPossibleItems, vendorPossibleMaterials, vendors, vendorsWithTypesView, vendorsWithTypesAndMaterialsView, vendorTypes, type Vendor } from "@/db/schema";
+import { vendorAttachments, VendorContact, vendorContacts, vendorDetailView, vendorItemsView, vendorMaterialsView, vendorPossibleItems, vendorPossibleMaterials, vendors, vendorsWithTypesView, vendorsWithTypesAndMaterialsView, vendorTypes, type Vendor, pqLists } from "@/db/schema";
import logger from '@/lib/logger';
import * as z from "zod"
import crypto from 'crypto';
@@ -2952,6 +2952,44 @@ export async function requestPQVendors(input: ApproveVendorsInput & {
}
}
+ // PQ 리스트 정보 조회 및 문항 검사
+ const pqType = input.type || "GENERAL";
+ const pqListConditions = [
+ eq(pqLists.type, pqType),
+ eq(pqLists.isDeleted, false)
+ ];
+
+ if (input.projectId) {
+ pqListConditions.push(eq(pqLists.projectId, input.projectId));
+ } else {
+ pqListConditions.push(isNull(pqLists.projectId));
+ }
+
+ const pqList = await db
+ .select()
+ .from(pqLists)
+ .where(and(...pqListConditions))
+ .limit(1)
+ .then(rows => rows[0]);
+
+ // PQ 리스트가 존재하지 않으면 요청 불가
+ if (!pqList) {
+ return {
+ success: false,
+ error: input.projectId ? "프로젝트 PQ 리스트를 찾을 수 없습니다" : "일반 PQ 리스트를 찾을 수 없습니다"
+ };
+ }
+
+ // PQ 리스트에 문항이 있는지 확인
+ const { getPqListCriteriaCount } = await import("@/lib/pq/service");
+ const criteriaCount = await getPqListCriteriaCount(pqList.id);
+ if (criteriaCount === 0) {
+ return {
+ success: false,
+ error: "PQ 리스트에 문항이 없습니다. 문항을 추가한 후 요청해주세요"
+ };
+ }
+
const result = await db.transaction(async (tx) => {
const vendorsBeforeUpdate = await tx
.select({ id: vendors.id, status: vendors.status })