Fix UI PPID:
Visi Misi PPID, Dasar Hukum, Daftar Informasi Publik
This commit is contained in:
@@ -11,12 +11,8 @@ type FormCreate = Prisma.DaftarInformasiPublikGetPayload<{
|
||||
}>
|
||||
export default async function daftarInformasiPublikCreate(context: Context) {
|
||||
const body = context.body as FormCreate;
|
||||
const jumlahData = await prisma.daftarInformasiPublik.count({
|
||||
where: { isActive: true }, // hitung data aktif aja
|
||||
})
|
||||
await prisma.daftarInformasiPublik.create({
|
||||
data: {
|
||||
nomor: jumlahData + 1,
|
||||
data: {
|
||||
jenisInformasi: body.jenisInformasi,
|
||||
deskripsi: body.deskripsi,
|
||||
tanggal: body.tanggal,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
const daftarInformasiPublikDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
status: 400,
|
||||
body: "ID tidak diberikan",
|
||||
};
|
||||
}
|
||||
|
||||
const daftarInformasi = await prisma.daftarInformasiPublik.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!daftarInformasi) {
|
||||
return {
|
||||
status: 400,
|
||||
body: "Daftar Informasi Publik tidak ditemukan",
|
||||
};
|
||||
}
|
||||
|
||||
await prisma.daftarInformasiPublik.delete({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
status: 200,
|
||||
body: "Daftar Informasi Publik berhasil dihapus",
|
||||
};
|
||||
};
|
||||
|
||||
export default daftarInformasiPublikDelete;
|
||||
@@ -0,0 +1,47 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function daftarInformasiPublikEdit(context: Context) {
|
||||
const id = context.params?.id;
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID tidak ditemukan",
|
||||
};
|
||||
}
|
||||
|
||||
const { jenisInformasi, deskripsi, tanggal } = context.body as {
|
||||
jenisInformasi: string;
|
||||
deskripsi: string;
|
||||
tanggal: string;
|
||||
};
|
||||
|
||||
const existing = await prisma.daftarInformasiPublik.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Data tidak ditemukan",
|
||||
};
|
||||
}
|
||||
|
||||
const updated = await prisma.daftarInformasiPublik.update({
|
||||
where: { id },
|
||||
data: {
|
||||
jenisInformasi,
|
||||
deskripsi,
|
||||
tanggal,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Data berhasil diupdate",
|
||||
data: updated,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export default async function handler(request: Request) {
|
||||
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 {
|
||||
if (typeof id !== 'string') {
|
||||
return Response.json({
|
||||
success: false,
|
||||
message: "ID tidak valid",
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
const data = await prisma.daftarInformasiPublik.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return Response.json({
|
||||
success: false,
|
||||
message: "Data tidak ditemukan",
|
||||
}, { status: 404 });
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
success: true,
|
||||
message: "Berhasil mengambil data berdasarkan ID",
|
||||
data,
|
||||
}, { status: 200 });
|
||||
} catch (e) {
|
||||
console.error("Find by ID error:", e);
|
||||
return Response.json({
|
||||
success: false,
|
||||
message: "Gagal mengambil data: " + (e instanceof Error ? e.message : 'Unknown error'),
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,36 @@
|
||||
import Elysia, { t } from "elysia";
|
||||
import daftarInformasiPublikCreate from "./create";
|
||||
import daftarInformasiPublikFindMany from "./find-many";
|
||||
import daftarInformasiPublikFindById from "./find-by-id";
|
||||
import daftarInformasiPublikEdit from "./edit";
|
||||
import daftarInformasiPublikDelete from "./del";
|
||||
|
||||
const DaftarInformasiPublik = new Elysia({
|
||||
prefix: "/daftarinformasipublik",
|
||||
tags: ["PPID/Daftar Informasi Publik"]
|
||||
prefix: "/daftarinformasipublik",
|
||||
tags: ["PPID/Daftar Informasi Publik"],
|
||||
})
|
||||
.get("/find-many", daftarInformasiPublikFindMany)
|
||||
.post("/create", daftarInformasiPublikCreate, {
|
||||
body: t.Object({
|
||||
jenisInformasi: t.String(),
|
||||
deskripsi: t.String(),
|
||||
tanggal: t.String(),
|
||||
}),
|
||||
})
|
||||
.put("/:id", daftarInformasiPublikEdit, {
|
||||
params: t.Object({
|
||||
id: t.String(),
|
||||
}),
|
||||
body: t.Object({
|
||||
jenisInformasi: t.String(),
|
||||
deskripsi: t.String(),
|
||||
tanggal: t.String(),
|
||||
}),
|
||||
})
|
||||
.delete("/del/:id", daftarInformasiPublikDelete)
|
||||
.get("/:id", async (context) => {
|
||||
const response = await daftarInformasiPublikFindById(new Request(context.request))
|
||||
return response
|
||||
})
|
||||
.get("/find-many", daftarInformasiPublikFindMany)
|
||||
.post("/create", daftarInformasiPublikCreate, {
|
||||
body: t.Object({
|
||||
jenisInformasi: t.String(),
|
||||
deskripsi: t.String(),
|
||||
tanggal: t.String(),
|
||||
}),
|
||||
});
|
||||
|
||||
export default DaftarInformasiPublik
|
||||
export default DaftarInformasiPublik;
|
||||
|
||||
Reference in New Issue
Block a user