31 lines
852 B
TypeScript
31 lines
852 B
TypeScript
import { IEditUserForm } from "@/app/features/UserRoles/User.interfaces";
|
|
|
|
export async function addUser(data: IEditUserForm) {
|
|
const res = await fetch("/api/auth/register", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(data),
|
|
});
|
|
|
|
if (!res.ok) {
|
|
throw new Error("Failed to create role");
|
|
}
|
|
|
|
return res.json(); // or return type depending on your backend
|
|
}
|
|
export async function editUser(id: string, data: IEditUserForm) {
|
|
console.log("[editUser] - id", id, data);
|
|
const res = await fetch(`/api/dashboard/admin/users/${id}`, {
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(data),
|
|
});
|
|
|
|
if (!res.ok) {
|
|
console.log("[editUser] - FAILING", id, data);
|
|
throw new Error("Failed to update user");
|
|
}
|
|
|
|
return res.json();
|
|
}
|