Yang Sudah Di Kerjakan * Tampilan UI Admin di menu inovasi * API Create, edit dan delete potensi * Tampilan UI Landing Page sudah sesuai di mobile Yang Lagi Dikerjakan: * Progress Tampilan UI Admin Di Menu lingkungan * Progress API Create, edit dan delete potensi Yang Akan Dikerjakan: * API Create, edit dan delete pengumuman * Tampilan UI Admin Di Menu Pendidikan
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import prisma from "@/lib/prisma";
|
|
|
|
export default async function handler(
|
|
request: Request
|
|
) {
|
|
// Extract the ID from the URL path
|
|
const url = new URL(request.url);
|
|
const pathSegments = url.pathname.split('/');
|
|
const id = pathSegments[pathSegments.length - 1];
|
|
|
|
if (!id) {
|
|
return Response.json({
|
|
success: false,
|
|
message: "ID tidak boleh kosong",
|
|
}, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
// Validate that the ID is a valid UUID or whatever format you're using
|
|
if (typeof id !== 'string') {
|
|
return Response.json({
|
|
success: false,
|
|
message: "ID tidak valid",
|
|
}, { status: 400 });
|
|
}
|
|
|
|
const data = await prisma.berita.findUnique({
|
|
where: { id },
|
|
include: {
|
|
image: true,
|
|
kategoriBerita: true,
|
|
},
|
|
});
|
|
|
|
if (!data) {
|
|
return Response.json({
|
|
success: false,
|
|
message: "Berita tidak ditemukan",
|
|
}, { status: 404 });
|
|
}
|
|
|
|
// Ensure we're returning a proper Response object
|
|
return Response.json({
|
|
success: true,
|
|
message: "Success fetch berita by ID",
|
|
data,
|
|
}, {
|
|
status: 200,
|
|
});
|
|
} catch (e) {
|
|
console.error("Find by ID error:", e);
|
|
return Response.json({
|
|
success: false,
|
|
message: "Gagal mengambil berita: " + (e instanceof Error ? e.message : 'Unknown error'),
|
|
}, {
|
|
status: 500,
|
|
});
|
|
}
|
|
} |