Sinkronisasi UI & API Admin - User Menu Inovasi

This commit is contained in:
2025-08-25 16:40:03 +08:00
parent bb8dab05ba
commit f63249327d
34 changed files with 1732 additions and 511 deletions

View File

@@ -1,23 +1,61 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function infoTeknoFindMany() {
try {
const data = await prisma.infoTekno.findMany({
include: {
image: true,
},
});
// Di findMany.ts
export default async function infoTeknoFindMany(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 fetch info teknologi",
data,
};
} catch (error) {
console.error("Find many error:", error);
return {
success: false,
message: "Failed fetch info teknologi",
};
}
// Buat where clause
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ name: { contains: search, mode: 'insensitive' } },
{ deskripsi: { contains: search, mode: 'insensitive' } },
];
}
try {
const [data, total] = await Promise.all([
prisma.infoTekno.findMany({
where,
include: {
image: true,
},
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.infoTekno.count({
where
})
]);
const totalPages = Math.ceil(total / limit);
return {
success: true,
message: "Success fetch info teknologi with pagination",
data,
page,
totalPages,
total,
};
} catch (e) {
console.error("Find many paginated error:", e);
return {
success: false,
message: "Failed fetch info teknologi with pagination",
data: [],
page: 1,
totalPages: 1,
total: 0,
};
}
}