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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user