fitur: divisi

Deskripsi:
- pengaplikasian api terbaru pada divisi
- list divisi
- create divisi
- detail divisi

No Issues
This commit is contained in:
amel
2024-08-09 17:25:02 +08:00
parent 925e54deec
commit f0c708a8f3
32 changed files with 821 additions and 353 deletions

View File

@@ -0,0 +1,32 @@
import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import { NextResponse } from "next/server";
// GET ONE DATA DIVISI :: UNTUK TAMPIL DATA DI HALAMAN EDIT
export async function GET(request: Request, context: { params: { id: string } }) {
try {
const { id } = context.params;
const user = await funGetUserByCookies()
if (user.id == undefined) {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const data = await prisma.division.findUnique({
where: {
id: String(id),
isActive: true
}
});
if (!data) {
return NextResponse.json( { success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan", }, { status: 404 } );
}
return NextResponse.json( { success: true, message: "Berhasil mendapatkan divisi", data, }, { status: 200 } );
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}