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

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

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,26 @@ import { Context } from "elysia";
async function lembagaPendidikanFindMany(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 = [
{ nama: { contains: search, mode: "insensitive" } },
{ siswa: { contains: search, mode: "insensitive" } },
{ pengajar: { contains: search, mode: "insensitive" } },
{ jenjangPendidikan: { contains: search, mode: "insensitive" } },
];
}
try {
const [data, total] = await Promise.all([
prisma.lembaga.findMany({
where: { isActive: true },
where,
include: {
jenjangPendidikan: true,
siswa: true,
@@ -20,8 +35,8 @@ async function lembagaPendidikanFindMany(context: Context) {
take: limit,
orderBy: { createdAt: 'desc' }, // opsional, kalau mau urut berdasarkan waktu
}),
prisma.kegiatanDesa.count({
where: { isActive: true }
prisma.lembaga.count({
where,
})
]);
@@ -30,6 +45,7 @@ async function lembagaPendidikanFindMany(context: Context) {
message: "Success fetch lembaga pendidikan with pagination",
data,
page,
limit,
totalPages: Math.ceil(total / limit),
total,
};

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";
@@ -6,11 +7,23 @@ async function pengajarFindMany(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) || "";
// Buat where clause
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ nama: { contains: search, mode: "insensitive" } },
{ lembaga: { contains: search, mode: "insensitive" } },
];
}
try {
const [data, total] = await Promise.all([
prisma.pengajar.findMany({
where: { isActive: true },
where,
include: {
lembaga: true,
},
@@ -19,7 +32,7 @@ async function pengajarFindMany(context: Context) {
orderBy: { createdAt: 'desc' }, // opsional, kalau mau urut berdasarkan waktu
}),
prisma.pengajar.count({
where: { isActive: true }
where,
})
]);
@@ -28,6 +41,7 @@ async function pengajarFindMany(context: Context) {
message: "Success fetch pengajar with pagination",
data,
page,
limit,
totalPages: Math.ceil(total / limit),
total,
};

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";
@@ -6,11 +7,23 @@ async function siswaFindMany(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) || "";
// Buat where clause
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ nama: { contains: search, mode: "insensitive" } },
{ lembaga: { contains: search, mode: "insensitive" } },
];
}
try {
const [data, total] = await Promise.all([
prisma.siswa.findMany({
where: { isActive: true },
where,
include: {
lembaga: true,
},
@@ -19,7 +32,7 @@ async function siswaFindMany(context: Context) {
orderBy: { createdAt: 'desc' }, // opsional, kalau mau urut berdasarkan waktu
}),
prisma.siswa.count({
where: { isActive: true }
where,
})
]);
@@ -28,6 +41,7 @@ async function siswaFindMany(context: Context) {
message: "Success fetch siswa with pagination",
data,
page,
limit,
totalPages: Math.ceil(total / limit),
total,
};