summaryrefslogtreecommitdiff
path: root/lib/vendor-document-list/enhanced-document-service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vendor-document-list/enhanced-document-service.ts')
-rw-r--r--lib/vendor-document-list/enhanced-document-service.ts62
1 files changed, 60 insertions, 2 deletions
diff --git a/lib/vendor-document-list/enhanced-document-service.ts b/lib/vendor-document-list/enhanced-document-service.ts
index 6f9eda01..50073ee5 100644
--- a/lib/vendor-document-list/enhanced-document-service.ts
+++ b/lib/vendor-document-list/enhanced-document-service.ts
@@ -25,6 +25,7 @@ import { getServerSession } from "next-auth/next"
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import { countDocumentStagesOnly, selectDocumentStagesOnly } from "./repository"
import { saveFile } from "../file-stroage"
+import { syncService } from "./sync-service"
// 스키마 타입 정의
export interface GetEnhancedDocumentsSchema {
@@ -1579,6 +1580,11 @@ export async function getDocumentDetails(documentId: number) {
if (!projectId) {
return { success: false, error: "프로젝트를 선택해주세요" }
}
+
+ // vendorId 가져오기
+ const vendorId = session.user.companyId ? Number(session.user.companyId) : 0
+ const userId = session.user.id ? parseInt(session.user.id) : 0
+ const userName = session.user.name || "System"
const results: UploadResult[] = []
let successCount = 0
@@ -1705,6 +1711,32 @@ export async function getDocumentDetails(documentId: number) {
revisionStatus: 'SUBMITTED',
}).returning()
revisionId = newRevision.id
+
+ // ✅ change_logs에 revision 생성 기록
+ if (vendorId > 0) {
+ try {
+ await syncService.logChange(
+ vendorId,
+ 'revision',
+ revisionId,
+ 'CREATE',
+ {
+ issueStageId: targetStageId,
+ revision: fileInfo.revision,
+ uploaderType: "vendor",
+ uploaderName: session.user.name || "System",
+ revisionStatus: 'SUBMITTED',
+ },
+ null,
+ userId,
+ userName,
+ ['DOLCE']
+ )
+ } catch (logError) {
+ console.error('Failed to log revision change:', logError)
+ // 로그 실패는 업로드 실패로 처리하지 않음
+ }
+ }
}
// 파일 저장
@@ -1720,13 +1752,39 @@ export async function getDocumentDetails(documentId: number) {
}
// 첨부파일 정보 저장
- await db.insert(documentAttachments).values({
+ const [newAttachment] = await db.insert(documentAttachments).values({
revisionId,
fileName: fileInfo.file.name,
filePath: saveResult.publicPath!,
fileType: fileInfo.file.type,
fileSize: fileInfo.file.size,
- })
+ }).returning()
+
+ // ✅ change_logs에 attachment 생성 기록
+ if (vendorId > 0 && newAttachment?.id) {
+ try {
+ await syncService.logChange(
+ vendorId,
+ 'attachment',
+ newAttachment.id,
+ 'CREATE',
+ {
+ revisionId,
+ fileName: fileInfo.file.name,
+ filePath: saveResult.publicPath!,
+ fileType: fileInfo.file.type,
+ fileSize: fileInfo.file.size,
+ },
+ null,
+ userId,
+ userName,
+ ['DOLCE']
+ )
+ } catch (logError) {
+ console.error('Failed to log attachment change:', logError)
+ // 로그 실패는 업로드 실패로 처리하지 않음
+ }
+ }
results.push({
docNumber,