Fix onboarding SQL column names
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
e7a5de3cc2
commit
514b115326
1 changed files with 31 additions and 26 deletions
|
|
@ -24,18 +24,19 @@ 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;
|
||||||
|
|
||||||
|
try {
|
||||||
// Create family
|
// Create family
|
||||||
const familyId = crypto.randomUUID();
|
const familyId = crypto.randomUUID();
|
||||||
await sql`
|
await sql.unsafe(
|
||||||
INSERT INTO families (id, name, tier, max_children, max_members, created_at, updated_at)
|
`INSERT INTO families (id, name, tier, created_at, updated_at) VALUES ($1, $2, 'free', NOW(), NOW())`,
|
||||||
VALUES (${familyId}, ${familyName || "The Family"}, 'free', 3, 4, 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();
|
||||||
|
|
@ -48,10 +49,14 @@ export async function POST(request: Request) {
|
||||||
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 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue