fix(user,trash): fix 500 server error when deleting user with operational history and protect audit integrity

This commit is contained in:
Ray1111-aa
2026-11-03 09:14:53 +07:00
parent 5a4969b467
commit ff3ab616e0
9 changed files with 236 additions and 52 deletions
+20 -16
View File
@@ -73,24 +73,28 @@ class TrashController extends Controller
*/
public function forceDelete(string $category, int $id): RedirectResponse
{
$success = $this->trashService->forceDeleteItem($category, $id);
try {
$success = $this->trashService->forceDeleteItem($category, $id);
if (!$success) {
return back()->with('error', 'Data tidak ditemukan di tong sampah atau gagal dihapus permanen.');
if (!$success) {
return back()->with('error', 'Data tidak ditemukan di tong sampah atau gagal dihapus permanen.');
}
$catDefinitions = TrashService::getCategoryDefinitions();
$label = $catDefinitions[$category]['label'] ?? $category;
AdminActivityLog::record(
actionType: 'delete',
module: 'Tong Sampah',
description: "Menghapus permanen data pada kategori '{$label}' (ID: {$id}).",
targetType: $category,
targetId: $id
);
return back()->with('success', "Data '{$label}' berhasil dihapus permanen dari sistem.");
} catch (\Throwable $e) {
return back()->with('error', 'Aksi Ditolak: ' . $e->getMessage());
}
$catDefinitions = TrashService::getCategoryDefinitions();
$label = $catDefinitions[$category]['label'] ?? $category;
AdminActivityLog::record(
actionType: 'delete',
module: 'Tong Sampah',
description: "Menghapus permanen data pada kategori '{$label}' (ID: {$id}).",
targetType: $category,
targetId: $id
);
return back()->with('success', "Data '{$label}' berhasil dihapus permanen dari sistem.");
}
/**