Fix All Search Admin

This commit is contained in:
2026-01-05 17:11:30 +08:00
parent f436aa2ef0
commit daaed8089b
39 changed files with 872 additions and 694 deletions

View File

@@ -7,20 +7,20 @@ async function kategoriProdukFindMany(context: Context) {
// Ambil parameter dari query
const page = Number(context.query.page) || 1;
const limit = Number(context.query.limit) || 10;
const search2 = (context.query.search as string) || '';
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 (search2) {
if (search) {
where.OR = [
{ nama: { contains: search2, mode: 'insensitive' } },
{ nama: { contains: search, mode: 'insensitive' } },
{KategoriToPasar : {
some: {
kategori: {
nama: { contains: search2, mode: 'insensitive' }
nama: { contains: search, mode: 'insensitive' }
}
}
}}

View File

@@ -5,19 +5,19 @@ import { Context } from "elysia";
async function kategoriProdukFindManyAll(context: Context) {
// Ambil query search (opsional)
const search2 = (context.query.search as string) || "";
const search = (context.query.search as string) || "";
// Buat where clause
const where: any = { isActive: true };
if (search2) {
if (search) {
where.OR = [
{ nama: { contains: search2, mode: "insensitive" } },
{ nama: { contains: search, mode: "insensitive" } },
{
KategoriToPasar: {
some: {
kategori: {
nama: { contains: search2, mode: "insensitive" },
nama: { contains: search, mode: "insensitive" },
},
},
},

View File

@@ -1,48 +1,72 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
// Di findMany.ts
export default async function pegawaiFindMany(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;
const isActiveParam = context.query.isActive;
// where clause dinamis
const where: any = {};
if (isActiveParam !== undefined) {
where.isActive = isActiveParam === "true";
}
if (search) {
where.OR = [
{ namaLengkap: { contains: search, mode: "insensitive" } },
{ alamat: { contains: search, mode: "insensitive" } },
{ posisi: { nama: { contains: search, mode: "insensitive" } } },
];
}
try {
const [data, total] = await Promise.all([
// Ambil semua data terlebih dahulu (tanpa pagination)
const [allData, total] = await Promise.all([
prisma.pegawaiBumDes.findMany({
where: { isActive: true },
where,
include: {
posisi: true,
image: true,
},
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.pegawaiBumDes.count({
where: { isActive: true }
})
prisma.pegawaiBumDes.count({ where }),
]);
// Sort manual berdasarkan hierarki posisi
const sortedData = allData.sort((a, b) => {
// Sort berdasarkan hierarki terlebih dahulu
if (a.posisi.hierarki !== b.posisi.hierarki) {
return a.posisi.hierarki - b.posisi.hierarki;
}
// Jika hierarki sama, sort berdasarkan nama posisi
return a.posisi.nama.localeCompare(b.posisi.nama);
});
// Lakukan pagination manual setelah sorting
const paginatedData = sortedData.slice(skip, skip + limit);
const totalPages = Math.ceil(total / limit);
return {
success: true,
message: "Success fetch pegawai with pagination",
data,
message: "Success fetch pegawai with hierarchy order",
data: paginatedData,
page,
totalPages,
total,
};
} catch (e) {
console.error("Find many paginated error:", e);
} catch (error) {
console.error("Find many pegawai error:", error);
return {
success: false,
message: "Failed fetch pegawai with pagination",
message: "Failed fetch pegawai",
data: [],
page: 1,
totalPages: 1,
total: 0,
};
}
}
}

View File

@@ -0,0 +1,48 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function pegawaiFindManyAll(context: Context) {
const search = (context.query.search as string) || "";
const isActiveParam = context.query.isActive;
// Buat where clause dinamis
const where: any = {};
if (isActiveParam !== undefined) {
where.isActive = isActiveParam === "true";
}
if (search) {
where.OR = [
{ namaLengkap: { contains: search, mode: "insensitive" } },
{ alamat: { contains: search, mode: "insensitive" } },
];
}
try {
const data = await prisma.pegawaiBumDes.findMany({
where,
include: {
posisi: true,
image: true,
},
orderBy: { posisi: { hierarki: "asc" } },
});
return {
success: true,
message: "Success fetch all pegawai (non-paginated)",
total: data.length,
data,
};
} catch (error) {
console.error("Find many all error:", error);
return {
success: false,
message: "Failed fetch all pegawai",
total: 0,
data: [],
};
}
}

View File

@@ -1,8 +1,49 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function dataPendidikanFindMany() {
const res = await prisma.dataPendidikan.findMany();
return {
data: res,
};
}
export default async function dataPendidikanFindMany(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;
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ name: { contains: search, mode: 'insensitive' } },
{ jumlah: { contains: search, mode: 'insensitive' } },
];
}
try {
const [data, total] = await Promise.all([
prisma.dataPendidikan.findMany({
where,
skip,
take: limit,
orderBy: { name: "asc" }, // opsional, kalau mau urut berdasarkan waktu
}),
prisma.dataPendidikan.count({
where: { isActive: true },
}),
]);
return {
success: true,
message: "Success fetch program inovasi with pagination",
data,
page,
totalPages: Math.ceil(total / limit),
total,
};
} catch (e) {
console.error("Find many paginated error:", e);
return {
success: false,
message: "Failed fetch program inovasi with pagination",
};
}
}

View File

@@ -1,11 +1,49 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function roleFindMany() {
const data = await prisma.role.findMany();
export default async function roleFindMany(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;
return {
success: true,
message: "Success get all role",
data,
};
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ name: { contains: search, mode: 'insensitive' } },
{ description: { contains: search, mode: 'insensitive' } },
];
}
try {
const [data, total] = await Promise.all([
prisma.role.findMany({
where,
skip,
take: limit,
orderBy: { name: "asc" }, // opsional, kalau mau urut berdasarkan waktu
}),
prisma.role.count({
where: { isActive: true },
}),
]);
return {
success: true,
message: "Success fetch role with pagination",
data,
page,
totalPages: Math.ceil(total / limit),
total,
};
} catch (e) {
console.error("Find many paginated error:", e);
return {
success: false,
message: "Failed fetch role with pagination",
};
}
}