upd: respon api

Deskripsi:
- update respon api

halaman user

No Issues
This commit is contained in:
amel
2024-07-29 12:27:01 +08:00
parent 796c3227f0
commit 39b1b5e416
3 changed files with 10 additions and 10 deletions

View File

@@ -4,12 +4,12 @@ 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 });
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({ 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

@@ -31,6 +31,6 @@ export async function getAllUser(req: NextRequest) {
return Response.json(users);
} 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

@@ -30,6 +30,6 @@ export async function createUser(req: NextRequest) {
return Response.json(users, { status: 200 });
} 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 });
}
}