Merge pull request 'Seed Pendidikan' (#54) from nico/23-jan-26 into staggingweb
Reviewed-on: http://wibugit.wibudev.com/wibu/desa-darmasaba/pulls/54
This commit is contained in:
@@ -400,6 +400,42 @@ const kategoriBuku = proxy({
|
||||
}
|
||||
},
|
||||
},
|
||||
findManyAll: {
|
||||
data: [] as Prisma.KategoriBukuGetPayload<{
|
||||
omit: {
|
||||
isActive: true;
|
||||
};
|
||||
}>[],
|
||||
loading: false,
|
||||
search: "",
|
||||
load: async (search = "") => {
|
||||
// Change to arrow function
|
||||
kategoriBuku.findManyAll.loading = true; // Use the full path to access the property
|
||||
kategoriBuku.findManyAll.search = search;
|
||||
try {
|
||||
const query: any = { search };
|
||||
if (search) query.search = search;
|
||||
|
||||
const res = await ApiFetch.api.pendidikan.perpustakaandigital.kategoribuku[
|
||||
"findManyAll"
|
||||
].get({
|
||||
query,
|
||||
});
|
||||
|
||||
if (res.status === 200 && res.data?.success) {
|
||||
kategoriBuku.findManyAll.data = res.data.data || [];
|
||||
} else {
|
||||
console.error("Failed to load pegawai:", res.data?.message);
|
||||
kategoriBuku.findManyAll.data = [];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error loading pegawai:", error);
|
||||
kategoriBuku.findManyAll.data = [];
|
||||
} finally {
|
||||
kategoriBuku.findManyAll.loading = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
findUnique: {
|
||||
data: null as Prisma.KategoriBukuGetPayload<{
|
||||
omit: {
|
||||
|
||||
@@ -40,7 +40,7 @@ function EditPerpustakaanDigital() {
|
||||
|
||||
// Load kategori & data awal
|
||||
useEffect(() => {
|
||||
perpustakaanDigitalState.kategoriBuku.findMany.load();
|
||||
perpustakaanDigitalState.kategoriBuku.findManyAll.load();
|
||||
|
||||
const loadData = async () => {
|
||||
const id = Array.isArray(params?.id) ? params.id[0] : params?.id;
|
||||
|
||||
@@ -19,7 +19,7 @@ function CreateDataPerpustakaan() {
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
perpustakaanDigitalState.kategoriBuku.findMany.load();
|
||||
perpustakaanDigitalState.kategoriBuku.findManyAll.load();
|
||||
}, []);
|
||||
|
||||
const resetForm = () => {
|
||||
@@ -109,7 +109,7 @@ function CreateDataPerpustakaan() {
|
||||
placeholder='Pilih kategori'
|
||||
value={createState.create.form.kategoriId || ""}
|
||||
onChange={(val) => { createState.create.form.kategoriId = val ?? ""; }}
|
||||
data={perpustakaanDigitalState.kategoriBuku.findMany.data?.map((item) => ({
|
||||
data={perpustakaanDigitalState.kategoriBuku.findManyAll.data?.map((item) => ({
|
||||
value: item.id,
|
||||
label: item.name,
|
||||
}))}
|
||||
|
||||
@@ -8,7 +8,8 @@ async function pengajarFindMany(context: Context) {
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const skip = (page - 1) * limit;
|
||||
const search = (context.query.search as string) || "";
|
||||
const jenjangPendidikanName = (context.query.jenjangPendidikanId as string) || "";
|
||||
const jenjangPendidikanName =
|
||||
(context.query.jenjangPendidikanId as string) || "";
|
||||
|
||||
const where: any = { isActive: true };
|
||||
|
||||
@@ -19,17 +20,17 @@ async function pengajarFindMany(context: Context) {
|
||||
where: {
|
||||
nama: {
|
||||
equals: jenjangPendidikanName,
|
||||
mode: 'insensitive'
|
||||
mode: "insensitive",
|
||||
},
|
||||
isActive: true
|
||||
isActive: true,
|
||||
},
|
||||
orderBy: { nama: 'desc' },
|
||||
orderBy: { nama: "desc" },
|
||||
});
|
||||
|
||||
if (jenjangPendidikan) {
|
||||
where.lembaga = {
|
||||
...where.lembaga,
|
||||
jenjangId: jenjangPendidikan.id
|
||||
jenjangId: jenjangPendidikan.id,
|
||||
};
|
||||
} else {
|
||||
// Jika tidak ditemukan, return data kosong
|
||||
@@ -48,8 +49,8 @@ async function pengajarFindMany(context: Context) {
|
||||
// Add search condition if search term exists
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ nama: { contains: search, mode: 'insensitive' } },
|
||||
{ lembaga: { nama: { contains: search, mode: 'insensitive' } } }
|
||||
{ nama: { contains: search, mode: "insensitive" } },
|
||||
{ lembaga: { nama: { contains: search, mode: "insensitive" } } },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -59,17 +60,15 @@ async function pengajarFindMany(context: Context) {
|
||||
include: {
|
||||
lembaga: {
|
||||
include: {
|
||||
jenjangPendidikan: true
|
||||
}
|
||||
}
|
||||
jenjangPendidikan: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { nama: 'asc' },
|
||||
orderBy: [{ nama: "asc" }, { lembaga: { nama: "asc" } }],
|
||||
}),
|
||||
prisma.pengajar.count({
|
||||
where,
|
||||
})
|
||||
prisma.pengajar.count({ where }),
|
||||
]);
|
||||
|
||||
return {
|
||||
@@ -85,8 +84,8 @@ async function pengajarFindMany(context: Context) {
|
||||
console.error("Error in pengajarFindMany:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: `Failed fetch pengajar: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
message: `Failed fetch pengajar: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
export default pengajarFindMany;
|
||||
export default pengajarFindMany;
|
||||
|
||||
@@ -8,7 +8,8 @@ async function siswaFindMany(context: Context) {
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const skip = (page - 1) * limit;
|
||||
const search = (context.query.search as string) || "";
|
||||
const jenjangPendidikanName = (context.query.jenjangPendidikanName as string) || "";
|
||||
const jenjangPendidikanName =
|
||||
(context.query.jenjangPendidikanName as string) || "";
|
||||
|
||||
// Buat where clause
|
||||
const where: any = { isActive: true };
|
||||
@@ -20,16 +21,16 @@ async function siswaFindMany(context: Context) {
|
||||
where: {
|
||||
nama: {
|
||||
equals: jenjangPendidikanName,
|
||||
mode: 'insensitive'
|
||||
mode: "insensitive",
|
||||
},
|
||||
isActive: true,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (jenjangPendidikan) {
|
||||
where.lembaga = {
|
||||
...where.lembaga,
|
||||
jenjangId: jenjangPendidikan.id
|
||||
jenjangId: jenjangPendidikan.id,
|
||||
};
|
||||
} else {
|
||||
// Jika tidak ditemukan, return data kosong
|
||||
@@ -48,8 +49,8 @@ async function siswaFindMany(context: Context) {
|
||||
// Add search functionality
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ nama: { contains: search, mode: 'insensitive' } },
|
||||
{ lembaga: { nama: { contains: search, mode: 'insensitive' } } }
|
||||
{ nama: { contains: search, mode: "insensitive" } },
|
||||
{ lembaga: { nama: { contains: search, mode: "insensitive" } } },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -65,15 +66,13 @@ async function siswaFindMany(context: Context) {
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { nama: 'asc' },
|
||||
orderBy: [{ nama: "asc" }, { lembaga: { nama: "asc" } }],
|
||||
}),
|
||||
prisma.siswa.count({
|
||||
where,
|
||||
})
|
||||
prisma.siswa.count({ where }),
|
||||
]);
|
||||
|
||||
console.log('Fetched siswa data count:', data.length);
|
||||
console.log('Total siswa count:', total);
|
||||
console.log("Fetched siswa data count:", data.length);
|
||||
console.log("Total siswa count:", total);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -88,7 +87,7 @@ async function siswaFindMany(context: Context) {
|
||||
console.error("Error in siswaFindMany:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: `Failed fetch siswa: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
message: `Failed fetch siswa: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function kategoriBukuFindManyAll(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 = [
|
||||
{ name: { contains: search, mode: "insensitive" } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await prisma.kategoriBuku.findMany({
|
||||
where,
|
||||
orderBy: { name: "asc" },
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch all kategori buku (non-paginated)",
|
||||
total: data.length,
|
||||
data,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Find many all error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch all kategori buku",
|
||||
total: 0,
|
||||
data: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import kategoriBukuDelete from "./del";
|
||||
import kategoriBukuFindMany from "./findMany";
|
||||
import kategoriBukuFindUnique from "./findUnique";
|
||||
import kategoriBukuUpdate from "./updt";
|
||||
import kategoriBukuFindManyAll from "./findManyAll";
|
||||
|
||||
const KategoriBuku = new Elysia({
|
||||
prefix: "/kategoribuku",
|
||||
@@ -17,6 +18,7 @@ const KategoriBuku = new Elysia({
|
||||
})
|
||||
|
||||
.get("/findMany", kategoriBukuFindMany)
|
||||
.get("/findManyAll", kategoriBukuFindManyAll)
|
||||
.get("/:id", async (context) => {
|
||||
const response = await kategoriBukuFindUnique(
|
||||
new Request(context.request)
|
||||
|
||||
@@ -173,9 +173,9 @@ function Content({ kategoriBuku }: { kategoriBuku: string }) {
|
||||
</Box>
|
||||
<Center mt="lg">
|
||||
<Pagination
|
||||
total={totalPages}
|
||||
value={currentPage}
|
||||
onChange={handlePageChange}
|
||||
total={totalPages}
|
||||
color="blue"
|
||||
radius="md"
|
||||
/>
|
||||
|
||||
@@ -46,7 +46,7 @@ export default function LayoutTabs({
|
||||
|
||||
// 🟦 Ambil kategori buku saat mount
|
||||
useEffect(() => {
|
||||
perpustakaanDigitalState.kategoriBuku.findMany.load();
|
||||
perpustakaanDigitalState.kategoriBuku.findManyAll.load();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -86,7 +86,7 @@ export default function LayoutTabs({
|
||||
|
||||
// 🟩 Tabs dinamis berdasarkan kategori dari state
|
||||
const kategoriTabs =
|
||||
snap.kategoriBuku.findMany.data?.map((item) => ({
|
||||
snap.kategoriBuku.findManyAll.data?.map((item) => ({
|
||||
label: item.name,
|
||||
value: item.name.toLowerCase().replace(/\s+/g, '-'),
|
||||
href: `/darmasaba/pendidikan/perpustakaan-digital/${encodeURIComponent(item.name.toLowerCase().replace(/\s+/g, '-'))}`,
|
||||
|
||||
Reference in New Issue
Block a user