summaryrefslogtreecommitdiff
path: root/lib/techsales-rfq/approval-actions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/techsales-rfq/approval-actions.ts')
-rw-r--r--lib/techsales-rfq/approval-actions.ts71
1 files changed, 69 insertions, 2 deletions
diff --git a/lib/techsales-rfq/approval-actions.ts b/lib/techsales-rfq/approval-actions.ts
index cf914592..c85a950f 100644
--- a/lib/techsales-rfq/approval-actions.ts
+++ b/lib/techsales-rfq/approval-actions.ts
@@ -97,7 +97,13 @@ export async function requestTechSalesRfqSendWithApproval(data: TechSalesRfqSend
applicationReason: data.applicationReason,
});
- // 5. 결재 상신용 payload 구성
+ // 5. Knox 상신용 첨부파일 준비
+ const knoxAttachments = await prepareKnoxDrmAttachments(data.drmAttachmentIds);
+ if (knoxAttachments.length === 0) {
+ throw new Error('상신할 DRM 첨부파일을 준비하지 못했습니다.');
+ }
+
+ // 6. 결재 상신용 payload 구성
const approvalPayload = {
rfqId: data.rfqId,
rfqCode: data.rfqCode,
@@ -112,7 +118,7 @@ export async function requestTechSalesRfqSendWithApproval(data: TechSalesRfqSend
},
};
- // 6. Saga로 결재 상신
+ // 7. Saga로 결재 상신
const saga = new ApprovalSubmissionSaga(
'tech_sales_rfq_send_with_drm', // 핸들러 키
approvalPayload, // 결재 승인 후 실행될 데이터
@@ -127,6 +133,7 @@ export async function requestTechSalesRfqSendWithApproval(data: TechSalesRfqSend
epId: data.currentUser.epId,
email: data.currentUser.email,
},
+ attachments: knoxAttachments,
}
);
@@ -171,6 +178,59 @@ function getTechSalesRevalidationPath(rfqType: "SHIP" | "TOP" | "HULL"): string
return "/evcp/budgetary-tech-sales-ship";
}
}
+
+/**
+ * Knox 상신용 DRM 첨부파일을 File 객체로 준비
+ */
+async function prepareKnoxDrmAttachments(attachmentIds: number[]): Promise<File[]> {
+ if (!attachmentIds || attachmentIds.length === 0) return [];
+
+ const db = (await import('@/db/db')).default;
+ const { techSalesAttachments } = await import('@/db/schema/techSales');
+ const { inArray } = await import('drizzle-orm');
+
+ const attachments = await db.query.techSalesAttachments.findMany({
+ where: inArray(techSalesAttachments.id, attachmentIds),
+ columns: {
+ id: true,
+ filePath: true,
+ originalFileName: true,
+ fileName: true,
+ fileType: true,
+ },
+ });
+
+ const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || process.env.NEXT_PUBLIC_URL;
+ const files: File[] = [];
+
+ for (const attachment of attachments) {
+ if (!attachment.filePath || !baseUrl) {
+ console.error('[TechSales RFQ Approval] 첨부파일 경로나 BASE_URL이 없습니다.', attachment.id);
+ continue;
+ }
+
+ const fileUrl = `${baseUrl}${attachment.filePath}`;
+ const response = await fetch(fileUrl);
+
+ if (!response.ok) {
+ console.error(`[TechSales RFQ Approval] 첨부파일 다운로드 실패: ${fileUrl} (status: ${response.status})`);
+ continue;
+ }
+
+ const blob = await response.blob();
+ const file = new File(
+ [blob],
+ attachment.originalFileName || attachment.fileName || 'attachment',
+ {
+ type: attachment.fileType || blob.type || 'application/octet-stream',
+ }
+ );
+
+ files.push(file);
+ }
+
+ return files;
+}
/**
* 기술영업 RFQ DRM 첨부 해제 결재 상신
*
@@ -214,6 +274,12 @@ export async function requestRfqResendWithDrmApproval(data: {
applicationReason: data.applicationReason,
});
+ // DRM 첨부파일을 Knox 상신용 File 객체로 준비
+ const knoxAttachments = await prepareKnoxDrmAttachments(data.drmAttachmentIds);
+ if (knoxAttachments.length === 0) {
+ throw new Error('상신할 DRM 첨부파일을 준비하지 못했습니다.');
+ }
+
// 결재 payload 구성
const approvalPayload = {
rfqId: data.rfqId,
@@ -244,6 +310,7 @@ export async function requestRfqResendWithDrmApproval(data: {
epId: data.currentUser.epId,
email: data.currentUser.email,
},
+ attachments: knoxAttachments,
}
);