Fix onboarding SQL column names

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Manohar Gupta 2026-05-17 00:15:51 +05:30
parent e7a5de3cc2
commit 514b115326

View file

@ -24,34 +24,39 @@ export async function POST(request: Request) {
const body = await request.json(); const body = await request.json();
const { familyName, memberName, childName, birthDate, sex } = body; const { familyName, memberName, childName, birthDate, sex } = body;
// Create family try {
const familyId = crypto.randomUUID(); // Create family
await sql` const familyId = crypto.randomUUID();
INSERT INTO families (id, name, tier, max_children, max_members, created_at, updated_at) await sql.unsafe(
VALUES (${familyId}, ${familyName || "The Family"}, 'free', 3, 4, NOW(), NOW()) `INSERT INTO families (id, name, tier, created_at, updated_at) VALUES ($1, $2, 'free', NOW(), NOW())`,
`; [familyId, familyName || "The Family"]
);
// Add member // Add member
await sql` await sql.unsafe(
INSERT INTO family_members (id, family_id, user_id, role, display_name, created_at) `INSERT INTO family_members (id, family_id, user_id, role, display_name, created_at) VALUES ($1, $2, $3, 'admin', $4, NOW())`,
VALUES (${crypto.randomUUID()}, ${familyId}, ${userId}, 'admin', ${memberName}, NOW()) [crypto.randomUUID(), familyId, userId, memberName]
`; );
// Create child // Create child
const childId = crypto.randomUUID(); const childId = crypto.randomUUID();
const birth = new Date(birthDate); const birth = new Date(birthDate);
const months = Math.floor((Date.now() - birth.getTime()) / (1000 * 60 * 60 * 24 * 30)); const months = Math.floor((Date.now() - birth.getTime()) / (1000 * 60 * 60 * 24 * 30));
let stage = "newborn"; let stage = "newborn";
if (months >= 36) stage = "preschool"; if (months >= 36) stage = "preschool";
else if (months >= 24) stage = "toddler_late"; else if (months >= 24) stage = "toddler_late";
else if (months >= 12) stage = "toddler_early"; else if (months >= 12) stage = "toddler_early";
else if (months >= 6) stage = "solids_start"; else if (months >= 6) stage = "solids_start";
else if (months >= 3) stage = "infant"; else if (months >= 3) stage = "infant";
await sql` await sql.unsafe(
INSERT INTO children (id, family_id, name, birth_date, sex, current_stage, created_at) `INSERT INTO children (id, family_id, name, birth_date, sex, current_stage, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, NOW(), NOW())`,
VALUES (${childId}, ${familyId}, ${childName}, ${birth.toISOString()}, ${sex}, ${stage}, NOW()) [childId, familyId, childName, birth.toISOString(), sex, stage]
`; );
return NextResponse.json({ success: true, childId, familyId }); return NextResponse.json({ success: true, childId, familyId });
} catch (error) {
console.error("Onboarding error:", error);
return NextResponse.json({ error: String(error) }, { status: 500 });
}
} }