fix-admin-menu-desa-potensi

This commit is contained in:
2026-02-25 15:41:01 +08:00
parent b1d28a8322
commit 22de1aa1f3
5 changed files with 89 additions and 22 deletions

View File

@@ -21,8 +21,13 @@ export default async function findUnique(
}, { status: 400 });
}
const data = await prisma.potensiDesa.findUnique({
where: { id },
// ✅ Filter by isActive and deletedAt
const data = await prisma.potensiDesa.findFirst({
where: {
id,
isActive: true,
deletedAt: null,
},
include: {
image: true,
kategori: true
@@ -48,5 +53,5 @@ export default async function findUnique(
message: "Gagal mengambil potensi desa: " + (error instanceof Error ? error.message : 'Unknown error'),
}, { status: 500 });
}
}

View File

@@ -2,15 +2,50 @@ import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function kategoriPotensiDelete(context: Context) {
const id = context.params.id as string;
try {
const id = context.params?.id as string;
await prisma.kategoriPotensi.delete({
where: { id },
});
if (!id) {
return Response.json({
success: false,
message: "ID tidak boleh kosong",
}, { status: 400 });
}
return {
status: 200,
success: true,
message: "Sukses Menghapus kategori potensi",
};
// ✅ Cek apakah kategori masih digunakan oleh potensi desa
const existingPotensi = await prisma.potensiDesa.findFirst({
where: {
kategoriId: id,
isActive: true,
deletedAt: null,
},
});
if (existingPotensi) {
return Response.json({
success: false,
message: "Kategori masih digunakan oleh potensi desa. Tidak dapat dihapus.",
}, { status: 400 });
}
// Soft delete
await prisma.kategoriPotensi.update({
where: { id },
data: {
deletedAt: new Date(),
isActive: false,
},
});
return {
success: true,
message: "Kategori potensi berhasil dihapus",
};
} catch (error) {
console.error("Delete kategori error:", error);
return Response.json({
success: false,
message: "Gagal menghapus kategori: " + (error instanceof Error ? error.message : 'Unknown error'),
}, { status: 500 });
}
}