completionId: cgen-f397a58d211b4147ab5db5a0646acafb

cgen-f397a58d211b4147ab5db5a0646acafb
This commit is contained in:
Builder.io 2025-11-17 02:50:21 +00:00
parent e141e68ef4
commit 43f0ef5ac1

View file

@ -131,11 +131,49 @@ export async function createCreatorProfile(req: Request, userId: string) {
spotify_profile_url,
} = body;
// Validate required fields
if (!username || typeof username !== "string" || username.trim().length === 0) {
return new Response(
JSON.stringify({ error: "Username is required and must be a non-empty string" }),
{ status: 400, headers: { "Content-Type": "application/json" } },
);
}
if (!experience_level) {
return new Response(
JSON.stringify({ error: "Experience level is required" }),
{ status: 400, headers: { "Content-Type": "application/json" } },
);
}
if (!primary_arm) {
return new Response(
JSON.stringify({ error: "Primary arm is required" }),
{ status: 400, headers: { "Content-Type": "application/json" } },
);
}
const normalizedUsername = username.trim().toLowerCase();
// Check if username already exists
const { data: existingCreator } = await supabase
.from("aethex_creators")
.select("id")
.eq("username", normalizedUsername)
.single();
if (existingCreator) {
return new Response(
JSON.stringify({ error: "Username is already taken" }),
{ status: 409, headers: { "Content-Type": "application/json" } },
);
}
const { data, error } = await supabase
.from("aethex_creators")
.insert({
user_id: userId,
username,
username: normalizedUsername,
bio,
skills: skills || [],
avatar_url,