Add Detail Semua Polsek, Submenu Polsek Terdekat, Menu Keamanan

This commit is contained in:
2025-08-19 17:40:59 +08:00
parent d79425d529
commit 49067f0218
11 changed files with 541 additions and 369 deletions

View File

@@ -15,16 +15,12 @@ export default async function respondenCreate(context: Context) {
try {
// Convert the date string to a Date object
const tanggal = new Date(body.tanggal);
// Validate the date
if (isNaN(tanggal.getTime())) {
throw new Error('Tanggal tidak valid');
}
const result = await prisma.responden.create({
data: {
name: body.name,
tanggal: tanggal, // Use the Date object
tanggal: tanggal.toISOString(), // Use the Date object
jenisKelaminId: body.jenisKelaminId,
ratingId: body.ratingId,
kelompokUmurId: body.kelompokUmurId,

View File

@@ -2,35 +2,40 @@ import prisma from "@/lib/prisma";
import { Context } from "elysia";
type FormUpdate = {
name: string;
tanggal: string;
jenisKelaminId: string;
ratingId: string;
kelompokUmurId: string;
}
name: string;
tanggal: string;
jenisKelaminId: string;
ratingId: string;
kelompokUmurId: string;
};
export default async function respondenUpdate(context: Context) {
const body = (await context.body) as FormUpdate;
const id = context.params.id as string;
const body = (await context.body) as FormUpdate;
const id = context.params.id as string;
try {
const result = await prisma.responden.update({
where: { id },
data: {
name: body.name,
tanggal: body.tanggal,
jenisKelaminId: body.jenisKelaminId,
ratingId: body.ratingId,
kelompokUmurId: body.kelompokUmurId,
},
});
return {
success: true,
message: "Berhasil mengupdate responden",
data: result,
};
} catch (error) {
console.error("Error updating responden:", error);
throw new Error("Gagal mengupdate responden: " + (error as Error).message);
}
try {
const result = await prisma.responden.update({
where: { id },
data: {
name: body.name,
tanggal: new Date(body.tanggal).toISOString(),
jenisKelaminId: body.jenisKelaminId,
ratingId: body.ratingId,
kelompokUmurId: body.kelompokUmurId,
},
});
return {
success: true,
message: "Berhasil mengupdate responden",
data: result,
};
} catch (error) {
console.error("Error updating responden:", error);
// Instead of throwing an error, return a proper JSON response
return {
success: false,
message: "Gagal mengupdate responden: " + (error as Error).message,
data: null,
};
}
}