summaryrefslogtreecommitdiff
path: root/lib/tags
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-08-13 11:05:09 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-08-13 11:05:09 +0000
commit33be47506f0aa62b969d82521580a29e95080268 (patch)
tree6b7e232f2d78ef8775944ea085a36b3ccbce7d95 /lib/tags
parent2ac95090157c355ea1bd0b8eb1e1e5e2bd56faf4 (diff)
(대표님) 입찰, 법무검토, EDP 변경사항 대응, dolce 개선, form-data 개선, 정규업체 등록관리 추가
(최겸) pq 미사용 컴포넌트 및 페이지 제거, 파일 라우트에 pq 적용
Diffstat (limited to 'lib/tags')
-rw-r--r--lib/tags/service.ts45
1 files changed, 32 insertions, 13 deletions
diff --git a/lib/tags/service.ts b/lib/tags/service.ts
index bec342e1..bb59287e 100644
--- a/lib/tags/service.ts
+++ b/lib/tags/service.ts
@@ -13,7 +13,7 @@ import { getErrorMessage } from "../handle-error";
import { getFormMappingsByTagType } from './form-mapping-service';
import { contractItems, contracts } from "@/db/schema/contract";
import { getCodeListsByID } from "../sedp/sync-object-class";
-import { projects } from "@/db/schema";
+import { projects, vendors } from "@/db/schema";
import { randomBytes } from 'crypto';
// 폼 결과를 위한 인터페이스 정의
@@ -390,7 +390,8 @@ export async function createTag(
export async function createTagInForm(
formData: CreateTagSchema,
selectedPackageId: number | null,
- formCode: string
+ formCode: string,
+ packageCode: string
) {
if (!selectedPackageId) {
return { error: "No selectedPackageId provided" }
@@ -412,7 +413,8 @@ export async function createTagInForm(
const contractItemResult = await tx
.select({
contractId: contractItems.contractId,
- projectId: contracts.projectId // projectId 추가
+ projectId: contracts.projectId, // projectId 추가
+ vendorId: contracts.vendorId // projectId 추가
})
.from(contractItems)
.innerJoin(contracts, eq(contractItems.contractId, contracts.id)) // contracts 테이블 조인
@@ -425,6 +427,15 @@ export async function createTagInForm(
const contractId = contractItemResult[0].contractId
const projectId = contractItemResult[0].projectId
+ const vendorId = contractItemResult[0].vendorId
+
+ const vendor = await db.query.vendors.findFirst({
+ where: eq(vendors.id, vendorId)
+ });
+
+ if (!vendor) {
+ return { error: "선택한 벤더를 찾을 수 없습니다." };
+ }
// 2) 해당 계약 내에서 같은 tagNo를 가진 태그가 있는지 확인
const duplicateCheck = await tx
@@ -560,6 +571,12 @@ export async function createTagInForm(
TAG_IDX: generatedTagIdx, // 🆕 같은 16진수 24자리 값 사용
TAG_NO: validated.data.tagNo,
TAG_DESC: validated.data.description ?? null,
+ CLS_ID: validated.data.class,
+ VNDRCD: vendor.vendorCode,
+ VNDRNM_1: vendor.vendorName,
+ CM3003: packageCode,
+ ME5074: packageCode,
+
status: "New" // 수동으로 생성된 태그임을 표시
};
@@ -596,6 +613,17 @@ export async function createTagInForm(
});
}
+ // 12) 성공 시 반환
+ return {
+ success: true,
+ data: {
+ formId: form.id,
+ tagNo: validated.data.tagNo,
+ tagIdx: generatedTagIdx, // 🆕 생성된 tagIdx도 반환
+ formCreated: !form // form이 새로 생성되었는지 여부
+ }
+ }
+
console.log(`[CREATE TAG IN FORM] Successfully created tag: ${validated.data.tagNo} with tagIdx: ${generatedTagIdx}`)
} else {
return { error: "Failed to create or find form" };
@@ -607,16 +635,7 @@ export async function createTagInForm(
revalidateTag(`form-data-${formCode}-${selectedPackageId}`) // 폼 데이터 캐시도 무효화
revalidateTag("tags")
- // 12) 성공 시 반환
- return {
- success: true,
- data: {
- formId: form.id,
- tagNo: validated.data.tagNo,
- tagIdx: generatedTagIdx, // 🆕 생성된 tagIdx도 반환
- formCreated: !form // form이 새로 생성되었는지 여부
- }
- }
+
})
} catch (err: any) {
console.log("createTag in Form error:", err)