Fix UI Admin menu desa

This commit is contained in:
2025-09-03 15:30:02 +08:00
parent fa9601e126
commit 2adf60f9eb
77 changed files with 6566 additions and 4402 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
@@ -5,11 +6,23 @@ export default async function potensiDesaFindMany(context: Context) {
const page = Number(context.query.page) || 1;
const limit = Number(context.query.limit) || 10;
const skip = (page - 1) * limit;
const search = (context.query.search as string) || '';
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ name: { contains: search, mode: 'insensitive' } },
{ kategori: { nama: { contains: search, mode: 'insensitive' } } },
{ deskripsi: { contains: search, mode: 'insensitive' } },
];
}
try {
const [data, total] = await Promise.all([
prisma.potensiDesa.findMany({
where: { isActive: true },
where,
skip,
take: limit,
include: {
@@ -22,15 +35,13 @@ export default async function potensiDesaFindMany(context: Context) {
where: { isActive: true }
})
]);
const totalPages = Math.ceil(total / limit);
return {
success: true,
message: "Success fetch potensi desa with pagination",
data,
page,
totalPages,
totalPages: Math.ceil(total / limit),
total,
};
} catch (e) {

View File

@@ -1,11 +1,53 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// /api/berita/findManyPaginated.ts
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function kategoriPotensiFindMany() {
const data = await prisma.kategoriPotensi.findMany();
async function kategoriPotensiFindMany(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;
return {
success: true,
message: "Success get all kategori potensi",
data,
};
// Buat where clause
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ nama: { contains: search, mode: 'insensitive' } },
];
}
try {
// Ambil data dan total count secara paralel
const [data, total] = await Promise.all([
prisma.kategoriPotensi.findMany({
where,
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.kategoriPotensi.count({ where }),
]);
return {
success: true,
message: "Berhasil ambil kategori potensi 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 kategori potensi",
};
}
}
export default kategoriPotensiFindMany;