Sinkronisasi UI & API Admin - User Menu Desa, Submenu Gallery

This commit is contained in:
2025-08-12 11:45:39 +08:00
parent 2fe8b8ce1a
commit c1583c21b1
24 changed files with 1173 additions and 398 deletions

View File

@@ -1,25 +1,57 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// /api/berita/findManyPaginated.ts
import prisma from "@/lib/prisma";
import { Context } from "elysia";
async function galleryFotoFindMany() {
try {
const data = await prisma.galleryFoto.findMany({
where: { isActive: true },
include: {
imageGalleryFoto: true,
},
});
async function galleryFotoFindMany(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 fetch gallery foto",
data,
};
} catch (e) {
console.error("Find many error:", e);
return {
success: false,
message: "Failed fetch gallery foto",
};
}
// 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 {
// Ambil data dan total count secara paralel
const [data, total] = await Promise.all([
prisma.galleryFoto.findMany({
where,
include: {
imageGalleryFoto: true,
},
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.galleryFoto.count({ where }),
]);
return {
success: true,
message: "Berhasil ambil foto 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 foto",
};
}
}
export default galleryFotoFindMany
export default galleryFotoFindMany;

View File

@@ -0,0 +1,18 @@
import prisma from "@/lib/prisma";
export default async function galleryFotoFindRecent() {
const result = await prisma.galleryFoto.findMany({
orderBy: {
createdAt: "desc",
},
take: 3, // ambil 4 data terbaru
include: {
imageGalleryFoto: true,
},
});
return {
success: true,
data: result,
};
}

View File

@@ -4,6 +4,7 @@ import galleryFotoDelete from "./del";
import galleryFotoFindMany from "./find-many";
import galleryFotoUpdate from "./updt";
import galleryFotoFindUnique from "./findUnique";
import galleryFotoFindRecent from "./findRecent";
const GalleryFoto = new Elysia({ prefix: "/gallery/foto", tags: ["Desa/Gallery/Foto"] })
.get("/find-many", galleryFotoFindMany)
@@ -18,6 +19,7 @@ const GalleryFoto = new Elysia({ prefix: "/gallery/foto", tags: ["Desa/Gallery/F
imagesId: t.String(),
}),
})
.get("/find-recent", galleryFotoFindRecent)
.delete("/del/:id", galleryFotoDelete)
.put("/:id", async (context) => {
const response = await galleryFotoUpdate(context);

View File

@@ -1,22 +1,53 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// /api/berita/findManyPaginated.ts
import prisma from "@/lib/prisma";
import { Context } from "elysia";
async function galleryVideoFindMany() {
try {
const data = await prisma.galleryVideo.findMany({
where: { isActive: true },
});
async function galleryVideoFindMany(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 fetch gallery video",
data,
};
} catch (e) {
console.error("Find many error:", e);
return {
success: false,
message: "Failed fetch gallery video",
};
}
// Buat where clause
const where: any = { isActive: true };
// Tambahkan pencarian (jika ada)
if (search) {
where.OR = [
{ name: { contains: search, mode: 'insensitive' } }
];
}
try {
// Ambil data dan total count secara paralel
const [data, total] = await Promise.all([
prisma.galleryVideo.findMany({
where,
skip,
take: limit,
orderBy: { createdAt: 'desc' },
}),
prisma.galleryVideo.count({ where }),
]);
return {
success: true,
message: "Berhasil ambil video 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 video",
};
}
}
export default galleryVideoFindMany;