45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { getAccessToken } from "@/lib/session";
|
|
|
|
const API_BASE_URL =
|
|
process.env.NEXT_PUBLIC_MARKETPLACE_API_URL?.replace(/\/$/, "") ||
|
|
"http://localhost:3001/api/v1";
|
|
|
|
export async function registerShop(body: {
|
|
name: string;
|
|
slug?: string;
|
|
about?: string;
|
|
meshkeeCategoryIds?: string[];
|
|
ownerPassword: string;
|
|
}) {
|
|
const token = getAccessToken();
|
|
if (!token) {
|
|
throw new Error("Sign in required");
|
|
}
|
|
|
|
const response = await fetch(`${API_BASE_URL}/businesses/register-shop`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
body: JSON.stringify(body),
|
|
});
|
|
|
|
const payload = await response.json().catch(() => null);
|
|
if (!response.ok) {
|
|
const message =
|
|
typeof payload?.message === "string"
|
|
? payload.message
|
|
: Array.isArray(payload?.message)
|
|
? payload.message.join(", ")
|
|
: `Registration failed (${response.status})`;
|
|
throw new Error(message);
|
|
}
|
|
|
|
return payload as {
|
|
listing: { id: string; slug: string; status: string };
|
|
meshkeeBusinessId: string;
|
|
message: string;
|
|
};
|
|
}
|