Sinkronisasi UI & API Admin - User Submenu Gotong Royong, Menu Lingkungan

This commit is contained in:
2025-08-27 11:57:02 +08:00
parent 3a726a3334
commit f15ef5a275
20 changed files with 1443 additions and 310 deletions

View File

@@ -0,0 +1,38 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function KegiatanDesaFindFirst(context: Context) {
const kategori = (context.query.kategori as string) || '';
const where: any = { isActive: true };
if (kategori) {
where.kategoriKegiatan = {
name: { equals: kategori, mode: 'insensitive' }
};
}
try {
const data = await prisma.kegiatanDesa.findFirst({
where,
include: {
image: true,
kategoriKegiatan: true,
},
orderBy: { createdAt: 'desc' },
});
return {
success: true,
message: "Berhasil ambil gotong royong terbaru",
data,
};
} catch (error) {
console.error('Error di findFirst:', error);
return {
success: false,
message: 'Gagal memuat gotong royong terbaru',
};
}
}

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,38 @@ 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) || ''; // 🔥 Parameter kategori baru
const skip = (page - 1) * limit;
// Buat where clause
const where: any = { isActive: true };
// Filter berdasarkan kategori (jika ada)
if (kategori) {
where.kategoriKegiatan = {
nama: {
equals: kategori,
mode: 'insensitive' // Tidak case-sensitive
}
};
}
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ judul: { contains: search, mode: 'insensitive' } },
{ deskripsiSingkat: { contains: search, mode: 'insensitive' } },
{ deskripsiLengkap: { contains: search, mode: 'insensitive' } },
{ kategoriKegiatan: { nama: { contains: search, mode: 'insensitive' } } }
];
}
try {
const [data, total] = await Promise.all([
prisma.kegiatanDesa.findMany({
where: { isActive: true },
where,
include: {
kategoriKegiatan: true,
image: true,
@@ -20,7 +47,7 @@ async function kegiatanDesaFindMany(context: Context) {
orderBy: { createdAt: 'desc' }, // opsional, kalau mau urut berdasarkan waktu
}),
prisma.kegiatanDesa.count({
where: { isActive: true }
where,
})
]);

View File

@@ -4,6 +4,7 @@ import KegiatanDesaDelete from "./del";
import KegiatanDesaFindMany from "./findMany";
import KegiatanDesaFindUnique from "./findUnique";
import KegiatanDesaUpdate from "./updt";
import KegiatanDesaFindFirst from "./findFirst";
const KegiatanDesa = new Elysia({
prefix: "/kegiatandesa",
@@ -16,6 +17,9 @@ const KegiatanDesa = new Elysia({
// ✅ Find by ID
.get("/:id", KegiatanDesaFindUnique)
// ✅ Find First
.get("/find-first", KegiatanDesaFindFirst)
// ✅ Create
.post("/create", KegiatanDesaCreate, {
body: t.Object({