api : add api position api group and api users
This commit is contained in:
34
src/module/user/api/api_index.ts
Normal file
34
src/module/user/api/api_index.ts
Normal 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,
|
||||
},
|
||||
];
|
||||
15
src/module/user/api/api_user.ts
Normal file
15
src/module/user/api/api_user.ts
Normal 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" });
|
||||
}
|
||||
31
src/module/user/api/get/getAllUser.ts
Normal file
31
src/module/user/api/get/getAllUser.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
9
src/module/user/api/get/getOneUser.ts
Normal file
9
src/module/user/api/get/getOneUser.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function getOneUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
9
src/module/user/api/post/createUser.ts
Normal file
9
src/module/user/api/post/createUser.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function createUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
9
src/module/user/api/post/deleteUser.ts
Normal file
9
src/module/user/api/post/deleteUser.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function deleteUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
9
src/module/user/api/post/updateUser.ts
Normal file
9
src/module/user/api/post/updateUser.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function updateUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user