From a78f26bc52a2ff032a8103f36a2a660cefa9fb64 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Fri, 7 Nov 2025 15:29:36 +0900 Subject: (김준회) 정규벤더 등록요청 결재 연결, 공통컴포넌트(미리보기) 연결, MDG 송신 공통함수 사용처리 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../approval-actions.ts | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'lib/vendor-regular-registrations/approval-actions.ts') diff --git a/lib/vendor-regular-registrations/approval-actions.ts b/lib/vendor-regular-registrations/approval-actions.ts index b90ef2b6..2bd5ec0f 100644 --- a/lib/vendor-regular-registrations/approval-actions.ts +++ b/lib/vendor-regular-registrations/approval-actions.ts @@ -14,6 +14,7 @@ import type { RegistrationRequestData } from '@/components/vendor-regular-regist import db from '@/db/db'; import { eq } from 'drizzle-orm'; import { vendorRegularRegistrations } from '@/db/schema/vendorRegistrations'; +import { users } from '@/db/schema'; /** * 결재를 거쳐 정규업체 등록을 처리하는 서버 액션 @@ -24,7 +25,8 @@ import { vendorRegularRegistrations } from '@/db/schema/vendorRegistrations'; * registrationId: 123, * requestData: registrationData, * currentUser: { id: 1, epId: 'EP001', email: 'user@example.com' }, - * approvers: ['EP002', 'EP003'] + * approvers: ['EP002', 'EP003'], + * attachments: [file1, file2] // 선택사항 * }); * * if (result.status === 'pending_approval') { @@ -38,6 +40,8 @@ export async function registerVendorWithApproval(data: { vendorId?: number; // vendors 테이블에서 정보를 가져오기 위한 vendorId currentUser: { id: number; epId: string | null; email?: string }; approvers?: string[]; // Knox EP ID 배열 (결재선) + attachments?: File[]; // 첨부파일 (선택사항) + title?: string; // 결재 제목 (선택사항, 미지정 시 자동 생성) }) { debugLog('[VendorRegistrationApproval] 정규업체 등록 결재 서버 액션 시작', { registrationId: data.registrationId, @@ -58,7 +62,16 @@ export async function registerVendorWithApproval(data: { throw new Error('등록 ID가 필요합니다'); } - // 1. 템플릿 변수 매핑 + // 1. 유저의 nonsapUserId 조회 (Cronjob 환경을 위해) + debugLog('[VendorRegistrationApproval] nonsapUserId 조회'); + const userResult = await db.query.users.findFirst({ + where: eq(users.id, data.currentUser.id), + columns: { nonsapUserId: true } + }); + const nonsapUserId = userResult?.nonsapUserId || null; + debugLog('[VendorRegistrationApproval] nonsapUserId 조회 완료', { nonsapUserId }); + + // 2. 템플릿 변수 매핑 debugLog('[VendorRegistrationApproval] 템플릿 변수 매핑 시작'); const requestedAt = new Date(); const variables = await mapRegistrationToTemplateVariables({ @@ -70,8 +83,11 @@ export async function registerVendorWithApproval(data: { variableKeys: Object.keys(variables), }); - // 2. 결재 워크플로우 시작 (Saga 패턴) - debugLog('[VendorRegistrationApproval] ApprovalSubmissionSaga 생성'); + // 3. 결재 워크플로우 시작 (Saga 패턴) + debugLog('[VendorRegistrationApproval] ApprovalSubmissionSaga 생성', { + hasAttachments: !!data.attachments, + attachmentCount: data.attachments?.length || 0, + }); const saga = new ApprovalSubmissionSaga( // actionType: 핸들러를 찾을 때 사용할 키 'vendor_regular_registration', @@ -80,23 +96,29 @@ export async function registerVendorWithApproval(data: { { registrationId: data.registrationId, requestData: data.requestData, + currentUser: { // ⚠️ Cronjob 환경을 위한 유저 정보 포함 (headers() 대신) + id: data.currentUser.id, + email: data.currentUser.email, + nonsapUserId: nonsapUserId, // ⚠️ 미리 조회한 nonsapUserId 전달 + }, }, // approvalConfig: 결재 상신 정보 (템플릿 포함) { - title: `정규업체 등록 - ${data.requestData.companyNameKor}`, + title: data.title || `정규업체 등록 - ${data.requestData.companyNameKor}`, description: `${data.requestData.companyNameKor} 정규업체 등록 요청`, templateName: '정규업체 등록', // 한국어 템플릿명 variables, // 치환할 변수들 approvers: data.approvers, currentUser: data.currentUser, + attachments: data.attachments, // 첨부파일 전달 } ); debugLog('[VendorRegistrationApproval] Saga 실행 시작'); const result = await saga.execute(); - // 3. 결재 상신 성공 시 상태를 pending_approval로 변경 + // 4. 결재 상신 성공 시 상태를 pending_approval로 변경 if (result.status === 'pending_approval') { debugLog('[VendorRegistrationApproval] 상태를 pending_approval로 변경'); await db.update(vendorRegularRegistrations) -- cgit v1.2.3