From 3af192313a2d93c082e74b62ff2c1ece717d9658 Mon Sep 17 00:00:00 2001 From: lukman Date: Thu, 25 Jul 2024 16:43:13 +0800 Subject: [PATCH] api : add api Deskripsi: - add gorup - add position - village No issue --- api.http | 109 ++++++++++++++++++ src/app/api/group/get/route.ts | 5 + src/app/api/group/post/route.ts | 5 + src/app/api/position/get/route.ts | 5 + src/app/api/position/post/route.ts | 5 + src/app/api/village/get/route.ts | 5 + src/app/api/village/post/route.ts | 5 + src/module/division/api/post/createProject.ts | 1 + src/module/group/api/api_group.ts | 13 +++ src/module/group/api/api_index.ts | 33 ++++++ src/module/group/api/get/getOneGroup.ts | 32 +++++ src/module/group/api/get/listGroup.ts | 20 ++++ src/module/group/api/post/createGroup.ts | 32 +++++ src/module/group/api/post/deleteGroup.ts | 19 +++ src/module/group/api/post/updateGroup.ts | 21 ++++ src/module/group/index.ts | 4 +- src/module/position/api/api_index.ts | 34 ++++++ src/module/position/api/api_position.ts | 14 +++ src/module/position/api/get/getAllPosition.ts | 20 ++++ src/module/position/api/get/getOnePosition.ts | 24 ++++ .../position/api/post/createPosition.ts | 24 ++++ .../position/api/post/deletePosition.ts | 27 +++++ .../position/api/post/updatePosition.ts | 22 ++++ src/module/position/index.ts | 4 +- src/module/village/api/api_index.ts | 36 ++++++ src/module/village/api/api_village.ts | 15 +++ src/module/village/api/get/getAllVillage.ts | 21 ++++ src/module/village/api/get/getOneVillage.ts | 32 +++++ src/module/village/api/post/createVillage.ts | 24 ++++ src/module/village/api/post/deleteVillage.ts | 25 ++++ src/module/village/api/post/updateVillage.ts | 28 +++++ src/module/village/index.ts | 3 + src/types/index.ts | 6 +- 33 files changed, 670 insertions(+), 3 deletions(-) create mode 100644 src/app/api/group/get/route.ts create mode 100644 src/app/api/group/post/route.ts create mode 100644 src/app/api/position/get/route.ts create mode 100644 src/app/api/position/post/route.ts create mode 100644 src/app/api/village/get/route.ts create mode 100644 src/app/api/village/post/route.ts create mode 100644 src/module/group/api/api_group.ts create mode 100644 src/module/group/api/api_index.ts create mode 100644 src/module/group/api/get/getOneGroup.ts create mode 100644 src/module/group/api/get/listGroup.ts create mode 100644 src/module/group/api/post/createGroup.ts create mode 100644 src/module/group/api/post/deleteGroup.ts create mode 100644 src/module/group/api/post/updateGroup.ts create mode 100644 src/module/position/api/api_index.ts create mode 100644 src/module/position/api/api_position.ts create mode 100644 src/module/position/api/get/getAllPosition.ts create mode 100644 src/module/position/api/get/getOnePosition.ts create mode 100644 src/module/position/api/post/createPosition.ts create mode 100644 src/module/position/api/post/deletePosition.ts create mode 100644 src/module/position/api/post/updatePosition.ts create mode 100644 src/module/village/api/api_index.ts create mode 100644 src/module/village/api/api_village.ts create mode 100644 src/module/village/api/get/getAllVillage.ts create mode 100644 src/module/village/api/get/getOneVillage.ts create mode 100644 src/module/village/api/post/createVillage.ts create mode 100644 src/module/village/api/post/deleteVillage.ts create mode 100644 src/module/village/api/post/updateVillage.ts diff --git a/api.http b/api.http index 1d69be2..3684308 100644 --- a/api.http +++ b/api.http @@ -4,4 +4,113 @@ Content-Type: application/json { "phone": "6287701790942" +} + +// GROUP + +### +GET http://localhost:3000/api/group/get?path=list-group HTTP/1.1 + +### +POST http://localhost:3000/api/group/post?path=create-group HTTP/1.1 +Content-Type: application/json + +{ + "name": "amalia2", + "idVillage": "121212" +} + + +### +POST http://localhost:3000/api/group/post?path=update-group HTTP/1.1 +Content-Type: application/json + +{ + "id": "1", + "name": "LPD2", + "idVillage": "121212" +} + +### +POST http://localhost:3000/api/group/post?path=delete-group HTTP/1.1 +Content-Type: application/json + +{ + "id": "1", + "idVillage": "121212" +} + +### +GET http://localhost:3000/api/group/get?path=get-one-group HTTP/1.1 + + +// VILLAGE + +### +GET http://localhost:3000/api/village/get?path=get-all-village HTTP/1.1 + +### +GET http://localhost:3000/api/village/get?path=get-one-village HTTP/1.1 + +### +POST http://localhost:3000/api/village/post?path=create-village HTTP/1.1 +Content-Type: application/json + +{ + "name": "nama satu satu ", + "desc": "description data" +} + +### +POST http://localhost:3000/api/village/post?path=update-village HTTP/1.1 +Content-Type: application/json + +{ + "id": "11", + "name": "nama satu new", + "desc": "description data new" +} + +### +POST http://localhost:3000/api/village/post?path=delete-village HTTP/1.1 +Content-Type: application/json + +{ + "id": "11" +} + + +// POSITION + +### +GET http://localhost:3000/api/position/get?path=get-all-position HTTP/1.1 + +### +GET http://localhost:3000/api/position/get?path=get-one-position 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" +} + +### +POST http://localhost:3000/api/position/post?path=update-position HTTP/1.1 +Content-Type: application/json + +{ + "id": "1", + "name": "Wakil Sekertaris", + "idGroup": "2" +} + +### +POST http://localhost:3000/api/position/post?path=delete-position HTTP/1.1 +Content-Type: application/json + +{ + "id": "1" } \ No newline at end of file diff --git a/src/app/api/group/get/route.ts b/src/app/api/group/get/route.ts new file mode 100644 index 0000000..48173b7 --- /dev/null +++ b/src/app/api/group/get/route.ts @@ -0,0 +1,5 @@ +import { apiGroup } from "@/module/group"; + +export async function GET(req: Request) { + return apiGroup(req, "GET") +} \ No newline at end of file diff --git a/src/app/api/group/post/route.ts b/src/app/api/group/post/route.ts new file mode 100644 index 0000000..9d58e5f --- /dev/null +++ b/src/app/api/group/post/route.ts @@ -0,0 +1,5 @@ +import { apiGroup } from "@/module/group"; + +export async function POST(req: Request) { + return apiGroup(req, "POST") +} \ No newline at end of file diff --git a/src/app/api/position/get/route.ts b/src/app/api/position/get/route.ts new file mode 100644 index 0000000..2944569 --- /dev/null +++ b/src/app/api/position/get/route.ts @@ -0,0 +1,5 @@ +import { apiPosition } from "@/module/position"; + +export async function GET(req: Request) { + return apiPosition(req, "GET"); +} diff --git a/src/app/api/position/post/route.ts b/src/app/api/position/post/route.ts new file mode 100644 index 0000000..4dd849e --- /dev/null +++ b/src/app/api/position/post/route.ts @@ -0,0 +1,5 @@ +import { apiPosition } from "@/module/position"; + +export async function POST(req: Request) { + return apiPosition(req, "POST"); +} diff --git a/src/app/api/village/get/route.ts b/src/app/api/village/get/route.ts new file mode 100644 index 0000000..e95887e --- /dev/null +++ b/src/app/api/village/get/route.ts @@ -0,0 +1,5 @@ +import { apiViilage } from "@/module/village"; + +export async function GET(req: Request) { + return apiViilage(req, "GET"); +} diff --git a/src/app/api/village/post/route.ts b/src/app/api/village/post/route.ts new file mode 100644 index 0000000..1c1e481 --- /dev/null +++ b/src/app/api/village/post/route.ts @@ -0,0 +1,5 @@ +import { apiViilage } from "@/module/village"; + +export async function POST(req: Request) { + return apiViilage(req, "POST"); +} diff --git a/src/module/division/api/post/createProject.ts b/src/module/division/api/post/createProject.ts index f1f4fc9..b7c8c24 100644 --- a/src/module/division/api/post/createProject.ts +++ b/src/module/division/api/post/createProject.ts @@ -1,3 +1,4 @@ export async function createProject(req: Request) { + const data = await req.json() return Response.json({ message: "success create projects" }) } \ No newline at end of file diff --git a/src/module/group/api/api_group.ts b/src/module/group/api/api_group.ts new file mode 100644 index 0000000..c6721cd --- /dev/null +++ b/src/module/group/api/api_group.ts @@ -0,0 +1,13 @@ +import { API_INDEX_GROUP } from "./api_index"; + +type Method = "GET" | "POST"; +export async function apiGroup(req: Request, 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); + if (!path) + return Response.json({ message: "page not found" }, { status: 404 }); + if (act) return act.bin(req); + + return Response.json({ message: "404" }); + } \ No newline at end of file diff --git a/src/module/group/api/api_index.ts b/src/module/group/api/api_index.ts new file mode 100644 index 0000000..52f7fa0 --- /dev/null +++ b/src/module/group/api/api_index.ts @@ -0,0 +1,33 @@ +import { getOneGroup } from "./get/getOneGroup"; +import { listGroup } from "./get/listGroup"; +import { createGroup } from "./post/createGroup"; +import { deleteGroup } from "./post/deleteGroup"; +import { updateGroup } from "./post/updateGroup"; + +export const API_INDEX_GROUP = [ + { + path: "list-group", + method: "GET", + bin: listGroup, + }, + { + path: "create-group", + method: "POST", + bin: createGroup, + }, + { + path: "update-group", + method: "POST", + bin: updateGroup, + }, + { + path: "delete-group", + method: "POST", + bin: deleteGroup, + }, + { + path: "get-one-group", + method: "GET", + bin: getOneGroup, + }, +]; diff --git a/src/module/group/api/get/getOneGroup.ts b/src/module/group/api/get/getOneGroup.ts new file mode 100644 index 0000000..b7cb0f8 --- /dev/null +++ b/src/module/group/api/get/getOneGroup.ts @@ -0,0 +1,32 @@ +import { prisma } from "@/module/_global"; + +export async function getOneGroup(req: Request): Promise { + try { + // const groupId = req.params.id; + const groupId = "clz0v4kce0009e6mukfhzmyzb"; + const getOne = await prisma.group.findUnique({ + where: { + id: groupId, + }, + select: { + id: true, + name: true, + }, + }); + + if (!getOne) { + return Response.json( + { message: "Grup tidak ditemukan", success: false }, + { status: 404 } + ); + } + + return Response.json(getOne); + } catch (error) { + console.error(error); + return Response.json( + { message: "Internal Server Error", success: false }, + { status: 500 } + ); + } +} diff --git a/src/module/group/api/get/listGroup.ts b/src/module/group/api/get/listGroup.ts new file mode 100644 index 0000000..2e242e0 --- /dev/null +++ b/src/module/group/api/get/listGroup.ts @@ -0,0 +1,20 @@ +import { prisma } from "@/module/_global"; + +export async function listGroup(req: Request): Promise { + try { + const groups = await prisma.group.findMany({ + where: { + isActive: true, + }, + select: { + id: true, + name: true, + }, + }); + + return Response.json(groups); + } catch (error) { + console.error(error); + return Response.json({ message: "Internal Server Error" }, { status: 500 }); + } +} diff --git a/src/module/group/api/post/createGroup.ts b/src/module/group/api/post/createGroup.ts new file mode 100644 index 0000000..d42ca5a --- /dev/null +++ b/src/module/group/api/post/createGroup.ts @@ -0,0 +1,32 @@ +import { prisma } from "@/module/_global"; + +export async function createGroup(req: Request){ + try { + const data = await req.json(); + + + if (!data || !data.name) { + return Response.json( + { message: "Nama grup harus diisi" }, + { status: 400 } + ); + } + + const group = await prisma.group.create({ + data: { + name: data.name, + isActive: true, + idVillage: data.idVillage, + }, + select: { + id: true, + name: true, + }, + }); + + return Response.json(group, { status: 201 }); + } catch (error) { + console.error(error); + return Response.json({ message: "Internal Server Error" }, { status: 500 }); + } +} diff --git a/src/module/group/api/post/deleteGroup.ts b/src/module/group/api/post/deleteGroup.ts new file mode 100644 index 0000000..8c4ef2f --- /dev/null +++ b/src/module/group/api/post/deleteGroup.ts @@ -0,0 +1,19 @@ +import { prisma } from "@/module/_global"; + +export async function deleteGroup(req: Request) { + try { + const data = await req.json(); + const update = await prisma.group.update({ + where: { + id: data.id, + }, + data: { + isActive: false, + }, + }); + return Response.json({ success: true, message: "Sukses Delete Grup" }, { status: 200 }); + } catch (error) { + console.error(error); + return Response.json({ message: "Internal Server Error", success: false }, { status: 500 }); + } +} diff --git a/src/module/group/api/post/updateGroup.ts b/src/module/group/api/post/updateGroup.ts new file mode 100644 index 0000000..15a2601 --- /dev/null +++ b/src/module/group/api/post/updateGroup.ts @@ -0,0 +1,21 @@ +import { prisma } from "@/module/_global"; + +export async function updateGroup(req: Request) { + try { + const data = await req.json(); + + const update = await prisma.group.update({ + where: { + id: data.id, + }, + data: { + name: data.name, + idVillage: data.idVillage, + }, + }); + return Response.json({ success: true, message: "Sukses Update Grup" }, { status: 200 }); + } catch (error) { + console.error(error); + return Response.json({ message: "Internal Server Error", success: false }, { status: 500 }); + } +} diff --git a/src/module/group/index.ts b/src/module/group/index.ts index 0fac4e6..cd3d4be 100644 --- a/src/module/group/index.ts +++ b/src/module/group/index.ts @@ -1,3 +1,5 @@ +import { apiGroup } from "./api/api_group"; import ViewGroup from "./view/view_group"; -export {ViewGroup} \ No newline at end of file +export { ViewGroup }; +export { apiGroup }; diff --git a/src/module/position/api/api_index.ts b/src/module/position/api/api_index.ts new file mode 100644 index 0000000..ba37ee9 --- /dev/null +++ b/src/module/position/api/api_index.ts @@ -0,0 +1,34 @@ +import { getAllPosition } from "./get/getAllPosition"; +import { getOnePosition } from "./get/getOnePosition"; +import { createlPosition } from "./post/createPosition"; +import { deletePosition } from "./post/deletePosition"; +import { updatePosition } from "./post/updatePosition"; + +export const API_INDEX_POSITION = [ + { + path: "get-all-position", + method: "GET", + bin: getAllPosition, + }, + { + path: "create-position", + method: "POST", + bin: createlPosition, + }, + { + path: "update-position", + method: "POST", + bin: updatePosition, + }, + { + path: "delete-position", + method: "POST", + bin: deletePosition, + }, + { + path: "get-one-position", + method: "GET", + bin: getOnePosition, + }, + ]; + \ No newline at end of file diff --git a/src/module/position/api/api_position.ts b/src/module/position/api/api_position.ts new file mode 100644 index 0000000..d9b984a --- /dev/null +++ b/src/module/position/api/api_position.ts @@ -0,0 +1,14 @@ +import { API_INDEX_POSITION } from "./api_index"; + + +type Method = "GET" | "POST"; +export async function apiPosition(req: Request, 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); + if (!path) + return Response.json({ message: "page not found" }, { status: 404 }); + if (act) return act.bin(req); + + return Response.json({ message: "404" }); + } \ No newline at end of file diff --git a/src/module/position/api/get/getAllPosition.ts b/src/module/position/api/get/getAllPosition.ts new file mode 100644 index 0000000..476a32a --- /dev/null +++ b/src/module/position/api/get/getAllPosition.ts @@ -0,0 +1,20 @@ +import { prisma } from "@/module/_global"; + +export async function getAllPosition(req: Request) { + try { + const positions = await prisma.position.findMany({ + where: { + isActive: true, + }, + select: { + id: true, + name: true, + }, + }); + + return Response.json(positions); + } catch (error) { + console.error(error); + return Response.json({ message: "Internal Server Error" }, { status: 500 }); + } +} diff --git a/src/module/position/api/get/getOnePosition.ts b/src/module/position/api/get/getOnePosition.ts new file mode 100644 index 0000000..c499f62 --- /dev/null +++ b/src/module/position/api/get/getOnePosition.ts @@ -0,0 +1,24 @@ +import { prisma } from "@/module/_global"; + +export async function getOnePosition(req: Request) { + try { + const positionId = "2"; + const getOne = await prisma.position.findUnique({ + where: { + id: positionId, + }, + select: { + id: true, + name: true, + }, + }); + + return Response.json(getOne); + } catch (error) { + console.error(error); + return Response.json( + { message: "Internal Server Error", success: false }, + { status: 500 } + ); + } +} diff --git a/src/module/position/api/post/createPosition.ts b/src/module/position/api/post/createPosition.ts new file mode 100644 index 0000000..d40f444 --- /dev/null +++ b/src/module/position/api/post/createPosition.ts @@ -0,0 +1,24 @@ +import { prisma } from "@/module/_global"; + +export async function createlPosition(req: Request) { + try { + const data = await req.json(); + + const positions = await prisma.position.create({ + data: { + name: data.name, + isActive: true, + idGroup: data.idGroup, + }, + select: { + id: true, + name: true, + }, + }); + + return Response.json(positions, { status: 201 }); + } catch (error) { + console.error(error); + return Response.json({ message: "Internal Server Error" }, { status: 500 }); + } +} diff --git a/src/module/position/api/post/deletePosition.ts b/src/module/position/api/post/deletePosition.ts new file mode 100644 index 0000000..9516fe6 --- /dev/null +++ b/src/module/position/api/post/deletePosition.ts @@ -0,0 +1,27 @@ +import { prisma } from "@/module/_global"; + +export async function deletePosition(req: Request) { + try { + const data = await req.json(); + + const update = await prisma.position.update({ + where: { + id: data.id, + }, + data: { + isActive: false, + }, + }); + + return Response.json( + { success: true, message: "Sukses Delete Position" }, + { status: 200 } + ); + } catch (error) { + console.error(error); + return Response.json( + { message: "Internal Server Error", success: false }, + { status: 500 } + ); + } +} diff --git a/src/module/position/api/post/updatePosition.ts b/src/module/position/api/post/updatePosition.ts new file mode 100644 index 0000000..806de8f --- /dev/null +++ b/src/module/position/api/post/updatePosition.ts @@ -0,0 +1,22 @@ +import { prisma } from "@/module/_global" + +export async function updatePosition(req: Request) { + try { + const data = await req.json() + + const update = await prisma.position.update({ + where: { + id: data.id + }, + data: { + name: data.name, + idGroup: data.idGroup + } + }) + + return Response.json({ success: true, message: "Sukses Update Position" }, { status: 200 }); + } catch (error) { + console.error(error); + return Response.json({ message: "Internal Server Error", success: false }, { status: 500 }); + } +} \ No newline at end of file diff --git a/src/module/position/index.ts b/src/module/position/index.ts index f77009c..bf46432 100644 --- a/src/module/position/index.ts +++ b/src/module/position/index.ts @@ -1,3 +1,5 @@ +import { apiPosition } from "./api/api_position"; import ViewListPosition from "./view/view_list_position"; -export { ViewListPosition } \ No newline at end of file +export { ViewListPosition }; +export { apiPosition }; diff --git a/src/module/village/api/api_index.ts b/src/module/village/api/api_index.ts new file mode 100644 index 0000000..9fd6f2f --- /dev/null +++ b/src/module/village/api/api_index.ts @@ -0,0 +1,36 @@ + + +import { getAllVillage } from "./get/getAllVillage"; +import { getOneVillage } from "./get/getOneVillage"; +import { createVillage } from "./post/createVillage"; +import { deleteVillage } from "./post/deleteVillage"; +import { updateVillage } from "./post/updateVillage"; + +export const API_INDEX_VILLAGE = [ + { + path: "get-all-village", + method: "GET", + bin: getAllVillage, + }, + { + path: "create-village", + method: "POST", + bin: createVillage, + }, + { + path: "update-village", + method: "POST", + bin: updateVillage, + }, + { + path: "delete-village", + method: "POST", + bin: deleteVillage, + }, + { + path: "get-one-village", + method: "GET", + bin: getOneVillage, + }, + ]; + \ No newline at end of file diff --git a/src/module/village/api/api_village.ts b/src/module/village/api/api_village.ts new file mode 100644 index 0000000..f34cdcf --- /dev/null +++ b/src/module/village/api/api_village.ts @@ -0,0 +1,15 @@ +import { API_INDEX_VILLAGE } from "./api_index"; + +type Method = "GET" | "POST"; +export async function apiViilage(req: Request, method: Method) { + const { searchParams } = new URL(req.url); + const path = searchParams.get("path"); + const act = API_INDEX_VILLAGE.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" }); +} diff --git a/src/module/village/api/get/getAllVillage.ts b/src/module/village/api/get/getAllVillage.ts new file mode 100644 index 0000000..25ee240 --- /dev/null +++ b/src/module/village/api/get/getAllVillage.ts @@ -0,0 +1,21 @@ +import { prisma } from "@/module/_global"; + +export async function getAllVillage(req: Request) { + try { + const villages = await prisma.village.findMany({ + where: { + isActive: true, + }, + select: { + id: true, + name: true, + desc: true, + }, + }); + + return Response.json(villages); + } catch (error) { + console.error(error); + return Response.json({ message: "Internal Server Error" }, { status: 500 }); + } +} diff --git a/src/module/village/api/get/getOneVillage.ts b/src/module/village/api/get/getOneVillage.ts new file mode 100644 index 0000000..15e22d6 --- /dev/null +++ b/src/module/village/api/get/getOneVillage.ts @@ -0,0 +1,32 @@ +import { prisma } from "@/module/_global"; + +export async function getOneVillage(req: Request) { + try { + const village = "11"; + const getOne = await prisma.village.findUnique({ + where: { + id: village, + }, + select: { + id: true, + name: true, + desc: true, + }, + }); + + if (!getOne) { + return Response.json( + { message: "Village tidak ditemukan", success: false }, + { status: 404 } + ); + } + + return Response.json(getOne); + } catch (error) { + console.error(error); + return Response.json( + { message: "Internal Server Error", success: false }, + { status: 500 } + ); + } +} diff --git a/src/module/village/api/post/createVillage.ts b/src/module/village/api/post/createVillage.ts new file mode 100644 index 0000000..b98d2bf --- /dev/null +++ b/src/module/village/api/post/createVillage.ts @@ -0,0 +1,24 @@ +import { prisma } from "@/module/_global"; + +export async function createVillage(req: Request) { + try { + const data = await req.json(); + const village = await prisma.village.create({ + data: { + name: data.name, + desc: data.desc, + isActive: true, + }, + select: { + id: true, + name: true, + desc: true, + }, + }); + + return Response.json(village, { status: 201 }); + } catch (error) { + console.error(error); + return Response.json({ message: "Internal Server Error" }, { status: 500 }); + } +} diff --git a/src/module/village/api/post/deleteVillage.ts b/src/module/village/api/post/deleteVillage.ts new file mode 100644 index 0000000..a89808f --- /dev/null +++ b/src/module/village/api/post/deleteVillage.ts @@ -0,0 +1,25 @@ +import { prisma } from "@/module/_global"; + +export async function deleteVillage(req: Request) { + try { + const data = await req.json(); + const update = await prisma.village.update({ + where: { + id: data.id, + }, + data: { + isActive: false, + }, + }); + return Response.json( + { success: true, message: "Sukses Delete Village" }, + { status: 200 } + ); + } catch (error) { + console.error(error); + return Response.json( + { message: "Internal Server Error", success: false }, + { status: 500 } + ); + } +} diff --git a/src/module/village/api/post/updateVillage.ts b/src/module/village/api/post/updateVillage.ts new file mode 100644 index 0000000..4f229b6 --- /dev/null +++ b/src/module/village/api/post/updateVillage.ts @@ -0,0 +1,28 @@ +import { prisma } from "@/module/_global"; + +export async function updateVillage(req: Request) { + try { + const data = await req.json(); + + const update = await prisma.village.update({ + where: { + id: data.id, + }, + data: { + name: data.name, + desc: data.desc, + }, + }); + + return Response.json( + { success: true, message: "Sukses Update Village" }, + { status: 200 } + ); + } catch (error) { + console.error(error); + return Response.json( + { message: "Internal Server Error", success: false }, + { status: 500 } + ); + } +} diff --git a/src/module/village/index.ts b/src/module/village/index.ts index e69de29..89437ae 100644 --- a/src/module/village/index.ts +++ b/src/module/village/index.ts @@ -0,0 +1,3 @@ +import { apiViilage } from "./api/api_village"; + +export { apiViilage }; diff --git a/src/types/index.ts b/src/types/index.ts index 6be00a1..52008ce 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,5 +2,9 @@ import { Login } from '@/types/auth/login'; import { Verification } from './auth/varification'; -export type ILogin = Login +export type ILogin = { + phone: string + id: string, +} + export type IVerification = Verification \ No newline at end of file