fix: [approval] 영구삭제 시 첨부파일/하위문서 정리 및 에러 로깅 추가

- 첨부파일(files 테이블) soft delete 처리
- 하위 문서(parent_doc_id) 참조 해제
- DB 트랜잭션으로 원자성 보장
- catch 블록에 report() 추가로 에러 로깅
This commit is contained in:
김보곤
2026-03-05 16:51:00 +09:00
parent 579a6caf39
commit 8239f03592
2 changed files with 24 additions and 8 deletions

View File

@@ -200,9 +200,12 @@ public function forceDestroy(int $id): JsonResponse
'message' => '결재 문서가 영구삭제되었습니다.', 'message' => '결재 문서가 영구삭제되었습니다.',
]); ]);
} catch (\Throwable $e) { } catch (\Throwable $e) {
report($e);
return response()->json([ return response()->json([
'success' => false, 'success' => false,
'message' => '영구삭제에 실패했습니다.', 'message' => '영구삭제에 실패했습니다.',
'error' => config('app.debug') ? $e->getMessage() : null,
], 500); ], 500);
} }
} }

View File

@@ -231,16 +231,29 @@ public function forceDeleteApproval(int $id): bool
{ {
$approval = Approval::withTrashed()->with('form')->findOrFail($id); $approval = Approval::withTrashed()->with('form')->findOrFail($id);
// 연동 Leave 정리 return DB::transaction(function () use ($approval) {
$leave = \App\Models\HR\Leave::where('approval_id', $approval->id)->first(); // 연동 Leave 정리
if ($leave) { $leave = \App\Models\HR\Leave::where('approval_id', $approval->id)->first();
$leave->update(['deleted_by' => auth()->id()]); if ($leave) {
$leave->delete(); $leave->update(['deleted_by' => auth()->id()]);
} $leave->delete();
}
$approval->steps()->withTrashed()->forceDelete(); // 첨부파일 정리 (files 테이블)
\App\Models\File::where('document_id', $approval->id)
->where('document_type', 'approval')
->update(['deleted_by' => auth()->id(), 'deleted_at' => now()]);
return $approval->forceDelete(); // 하위 문서 참조 해제
Approval::withTrashed()
->where('parent_doc_id', $approval->id)
->update(['parent_doc_id' => null]);
// 결재 단계 삭제
$approval->steps()->forceDelete();
return $approval->forceDelete();
});
} }
// ========================================================================= // =========================================================================