diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-14 11:54:47 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-14 11:54:47 +0000 |
| commit | 969c25b56f6d29d7ffa4bc2ce04c5fb4e5846b34 (patch) | |
| tree | 551d335e850e6163792ded0e7a75fa41d96d612a /app/api/attachment-delete/route.ts | |
| parent | dd20ba9785cdbd3d61f6b014d003d3bd9646ad13 (diff) | |
(대표님) 정규벤더등록, 벤더문서관리, 벤더데이터입력, 첨부파일관리
Diffstat (limited to 'app/api/attachment-delete/route.ts')
| -rw-r--r-- | app/api/attachment-delete/route.ts | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/app/api/attachment-delete/route.ts b/app/api/attachment-delete/route.ts new file mode 100644 index 00000000..254c579f --- /dev/null +++ b/app/api/attachment-delete/route.ts @@ -0,0 +1,76 @@ +// /api/attachment-delete/route.ts + +import { NextRequest, NextResponse } from 'next/server' +import db from '@/db/db' +import { documentAttachments } from '@/db/schema' // 실제 스키마에 맞게 수정 +import { eq, and } from 'drizzle-orm' +import fs from 'fs/promises' +import path from 'path' + +export async function DELETE(request: NextRequest) { + try { + const { attachmentId, revisionId } = await request.json() + + if (!attachmentId || !revisionId) { + return NextResponse.json( + { error: 'attachmentId and revisionId are required' }, + { status: 400 } + ) + } + + // 1. 데이터베이스에서 첨부파일 정보 조회 + const attachment = await db + .select() + .from(documentAttachments) + .where( + and( + eq(documentAttachments.id, attachmentId), + eq(documentAttachments.revisionId, revisionId) + ) + ) + .limit(1) + + if (!attachment || attachment.length === 0) { + return NextResponse.json( + { error: 'Attachment not found' }, + { status: 404 } + ) + } + + const attachmentData = attachment[0] + + // 2. dolceFilePath 체크 - 있으면 삭제 불가 + if (attachmentData.dolceFilePath && attachmentData.dolceFilePath.trim() !== '') { + return NextResponse.json( + { error: 'Cannot delete processed file' }, + { status: 403 } + ) + } + + // 4. 데이터베이스에서 첨부파일 레코드 삭제 + await db + .delete(documentAttachments) + .where( + and( + eq(documentAttachments.id, attachmentId), + eq(documentAttachments.revisionId, revisionId) + ) + ) + + return NextResponse.json({ + success: true, + message: 'Attachment deleted successfully', + deletedAttachmentId: attachmentId + }) + + } catch (error) { + console.error('Attachment deletion error:', error) + return NextResponse.json( + { + error: 'Internal server error', + details: error instanceof Error ? error.message : 'Unknown error' + }, + { status: 500 } + ) + } +}
\ No newline at end of file |
