This commit is contained in:
@@ -12,15 +12,33 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
|
||||
|
||||
let name: string | undefined;
|
||||
let email: string | undefined;
|
||||
let phone: string | undefined;
|
||||
let street: string | undefined;
|
||||
let city: string | undefined;
|
||||
let state: string | undefined;
|
||||
let zip: string | undefined;
|
||||
let country: string | undefined;
|
||||
|
||||
if (request.headers.get("Content-Type")?.includes("application/json")) {
|
||||
const body = await request.json();
|
||||
name = body.name;
|
||||
email = body.email;
|
||||
phone = body.phone;
|
||||
street = body.street;
|
||||
city = body.city;
|
||||
state = body.state;
|
||||
zip = body.zip;
|
||||
country = body.country;
|
||||
} else {
|
||||
const formData = await request.formData();
|
||||
name = formData.get("name")?.toString();
|
||||
email = formData.get("email")?.toString();
|
||||
phone = formData.get("phone")?.toString();
|
||||
street = formData.get("street")?.toString();
|
||||
city = formData.get("city")?.toString();
|
||||
state = formData.get("state")?.toString();
|
||||
zip = formData.get("zip")?.toString();
|
||||
country = formData.get("country")?.toString();
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
@@ -44,13 +62,32 @@ export const POST: APIRoute = async ({ request, locals, redirect }) => {
|
||||
organizationId: userOrg.organizationId,
|
||||
name,
|
||||
email: email || null,
|
||||
phone: phone || null,
|
||||
street: street || null,
|
||||
city: city || null,
|
||||
state: state || null,
|
||||
zip: zip || null,
|
||||
country: country || null,
|
||||
});
|
||||
|
||||
if (locals.scopes) {
|
||||
return new Response(JSON.stringify({ id, name, email: email || null }), {
|
||||
status: 201,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
id,
|
||||
name,
|
||||
email: email || null,
|
||||
phone: phone || null,
|
||||
street: street || null,
|
||||
city: city || null,
|
||||
state: state || null,
|
||||
zip: zip || null,
|
||||
country: country || null,
|
||||
}),
|
||||
{
|
||||
status: 201,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return redirect("/dashboard/clients");
|
||||
|
||||
Reference in New Issue
Block a user