- QC User & Admin Menu Pendidikan V
- Fix SubMenu : - Beasiswa Desa ( Baca Selengkapnya terdapatkan konten ) V - Info Sekolah ( Kategori Menyesuaikan Dengan Datanya ) V - Perpustakaan Digital ( V - Kategori Menyesuaikan Dengan Datanya V - Saat Mau minjam muncul modal data diri peminjam buku V - Ada Status Peminjamannya V )
This commit is contained in:
@@ -66,9 +66,6 @@ async function lembagaPendidikanFindMany(context: Context) {
|
||||
})
|
||||
]);
|
||||
|
||||
console.log('Fetched data count:', data.length);
|
||||
console.log('Total count:', total);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch lembaga pendidikan with pagination",
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import Elysia from "elysia";
|
||||
import DataPerpustakaan from "./data-perpustakaan";
|
||||
import KategoriBuku from "./kategori-buku";
|
||||
import PeminjamanBuku from "./peminjaman";
|
||||
|
||||
const PerpustakaanDigital = new Elysia({
|
||||
prefix: "/perpustakaandigital",
|
||||
tags: ["Pendidikan / Perpustakaan Digital"],
|
||||
})
|
||||
.use(DataPerpustakaan)
|
||||
.use(KategoriBuku);
|
||||
.use(KategoriBuku)
|
||||
.use(PeminjamanBuku);
|
||||
|
||||
export default PerpustakaanDigital;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormCreate = {
|
||||
nama: string;
|
||||
noTelp: string;
|
||||
alamat: string;
|
||||
bukuId: string;
|
||||
tanggalPinjam: string;
|
||||
batasKembali: string;
|
||||
tanggalKembali?: string;
|
||||
catatan?: string;
|
||||
}
|
||||
|
||||
export default async function peminjamanBukuCreate(context: Context) {
|
||||
const body = (await context.body) as FormCreate;
|
||||
|
||||
try {
|
||||
const result = await prisma.peminjamanBuku.create({
|
||||
data: {
|
||||
nama: body.nama,
|
||||
noTelp: body.noTelp,
|
||||
alamat: body.alamat,
|
||||
bukuId: body.bukuId,
|
||||
tanggalPinjam: body.tanggalPinjam,
|
||||
batasKembali: body.batasKembali,
|
||||
tanggalKembali: body.tanggalKembali,
|
||||
catatan: body.catatan,
|
||||
},
|
||||
});
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil membuat peminjaman buku",
|
||||
data: result,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error creating peminjaman buku:", error);
|
||||
throw new Error("Gagal membuat peminjaman buku: " + (error as Error).message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function peminjamanBukuDelete(context: Context) {
|
||||
const id = context.params.id as string;
|
||||
|
||||
await prisma.peminjamanBuku.delete({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
success: true,
|
||||
message: "Success delete peminjaman buku",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
async function peminjamanBukuFindMany(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;
|
||||
|
||||
// Buat where clause
|
||||
const where: any = {};
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ catatan: { contains: search, mode: 'insensitive' } },
|
||||
{ nama: { contains: search, mode: 'insensitive' } },
|
||||
{ buku: { judul: { contains: search, mode: 'insensitive' } } },
|
||||
{ noTelp: { contains: search, mode: 'insensitive' } },
|
||||
{ alamat: { contains: search, mode: 'insensitive' } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
// Ambil data dan total count secara paralel
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.peminjamanBuku.findMany({
|
||||
where,
|
||||
include: {
|
||||
buku: {
|
||||
select: {
|
||||
id: true,
|
||||
judul: true,
|
||||
kategoriId: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
deletedAt: true,
|
||||
isActive: true,
|
||||
imageId: true,
|
||||
deskripsi: true
|
||||
}
|
||||
},
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { tanggalPinjam: 'desc' },
|
||||
}),
|
||||
prisma.peminjamanBuku.count({ where }),
|
||||
]);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil ambil data peminjaman buku dengan pagination",
|
||||
data,
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Error di peminjamanBukuFindMany:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal mengambil data peminjaman buku",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default peminjamanBukuFindMany;
|
||||
@@ -0,0 +1,49 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export default async function peminjamanBukuFindUnique(request: Request) {
|
||||
const url = new URL(request.url);
|
||||
const pathSegments = url.pathname.split('/');
|
||||
const id = pathSegments[pathSegments.length - 1];
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID is required",
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof id !== 'string') {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID is required",
|
||||
}
|
||||
}
|
||||
|
||||
const data = await prisma.peminjamanBuku.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
buku: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Data not found",
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success get data peminjaman buku",
|
||||
data,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Find by ID error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal mengambil data: " + (error instanceof Error ? error.message : 'Unknown error'),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import Elysia, { t } from "elysia";
|
||||
import peminjamanBukuCreate from "./create";
|
||||
import peminjamanBukuDelete from "./del";
|
||||
import peminjamanBukuFindMany from "./findMany";
|
||||
import peminjamanBukuFindUnique from "./findUnique";
|
||||
import peminjamanBukuUpdate from "./updt";
|
||||
|
||||
const PeminjamanBuku = new Elysia({
|
||||
prefix: "/peminjamanbuku",
|
||||
tags: ["Pendidikan / Perpustakaan Digital / Peminjaman Buku"],
|
||||
})
|
||||
|
||||
.post("/create", peminjamanBukuCreate, {
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
noTelp: t.String(),
|
||||
alamat: t.String(),
|
||||
bukuId: t.String(),
|
||||
tanggalPinjam: t.String(),
|
||||
batasKembali: t.String(),
|
||||
tanggalKembali: t.String(),
|
||||
catatan: t.String()
|
||||
}),
|
||||
})
|
||||
|
||||
.get("/findMany", peminjamanBukuFindMany)
|
||||
.get("/:id", async (context) => {
|
||||
const response = await peminjamanBukuFindUnique(
|
||||
new Request(context.request)
|
||||
);
|
||||
return response;
|
||||
})
|
||||
.put("/:id", peminjamanBukuUpdate, {
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
noTelp: t.String(),
|
||||
alamat: t.String(),
|
||||
bukuId: t.String(),
|
||||
tanggalPinjam: t.String(),
|
||||
batasKembali: t.String(),
|
||||
tanggalKembali: t.String(),
|
||||
catatan: t.String(),
|
||||
status: t.String()
|
||||
}),
|
||||
})
|
||||
.delete("/del/:id", peminjamanBukuDelete);
|
||||
|
||||
export default PeminjamanBuku;
|
||||
@@ -0,0 +1,49 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormUpdate = {
|
||||
nama: string;
|
||||
noTelp: string;
|
||||
alamat: string;
|
||||
bukuId: string;
|
||||
tanggalPinjam: string;
|
||||
batasKembali: string;
|
||||
tanggalKembali?: string;
|
||||
catatan?: string;
|
||||
status?: 'Dipinjam' | 'Dikembalikan' | 'Terlambat' | 'Dibatalkan';
|
||||
};
|
||||
|
||||
export default async function dataPerpustakaanUpdate(context: Context) {
|
||||
const body = (await context.body) as FormUpdate;
|
||||
const id = context.params.id as string;
|
||||
|
||||
try {
|
||||
const result = await prisma.peminjamanBuku.update({
|
||||
where: { id },
|
||||
data: {
|
||||
nama: body.nama,
|
||||
noTelp: body.noTelp,
|
||||
alamat: body.alamat,
|
||||
bukuId: body.bukuId,
|
||||
tanggalPinjam: body.tanggalPinjam,
|
||||
batasKembali: body.batasKembali,
|
||||
tanggalKembali: body.tanggalKembali,
|
||||
catatan: body.catatan,
|
||||
status: body.status,
|
||||
},
|
||||
include: {
|
||||
buku: true,
|
||||
}
|
||||
});
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil mengupdate data peminjaman buku",
|
||||
data: result,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error updating data peminjaman buku:", error);
|
||||
throw new Error(
|
||||
"Gagal mengupdate data peminjaman buku: " + (error as Error).message
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user