feat : api

Deskripsi:
- add group
- add position

No issue
This commit is contained in:
lukman
2024-07-30 17:45:02 +08:00
parent 2e8d2b3c1f
commit 01016bede9
12 changed files with 214 additions and 224 deletions

View File

@@ -1,22 +1,35 @@
import { prisma } from "@/module/_global";
import _, { omit } from "lodash";
import { NextRequest } from "next/server";
export async function getAllPosition(req: NextRequest) {
try {
const searchParams = req.nextUrl.searchParams
const groupID = searchParams.get('groupID');
const groupID = "3";
const active = searchParams.get('active');
const positions = await prisma.position.findMany({
where: {
idGroup: String(groupID),
isActive: true,
isActive: (active == "true" ? true : false),
},
select: {
id: true,
name: true,
isActive: true,
Group: {
select: {
name: true
}
}
},
});
return Response.json(positions);
const allData = positions.map((v: any) => ({
..._.omit(v, ["Group"]),
group: v.Group.name
}))
return Response.json(allData);
} catch (error) {
console.error(error);
return Response.json({ success: false, message: "Internal Server Error" }, { status: 500 });