api : add api position api group and api users

This commit is contained in:
lukman
2024-07-26 17:44:54 +08:00
parent 4e55c7b061
commit ea7a2ba98c
30 changed files with 267 additions and 29 deletions

View File

@@ -0,0 +1,34 @@
import { getAllUser } from "./get/getAllUser";
import { getOneUser } from "./get/getOneUser";
import { updateUser } from "./post/updateUser";
import { deleteUser } from "./post/deleteUser";
import { createUser } from "./post/createUser";
export const API_INDEX_USER = [
{
path: "get-all-users",
method: "GET",
bin: getAllUser,
},
{
path: "get-one-users",
method: "GET",
bin: getOneUser,
},
{
path: "create-users",
method: "POST",
bin: createUser,
},
{
path: "update-users",
method: "POST",
bin: updateUser,
},
{
path: "delete-users",
method: "POST",
bin: deleteUser,
},
];

View File

@@ -0,0 +1,15 @@
import { NextRequest } from "next/server";
import { API_INDEX_USER } from "./api_index";
type Method = "GET" | "POST";
export async function apiUser(req: NextRequest, method: Method) {
const { searchParams } = new URL(req.url);
const path = searchParams.get("path");
const act = API_INDEX_USER.find((v) => v.path === path && v.method === method);
if (!path)
return Response.json({ message: "page not found" }, { status: 404 });
if (act) return act.bin(req);
return Response.json({ message: "404" });
}

View File

@@ -0,0 +1,31 @@
import { prisma } from "@/module/_global";
import { NextRequest } from "next/server";
export async function getAllUser(req: NextRequest) {
try {
const searchParams = req.nextUrl.searchParams;
const users = await prisma.user.findMany({
where: {
isActive: true,
idUserRole: String(searchParams.get("roleID")),
idPosition: String(searchParams.get("positionID")),
idVillage: String(searchParams.get("villageID")),
idGroup: String(searchParams.get("groupID")),
},
select: {
id: true,
nik: true,
name: true,
phone: true,
email: true,
gender: true,
},
});
return Response.json(users);
} catch (error) {
console.error(error);
return Response.json({ message: "Internal Server Error" }, { status: 500 });
}
}

View File

@@ -0,0 +1,9 @@
import { NextRequest } from "next/server";
export async function getOneUser(req: NextRequest) {
try {
} catch (error) {
}
}

View File

@@ -0,0 +1,9 @@
import { NextRequest } from "next/server";
export async function createUser(req: NextRequest) {
try {
} catch (error) {
}
}

View File

@@ -0,0 +1,9 @@
import { NextRequest } from "next/server";
export async function deleteUser(req: NextRequest) {
try {
} catch (error) {
}
}

View File

@@ -0,0 +1,9 @@
import { NextRequest } from "next/server";
export async function updateUser(req: NextRequest) {
try {
} catch (error) {
}
}

View File

@@ -1,5 +1,7 @@
import { apiUser } from "./api/api_user";
import ViewEditProfile from "./profile/view/view_edit_profile";
import ViewProfile from "./profile/view/view_profile";
export { ViewProfile }
export { ViewEditProfile }
export { ViewProfile };
export { ViewEditProfile };
export { apiUser };