Files
desa-darmasaba/src/app/api/[[...slugs]]/_lib/kependudukan/migrasi-penduduk/findMany.ts
nico 5e822f0b05 feat: implement Kependudukan menu with CRUD admin pages
- Add Distribusi Umur admin pages (list, create, edit)
- Add Data Banjar admin pages (list, create, edit)
- Add Migrasi Penduduk admin pages (list, create, edit)
- Update state management with full CRUD operations for all modules
- Add Kependudukan menu to admin sidebar (devBar, navBar, role1)
- Add public pages for Distribusi Umur with age range sorting
- Update Dinamika Penduduk to use real-time birth/death data
- Add Biome configuration for code linting
- Create API routes for all Kependudukan modules

Features:
- Pagination and search for all admin list pages
- Responsive design (table for desktop, cards for mobile)
- Delete confirmation modal
- Toast notifications for user feedback
- Zod validation for all forms
- Age range auto-sorting in public Distribusi Umur chart

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-09 17:10:29 +08:00

63 lines
1.5 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function migrasiPendudukFindMany(context: Context) {
const page = Number(context.query.page) || 1;
const limit = Number(context.query.limit) || 10;
const search = (context.query.search as string) || '';
const jenis = (context.query.jenis as string) || '';
const tahun = Number(context.query.tahun) || new Date().getFullYear();
const skip = (page - 1) * limit;
const where: any = { isActive: true };
if (jenis) {
where.jenis = jenis;
}
if (tahun) {
where.tanggal = {
gte: new Date(`${tahun}-01-01`),
lte: new Date(`${tahun}-12-31`),
};
}
if (search) {
where.OR = [
{ nama: { contains: search, mode: "insensitive" } },
{ asalTujuan: { contains: search, mode: "insensitive" } },
];
}
try {
const [data, total] = await Promise.all([
prisma.migrasiPenduduk.findMany({
where,
skip,
take: limit,
orderBy: { tanggal: "desc" },
}),
prisma.migrasiPenduduk.count({
where,
}),
]);
return {
success: true,
message: "Success fetch migrasi penduduk with pagination",
data,
page,
totalPages: Math.ceil(total / limit),
total,
};
} catch (e) {
console.error(e);
return {
success: false,
message: "Failed to fetch migrasi penduduk with pagination",
data: null,
};
}
}