Merge pull request #69 from bipproduction/lukman/29-juli-2024

Lukman/29 juli 2024
This commit is contained in:
Amalia
2024-07-29 10:46:39 +08:00
committed by GitHub
32 changed files with 411 additions and 31 deletions

View File

@@ -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,55 @@ Content-Type: application/json
{
"id": "1"
}
}
// USERS
###
GET http://localhost:3000/api/user/get?path=get-all-users&roleID=dev&villageID=121212&groupID=2&positionID=clz24bff70001w01in64dd9ea HTTP/1.1
###
GET http://localhost:3000/api/user/get?path=get-one-users&userID=devAmalia HTTP/1.1
###
POST http://localhost:3000/api/user/post?path=create-users HTTP/1.1
Content-Type: application/json
{
"idUserRole": "user",
"idVillage": "121212",
"idGroup": "2",
"idPosition": "clz24bff70001w01in64dd9ea",
"nik": "53239236727329",
"name": "coba user",
"email": "cobauser@gmail.com",
"phone": "07319031009",
"gender": "M"
}
###
POST http://localhost:3000/api/user/post?path=update-users HTTP/1.1
Content-Type: application/json
{
"id": "clz6dq88e0001b3mlyl4vjaf8",
"idUserRole": "user",
"idVillage": "121212",
"idGroup": "2",
"idPosition": "clz24bff70001w01in64dd9ea",
"nik": "53239236727329",
"name": "coba user edit",
"email": "cobauser@gmail.com",
"phone": "07319031009",
"gender": "M"
}
###
POST http://localhost:3000/api/user/post?path=delete-users HTTP/1.1
Content-Type: application/json
{
"id": "clz6dq88e0001b3mlyl4vjaf8"
}

View File

@@ -0,0 +1,5 @@
import { apiAnnouncement } from "@/module/announcement";
export async function GET(req: Request) {
return apiAnnouncement(req, "GET")
}

View File

@@ -0,0 +1,5 @@
import { apiAnnouncement } from "@/module/announcement";
export async function POST(req: Request) {
return apiAnnouncement(req, "POST");
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -1,5 +1,6 @@
import { apiPosition } from "@/module/position";
import { NextRequest } from "next/server";
export async function GET(req: Request) {
export async function GET(req: NextRequest) {
return apiPosition(req, "GET");
}

View File

@@ -1,5 +1,6 @@
import { apiPosition } from "@/module/position";
import { NextRequest } from "next/server";
export async function POST(req: Request) {
export async function POST(req: NextRequest) {
return apiPosition(req, "POST");
}

View 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")
}

View 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")
}

View 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" });
}

View 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,
},
];

View File

@@ -0,0 +1,4 @@
export async function getAllAnnouncement(req: Request) {
try {
} catch (error) {}
}

View File

@@ -0,0 +1,5 @@
export async function getOneAnnouncement(req: Request) {
try {
} catch (error) {}
}

View File

@@ -0,0 +1,5 @@
export async function createAnnouncement(req: Request) {
try {
} catch (error) {}
}

View File

@@ -0,0 +1,5 @@
export async function deleteAnnouncement(req: Request) {
try {
} catch (error) {}
}

View File

@@ -0,0 +1,5 @@
export async function updateAnnouncement(req: Request) {
try {
} catch (error) {}
}

View File

@@ -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 };

View File

@@ -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);

View File

@@ -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",

View File

@@ -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,

View File

@@ -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,

View File

@@ -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);

View File

@@ -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: {

View File

@@ -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,

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,36 @@
import { prisma } from "@/module/_global";
import { NextRequest } from "next/server";
export async function getAllUser(req: NextRequest) {
try {
const searchParams = req.nextUrl.searchParams;
const idGroup = searchParams.get('groupID');
const idUserRole = searchParams.get('roleID');
const idPosition = searchParams.get('positionID');
const idVillage = searchParams.get('villageID');
const users = await prisma.user.findMany({
where: {
isActive: true,
idUserRole: String(idUserRole),
idPosition: idPosition,
idVillage: idVillage,
idGroup: idGroup,
},
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,28 @@
import { prisma } from "@/module/_global";
import { NextRequest } from "next/server";
export async function getOneUser(req: NextRequest) {
try {
const searchParams = req.nextUrl.searchParams;
const idUser = searchParams.get("userID");
const users = await prisma.user.findUnique({
where: {
id: String(idUser),
},
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", success: false }, { status: 500 });
}
}

View File

@@ -0,0 +1,35 @@
import { prisma } from "@/module/_global";
import { NextRequest } from "next/server";
export async function createUser(req: NextRequest) {
try {
const data = await req.json();
const users = await prisma.user.create({
data: {
nik: data.nik,
name: data.name,
phone: data.phone,
email: data.email,
gender: data.gender,
idGroup: data.idGroup,
idVillage: data.idVillage,
idPosition: data.idPosition,
idUserRole: data.idUserRole,
},
select: {
id: true,
nik: true,
name: true,
phone: true,
email: true,
gender: true,
},
});
return Response.json(users, { status: 200 });
} catch (error) {
console.error(error);
return Response.json({ message: "Internal Server Error" }, { status: 500 });
}
}

View File

@@ -0,0 +1,27 @@
import { prisma } from "@/module/_global";
import { NextRequest } from "next/server";
export async function deleteUser(req: NextRequest) {
try {
const data = await req.json();
const update = await prisma.user.update({
where: {
id: data.id,
},
data: {
isActive: false,
},
});
return Response.json(
{ success: true, message: "Sukses Delete User" },
{ status: 200 }
);
} catch (error) {
console.error(error);
return Response.json(
{ message: "Internal Server Error", success: false },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,36 @@
import { prisma } from "@/module/_global";
import { NextRequest } from "next/server";
export async function updateUser(req: NextRequest) {
try {
const data = await req.json();
const updates = await prisma.user.update({
where: {
id: data.id,
},
data: {
nik: data.nik,
name: data.name,
phone: data.phone,
email: data.email,
gender: data.gender,
idGroup: data.idGroup,
idVillage: data.idVillage,
idPosition: data.idPosition,
idUserRole: data.idUserRole,
},
});
return Response.json(
{ success: true, message: "Sukses Update User" },
{ status: 200 }
);
} catch (error) {
console.error(error);
return Response.json(
{ message: "Internal Server Error", success: false },
{ status: 500 }
);
}
}

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 };