upd: update status api

Deskripsi:
update database
- update status success respon api group

No Issues
This commit is contained in:
amel
2024-07-29 12:00:49 +08:00
parent 5a03d259b1
commit 9dd8611992
4 changed files with 36 additions and 34 deletions

View File

@@ -3,12 +3,12 @@ import { API_INDEX_GROUP } from "./api_index";
type Method = "GET" | "POST";
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);
if (!path)
return Response.json({ message: "page not found" }, { status: 404 });
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({ success: false, message: "page not found" }, { status: 404 });
if (act) return act.bin(req);
return Response.json({ message: "404" });
}
return Response.json({ success: false, message: "404" });
}

View File

@@ -2,7 +2,7 @@ import { prisma } from "@/module/_global";
import { NextRequest } from "next/server";
export async function listGroups(req: NextRequest): Promise<Response> {
try {
const searchParams = req.nextUrl.searchParams
const villaId = searchParams.get('villageId');
@@ -20,6 +20,6 @@ export async function listGroups(req: NextRequest): Promise<Response> {
return Response.json(groups);
} catch (error) {
console.error(error);
return Response.json({ message: "Internal Server Error" }, { status: 500 });
return Response.json({ success: false, message: "Internal Server Error" }, { status: 500 });
}
}

View File

@@ -1,13 +1,13 @@
import { prisma } from "@/module/_global";
export async function createGroup(req: Request){
export async function createGroup(req: Request) {
try {
const data = await req.json();
const data = await req.json();
if (!data || !data.name) {
return Response.json(
{ message: "Nama grup harus diisi" },
{ success: false, message: "Nama grup harus diisi" },
{ status: 400 }
);
}
@@ -27,6 +27,6 @@ export async function createGroup(req: Request){
return Response.json(group, { status: 201 });
} catch (error) {
console.error(error);
return Response.json({ message: "Internal Server Error" }, { status: 500 });
return Response.json({ success: false, message: "Internal Server Error" }, { status: 500 });
}
}