fix tampilan admin menu inovasi, sisa menu lingkungan

This commit is contained in:
2025-09-22 10:53:48 +08:00
parent 8e25c91e85
commit 0fc47c28ff
52 changed files with 3787 additions and 1723 deletions

View File

@@ -1,19 +1,54 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// /api/berita/findManyPaginated.ts
import prisma from "@/lib/prisma";
import { Context } from "elysia";
async function ajukanIdeInovatifFindMany(context: Context) {
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 = [
{ name: { contains: search, mode: 'insensitive' } },
{ alamat: { contains: search, mode: 'insensitive' } },
];
}
export default async function ajukanIdeInovatifFindMany() {
try {
const data = await prisma.ajukanIdeInovatif.findMany({});
const [data, total] = await Promise.all([
prisma.ajukanIdeInovatif.findMany({
where: where, // Use the where clause that includes search conditions
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.ajukanIdeInovatif.count({
where: where // Also update the count query to use the same where clause
})
]);
return {
success: true,
message: "Success fetch ajukan ide inovatif",
message: "Success fetch ajukan ide inovatif with pagination",
data,
page,
limit,
totalPages: Math.ceil(total / limit),
total,
};
} catch (error) {
console.error("Find many error:", error);
} catch (e) {
console.error("Find many paginated error:", e);
return {
success: false,
message: "Failed fetch ajukan ide inovatif",
message: "Failed fetch ajukan ide inovatif with pagination",
};
}
}
export default ajukanIdeInovatifFindMany;

View File

@@ -23,16 +23,16 @@ async function administrasiOnlineFindMany(context: Context) {
try {
const [data, total] = await Promise.all([
prisma.administrasiOnline.findMany({
where: { isActive: true },
where: where, // Use the where clause that includes search conditions
include: {
jenisLayanan: true,
},
skip,
take: limit,
orderBy: { createdAt: 'desc' }, // opsional, kalau mau urut berdasarkan waktu
orderBy: { createdAt: 'desc' },
}),
prisma.administrasiOnline.count({
where: { isActive: true }
where: where // Also update the count query to use the same where clause
})
]);

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// /api/berita/findManyPaginated.ts
import prisma from "@/lib/prisma";
import { Context } from "elysia";
@@ -5,12 +6,24 @@ import { Context } from "elysia";
async function pengaduanMasyarakatFindMany(context: Context) {
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 = [
{ name: { contains: search, mode: 'insensitive' } },
{ judulPengaduan: { contains: search, mode: 'insensitive' } },
];
}
try {
const [data, total] = await Promise.all([
prisma.pengaduanMasyarakat.findMany({
where: { isActive: true },
where: where,
include: {
jenisPengaduan: true,
image: true,
@@ -20,7 +33,7 @@ async function pengaduanMasyarakatFindMany(context: Context) {
orderBy: { createdAt: 'desc' }, // opsional, kalau mau urut berdasarkan waktu
}),
prisma.pengaduanMasyarakat.count({
where: { isActive: true }
where: where
})
]);
@@ -29,6 +42,7 @@ async function pengaduanMasyarakatFindMany(context: Context) {
message: "Success fetch pengaduan masyarakat with pagination",
data,
page,
limit,
totalPages: Math.ceil(total / limit),
total,
};

View File

@@ -1,15 +1,53 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function jenisPengaduanFindMany() {
const data = await prisma.jenisPengaduan.findMany();
return {
export default async function jenisPengaduanFindMany(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 = [
{ nama: { contains: search, mode: 'insensitive' } }
];
}
try {
const [data, total] = await Promise.all([
prisma.jenisPengaduan.findMany({
where,
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.jenisLayanan.count({ where }),
]);
return {
success: true,
data: data.map((item: any) => {
return {
id: item.id,
nama: item.nama,
nama: item.nama
}
}),
page,
limit,
total,
totalPages: Math.ceil(total / limit),
};
} catch (e) {
console.error("Error di findMany paginated:", e);
return {
success: false,
message: "Gagal mengambil data jenis pengaduan",
};
}
}

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
@@ -5,29 +6,39 @@ import { Context } from "elysia";
export default async function programKreatifFindMany(context: Context) {
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 = [
{ name: { contains: search, mode: 'insensitive' } },
{ deskripsi: { contains: search, mode: 'insensitive' } },
];
}
try {
const [data, total] = await Promise.all([
prisma.programKreatif.findMany({
where: { isActive: true },
where: where,
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.programKreatif.count({
where: { isActive: true }
where: where
})
]);
const totalPages = Math.ceil(total / limit);
return {
success: true,
message: "Success fetch program kreatif with pagination",
data,
page,
totalPages,
limit,
totalPages: Math.ceil(total / limit),
total,
};
} catch (e) {
@@ -35,10 +46,6 @@ export default async function programKreatifFindMany(context: Context) {
return {
success: false,
message: "Failed fetch program kreatif with pagination",
data: [],
page: 1,
totalPages: 1,
total: 0,
};
}
}

View File

@@ -0,0 +1,33 @@
import prisma from "@/lib/prisma";
import { Context } from "elysia";
type FormCreate = {
name: string;
tanggal: string;
namaOrangtua: string;
nomor: string;
alamat: string;
catatan: string;
};
async function createPendaftaran(context: Context) {
const body = context.body as FormCreate;
await prisma.pendaftaranJadwalKegiatan.create({
data: {
name: body.name,
tanggal: body.tanggal,
namaOrangtua: body.namaOrangtua,
nomor: body.nomor,
alamat: body.alamat,
catatan: body.catatan,
},
});
return {
success: true,
message: "Success create pendaftaran jadwal kegiatan",
data: {
...body,
},
};
}
export default createPendaftaran;

View File

@@ -0,0 +1,23 @@
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function pendaftaranJadwalKegiatanDelete(context: Context) {
const id = context.params?.id as string;
if (!id) {
return {
status: 400,
body: "ID tidak diberikan",
};
}
await prisma.pendaftaranJadwalKegiatan.delete({
where: { id },
});
return {
success: true,
message: "Pendaftaran jadwal kegiatan berhasil dihapus",
status: 200,
};
}

View File

@@ -0,0 +1,50 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function pendaftaranJadwalKegiatanFindMany(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 = [
{ name: { contains: search, mode: 'insensitive' } },
];
}
try {
// Ambil data dan total count secara paralel
const [data, total] = await Promise.all([
prisma.pendaftaranJadwalKegiatan.findMany({
where,
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.pendaftaranJadwalKegiatan.count({ where }),
]);
return {
success: true,
message: "Berhasil ambil pendaftaran jadwal kegiatan dengan pagination",
data,
page,
limit,
total,
totalPages: Math.ceil(total / limit),
};
} catch (e) {
console.error("Error di findMany paginated:", e);
return {
success: false,
message: "Gagal mengambil data pendaftaran jadwal kegiatan",
};
}
}

View File

@@ -0,0 +1,45 @@
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function pendaftaranJadwalKegiatanFindUnique(context: Context) {
const id = context.params?.id as string;
if (!id) {
return Response.json({
success: false,
message: "ID tidak ditemukan",
}, {status: 400});
}
try {
if (typeof id !== 'string') {
return Response.json({
success: false,
message: "ID tidak valid",
}, {status: 400});
}
const data = await prisma.pendaftaranJadwalKegiatan.findUnique({
where: { id },
});
if (!data) {
return Response.json({
success: false,
message: "Pendaftaran jadwal kegiatan tidak ditemukan",
}, {status: 404});
}
return Response.json({
success: true,
message: "Success fetch pendaftaran jadwal kegiatan by ID",
data,
}, {status: 200});
} catch (error) {
console.error("Find by ID error:", error);
return Response.json({
success: false,
message: "Gagal mengambil pendaftaran jadwal kegiatan: " + (error instanceof Error ? error.message : 'Unknown error'),
}, {status: 500});
}
}

View File

@@ -0,0 +1,39 @@
import Elysia, { t } from "elysia";
import pendaftaranJadwalKegiatanCreate from "./create";
import pendaftaranJadwalKegiatanDelete from "./del";
import pendaftaranJadwalKegiatanUpdate from "./updt";
import pendaftaranJadwalKegiatanFindUnique from "./findUnique";
import pendaftaranJadwalKegiatanFindMany from "./findMany";
const PendaftaranJadwalKegiatan = new Elysia({
prefix: "/pendaftaran-jadwal-kegiatan",
tags: ["Kesehatan/Pendaftaran Jadwal Kegiatan"],
})
.post("/create", pendaftaranJadwalKegiatanCreate, {
body: t.Object({
name: t.String(),
tanggal: t.String(),
namaOrangtua: t.String(),
nomor: t.String(),
alamat: t.String(),
catatan: t.String(),
}),
})
.get("/find-many", pendaftaranJadwalKegiatanFindMany)
.get("/:id", pendaftaranJadwalKegiatanFindUnique)
.delete("/del/:id", pendaftaranJadwalKegiatanDelete)
.put(
"/:id",
pendaftaranJadwalKegiatanUpdate,
{
body: t.Object({
name: t.String(),
tanggal: t.String(),
namaOrangtua: t.String(),
nomor: t.String(),
alamat: t.String(),
catatan: t.String(),
}),
}
);
export default PendaftaranJadwalKegiatan;

View File

@@ -0,0 +1,87 @@
import prisma from "@/lib/prisma";
import { Context } from "elysia";
type FormUpdate = {
id: string;
name: string;
tanggal: string;
namaOrangtua: string;
nomor: string;
alamat: string;
catatan: string;
}
export default async function mitraKolaborasiUpdate(context: Context) {
try {
const id = context.params?.id as string;
const body = (await context.body) as Omit<FormUpdate, "id">;
const {
tanggal,
namaOrangtua,
nomor,
alamat,
catatan
} = body;
if (!id) {
return new Response(JSON.stringify({
success: false,
message: "ID tidak ditemukan",
}), {
status: 400,
headers: {
'Content-Type': 'application/json'
}
})
}
const existing = await prisma.pendaftaranJadwalKegiatan.findUnique({
where: {id},
})
if (!existing) {
return new Response(JSON.stringify({
success: false,
message: "Pendaftaran jadwal kegiatan tidak ditemukan",
}), {
status: 404,
headers: {
'Content-Type': 'application/json'
}
})
}
const updated = await prisma.pendaftaranJadwalKegiatan.update({
where: { id },
data: {
tanggal,
namaOrangtua,
nomor,
alamat,
catatan,
}
})
return new Response(JSON.stringify({
success: true,
message: "Pendaftaran jadwal kegiatan berhasil diupdate",
data: updated,
}), {
status: 200,
headers: {
'Content-Type': 'application/json'
}
})
} catch (error) {
console.error("Error updating pendaftaran jadwal kegiatan:", error);
return new Response(JSON.stringify({
success: false,
message: "Terjadi kesalahan saat mengupdate pendaftaran jadwal kegiatan",
}), {
status: 500,
headers: {
'Content-Type': 'application/json'
}
})
}
}

View File

@@ -19,6 +19,7 @@ import ArtikelKesehatan from "./data_kesehatan_warga/artikel_kesehatan";
import Kelahiran from "./data_kesehatan_warga/persentase_kelahiran_kematian/kelahiran";
import Kematian from "./data_kesehatan_warga/persentase_kelahiran_kematian/kematian";
import DokterTenagaMedis from "./data_kesehatan_warga/fasilitas_kesehatan/dokter-tenaga-medis";
import PendaftaranJadwalKegiatan from "./data_kesehatan_warga/jadwal_kegiatan/pendaftaran";
const Kesehatan = new Elysia({
@@ -45,4 +46,5 @@ const Kesehatan = new Elysia({
.use(Kelahiran)
.use(Kematian)
.use(DokterTenagaMedis)
.use(PendaftaranJadwalKegiatan)
export default Kesehatan;