- Add persentase field to ProgramKesehatan (for health stats bar chart) - Add BeasiswaConfig model (dana tersalurkan + tahun ajaran) - Add RingkasanKesehatanDesa model (ibu hamil, balita, alert stunting) - Add KegiatanDesa CRUD API (GET /api/desa/kegiatandesa/find-many?kategori=Budaya) - Add BeasiswaConfig API (GET/PUT /api/pendidikan/beasiswa/beasiswaconfig/...) - Add RingkasanKesehatan API (GET/PUT /api/kesehatan/ringkasankesehatan/...) - Migration: 20260430000000_add_sosial_fields Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
import prisma from "@/lib/prisma";
|
|
import { Context } from "elysia";
|
|
|
|
async function kegiatanDesaFindMany(context: Context) {
|
|
const page = Number(context.query.page) || 1;
|
|
const limit = Number(context.query.limit) || 10;
|
|
const search = (context.query.search as string) || '';
|
|
const kategori = (context.query.kategori as string) || '';
|
|
const skip = (page - 1) * limit;
|
|
|
|
const where: any = { isActive: true };
|
|
|
|
if (search) {
|
|
where.OR = [
|
|
{ judul: { contains: search, mode: 'insensitive' } },
|
|
{ lokasi: { contains: search, mode: 'insensitive' } },
|
|
];
|
|
}
|
|
|
|
if (kategori) {
|
|
where.kategoriKegiatan = {
|
|
nama: { contains: kategori, mode: 'insensitive' },
|
|
};
|
|
}
|
|
|
|
try {
|
|
const [data, total] = await Promise.all([
|
|
prisma.kegiatanDesa.findMany({
|
|
where,
|
|
include: {
|
|
kategoriKegiatan: true,
|
|
image: true,
|
|
},
|
|
skip,
|
|
take: limit,
|
|
orderBy: { tanggal: 'asc' },
|
|
}),
|
|
prisma.kegiatanDesa.count({ where }),
|
|
]);
|
|
|
|
return {
|
|
success: true,
|
|
message: "Berhasil ambil kegiatan desa",
|
|
data,
|
|
page,
|
|
limit,
|
|
total,
|
|
totalPages: Math.ceil(total / limit),
|
|
};
|
|
} catch (e) {
|
|
console.error("Error di kegiatanDesaFindMany:", e);
|
|
return { success: false, message: "Gagal mengambil data kegiatan desa" };
|
|
}
|
|
}
|
|
|
|
export default kegiatanDesaFindMany;
|