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,
};
}
}

View File

@@ -1,44 +1,54 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// /api/berita/findManyPaginated.ts
import prisma from "@/lib/prisma";
import { Context } from "elysia";
// Di findMany.ts
export default async function daftarInformasiPublikFindMany(context: Context) {
async function daftarInformasiPublikFindMany(context: Context) {
// Ambil parameter dari query
const page = Number(context.query.page) || 1;
const limit = Number(context.query.limit) || 10;
const search = (context.query.search as string) || '';
const skip = (page - 1) * limit;
// Buat where clause
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ jenisInformasi: { contains: search, mode: 'insensitive' } },
{ deskripsi: { contains: search, mode: 'insensitive' } },
];
}
try {
// Ambil data dan total count secara paralel
const [data, total] = await Promise.all([
prisma.daftarInformasiPublik.findMany({
where: { isActive: true },
where,
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.daftarInformasiPublik.count({
where: { isActive: true }
})
prisma.daftarInformasiPublik.count({ where }),
]);
const totalPages = Math.ceil(total / limit);
return {
success: true,
message: "Success fetch daftar informasi publik with pagination",
message: "Berhasil ambil daftar informasi publik dengan pagination",
data,
page,
totalPages,
limit,
total,
totalPages: Math.ceil(total / limit),
};
} catch (e) {
console.error("Find many paginated error:", e);
console.error("Error di findMany paginated:", e);
return {
success: false,
message: "Failed fetch daftar informasi publik with pagination",
data: [],
page: 1,
totalPages: 1,
total: 0,
message: "Gagal mengambil data daftar informasi publik",
};
}
}
}
export default daftarInformasiPublikFindMany;