api : add api position api group and api users
This commit is contained in:
21
api.http
21
api.http
@@ -9,7 +9,7 @@ Content-Type: application/json
|
||||
// GROUP
|
||||
|
||||
###
|
||||
GET http://localhost:3000/api/group/get?path=list-group HTTP/1.1
|
||||
GET http://localhost:3000/api/group/get?path=list-group&villageId=121212 HTTP/1.1
|
||||
|
||||
###
|
||||
POST http://localhost:3000/api/group/post?path=create-group HTTP/1.1
|
||||
@@ -20,7 +20,6 @@ Content-Type: application/json
|
||||
"idVillage": "121212"
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
POST http://localhost:3000/api/group/post?path=update-group HTTP/1.1
|
||||
Content-Type: application/json
|
||||
@@ -41,7 +40,7 @@ Content-Type: application/json
|
||||
}
|
||||
|
||||
###
|
||||
GET http://localhost:3000/api/group/get?path=get-one-group HTTP/1.1
|
||||
GET http://localhost:3000/api/group/get?path=get-one-group&groupId=3 HTTP/1.1
|
||||
|
||||
|
||||
// VILLAGE
|
||||
@@ -83,18 +82,18 @@ Content-Type: application/json
|
||||
// POSITION
|
||||
|
||||
###
|
||||
GET http://localhost:3000/api/position/get?path=get-all-position HTTP/1.1
|
||||
GET http://localhost:3000/api/position/get?path=get-all-position&groupID=2 HTTP/1.1
|
||||
|
||||
###
|
||||
GET http://localhost:3000/api/position/get?path=get-one-position HTTP/1.1
|
||||
GET http://localhost:3000/api/position/get?path=get-one-position&positionId=clz24bff70001w01in64dd9ea HTTP/1.1
|
||||
|
||||
###
|
||||
POST http://localhost:3000/api/position/post?path=create-position HTTP/1.1
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"name": "Wakil Bendahara 10",
|
||||
"idGroup": "2"
|
||||
"name": "Anggota",
|
||||
"idGroup": "1"
|
||||
}
|
||||
|
||||
###
|
||||
@@ -113,4 +112,10 @@ Content-Type: application/json
|
||||
|
||||
{
|
||||
"id": "1"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// USERS
|
||||
|
||||
###
|
||||
GET http://localhost:3000/api/user/get?path=get-all-users&roleID=dev&positionID=null&villageID=null&groupID=null HTTP/1.1
|
||||
5
src/app/api/annoucement/get/route.ts
Normal file
5
src/app/api/annoucement/get/route.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { apiAnnouncement } from "@/module/announcement";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
return apiAnnouncement(req, "GET")
|
||||
}
|
||||
5
src/app/api/annoucement/post/route.ts
Normal file
5
src/app/api/annoucement/post/route.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { apiAnnouncement } from "@/module/announcement";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
return apiAnnouncement(req, "POST");
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { apiGroup } from "@/module/group";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
export async function GET(req: NextRequest) {
|
||||
return apiGroup(req, "GET")
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { apiGroup } from "@/module/group";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
export async function POST(req: NextRequest) {
|
||||
return apiGroup(req, "POST")
|
||||
}
|
||||
7
src/app/api/user/get/route.ts
Normal file
7
src/app/api/user/get/route.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
import { apiUser } from "@/module/user";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
return apiUser(req, "GET")
|
||||
}
|
||||
7
src/app/api/user/post/route.ts
Normal file
7
src/app/api/user/post/route.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
import { apiUser } from "@/module/user";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
return apiUser(req, "POST")
|
||||
}
|
||||
15
src/module/announcement/api/api_announcement.ts
Normal file
15
src/module/announcement/api/api_announcement.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { API_INDEX_ANNOUNCEMENT } from "./api_index";
|
||||
|
||||
type Method = "GET" | "POST";
|
||||
export async function apiAnnouncement(req: Request, method: Method) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const path = searchParams.get("path");
|
||||
const act = API_INDEX_ANNOUNCEMENT.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" });
|
||||
}
|
||||
34
src/module/announcement/api/api_index.ts
Normal file
34
src/module/announcement/api/api_index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { getAllAnnouncement } from "./get/getAllAnnouncement";
|
||||
import { getOneAnnouncement } from "./get/getOneAnnouncement";
|
||||
import { createAnnouncement } from "./post/createAnnouncement";
|
||||
import { deleteAnnouncement } from "./post/deleteAnnouncement";
|
||||
import { updateAnnouncement } from "./post/updateAnnouncement";
|
||||
|
||||
export const API_INDEX_ANNOUNCEMENT = [
|
||||
{
|
||||
path: "get-all-announcement",
|
||||
method: "GET",
|
||||
bin: getAllAnnouncement,
|
||||
},
|
||||
{
|
||||
path: "get-one-announcement",
|
||||
method: "GET",
|
||||
bin: getOneAnnouncement,
|
||||
},
|
||||
{
|
||||
path: "create-announcement",
|
||||
method: "POST",
|
||||
bin: createAnnouncement,
|
||||
},
|
||||
{
|
||||
path: "update-announcement",
|
||||
method: "POST",
|
||||
bin: updateAnnouncement,
|
||||
},
|
||||
{
|
||||
path: "delete-announcement",
|
||||
method: "POST",
|
||||
bin: deleteAnnouncement,
|
||||
},
|
||||
];
|
||||
|
||||
4
src/module/announcement/api/get/getAllAnnouncement.ts
Normal file
4
src/module/announcement/api/get/getAllAnnouncement.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export async function getAllAnnouncement(req: Request) {
|
||||
try {
|
||||
} catch (error) {}
|
||||
}
|
||||
5
src/module/announcement/api/get/getOneAnnouncement.ts
Normal file
5
src/module/announcement/api/get/getOneAnnouncement.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export async function getOneAnnouncement(req: Request) {
|
||||
try {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
5
src/module/announcement/api/post/createAnnouncement.ts
Normal file
5
src/module/announcement/api/post/createAnnouncement.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export async function createAnnouncement(req: Request) {
|
||||
try {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
5
src/module/announcement/api/post/deleteAnnouncement.ts
Normal file
5
src/module/announcement/api/post/deleteAnnouncement.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export async function deleteAnnouncement(req: Request) {
|
||||
try {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
5
src/module/announcement/api/post/updateAnnouncement.ts
Normal file
5
src/module/announcement/api/post/updateAnnouncement.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export async function updateAnnouncement(req: Request) {
|
||||
try {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { apiAnnouncement } from "./api/api_announcement";
|
||||
import ViewCreateAnnouncement from "./view/view_create_announcement";
|
||||
import ViewDetailAnnouncement from "./view/view_detail_anouncement";
|
||||
import ViewEditAnnouncement from "./view/view_edit_announcement";
|
||||
import ViewListAnnouncement from "./view/view_list_announcement";
|
||||
|
||||
export { ViewListAnnouncement }
|
||||
export { ViewCreateAnnouncement }
|
||||
export { ViewDetailAnnouncement }
|
||||
export { ViewEditAnnouncement }
|
||||
export { ViewListAnnouncement };
|
||||
export { ViewCreateAnnouncement };
|
||||
export { ViewDetailAnnouncement };
|
||||
export { ViewEditAnnouncement };
|
||||
export { apiAnnouncement };
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { API_INDEX_GROUP } from "./api_index";
|
||||
|
||||
type Method = "GET" | "POST";
|
||||
export async function apiGroup(req: Request, method: Method) {
|
||||
export async function apiGroup(req: NextRequest, method: Method) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const path = searchParams.get("path");
|
||||
const act = API_INDEX_GROUP.find((v) => v.path === path && v.method === method);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getOneGroup } from "./get/getOneGroup";
|
||||
import { listGroup } from "./get/listGroup";
|
||||
import { listGroups } from "./get/listGroup";
|
||||
import { createGroup } from "./post/createGroup";
|
||||
import { deleteGroup } from "./post/deleteGroup";
|
||||
import { updateGroup } from "./post/updateGroup";
|
||||
@@ -8,7 +8,7 @@ export const API_INDEX_GROUP = [
|
||||
{
|
||||
path: "list-group",
|
||||
method: "GET",
|
||||
bin: listGroup,
|
||||
bin: listGroups,
|
||||
},
|
||||
{
|
||||
path: "create-group",
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function getOneGroup(req: Request): Promise<Response> {
|
||||
export async function getOneGroup(req: NextRequest): Promise<Response> {
|
||||
try {
|
||||
// const groupId = req.params.id;
|
||||
const groupId = "clz0v4kce0009e6mukfhzmyzb";
|
||||
const searchParams = req.nextUrl.searchParams
|
||||
const groupId = searchParams.get('groupId');
|
||||
const getOne = await prisma.group.findUnique({
|
||||
where: {
|
||||
id: groupId,
|
||||
id: String(groupId),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function listGroup(req: Request): Promise<Response> {
|
||||
export async function listGroups(req: NextRequest): Promise<Response> {
|
||||
|
||||
try {
|
||||
const searchParams = req.nextUrl.searchParams
|
||||
const villaId = searchParams.get('villageId');
|
||||
const groups = await prisma.group.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idVillage: String(villaId),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { API_INDEX_POSITION } from "./api_index";
|
||||
|
||||
|
||||
type Method = "GET" | "POST";
|
||||
export async function apiPosition(req: Request, method: Method) {
|
||||
export async function apiPosition(req: NextRequest, method: Method) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const path = searchParams.get("path");
|
||||
const act = API_INDEX_POSITION.find((v) => v.path === path && v.method === method);
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function getAllPosition(req: Request) {
|
||||
export async function getAllPosition(req: NextRequest) {
|
||||
try {
|
||||
const searchParams = req.nextUrl.searchParams
|
||||
const groupID = searchParams.get('groupID');
|
||||
const positions = await prisma.position.findMany({
|
||||
where: {
|
||||
idGroup: String(groupID),
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function getOnePosition(req: Request) {
|
||||
export async function getOnePosition(req: NextRequest) {
|
||||
try {
|
||||
const positionId = "2";
|
||||
const searchParams = req.nextUrl.searchParams
|
||||
const positionId = searchParams.get('positionId');
|
||||
const getOne = await prisma.position.findUnique({
|
||||
where: {
|
||||
id: positionId,
|
||||
id: String(positionId),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
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