temp: surface DB error in circles POST for diagnostics
This commit is contained in:
parent
d8bda20887
commit
acb9d66815
1 changed files with 15 additions and 11 deletions
|
|
@ -34,17 +34,21 @@ export async function POST(request: Request) {
|
||||||
return NextResponse.json({ error: "Circle name is required" }, { status: 400 });
|
return NextResponse.json({ error: "Circle name is required" }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const [circle] = await sql.unsafe(
|
const [circle] = await sql.unsafe(
|
||||||
`INSERT INTO circles (name, created_by) VALUES ($1, $2)
|
`INSERT INTO circles (name, created_by) VALUES ($1, $2)
|
||||||
RETURNING id, name, created_by as "createdBy", created_at as "createdAt"`,
|
RETURNING id, name, created_by as "createdBy", created_at as "createdAt"`,
|
||||||
[name.trim(), familyId]
|
[name.trim(), familyId]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Creator is automatically an admin member
|
|
||||||
await sql.unsafe(
|
await sql.unsafe(
|
||||||
`INSERT INTO circle_members (circle_id, family_id, role) VALUES ($1, $2, 'admin')`,
|
`INSERT INTO circle_members (circle_id, family_id, role) VALUES ($1, $2, 'admin')`,
|
||||||
[circle.id, familyId]
|
[circle.id, familyId]
|
||||||
);
|
);
|
||||||
|
|
||||||
return NextResponse.json({ success: true, circle: { ...circle, role: "admin", memberCount: 1 } });
|
return NextResponse.json({ success: true, circle: { ...circle, role: "admin", memberCount: 1 } });
|
||||||
|
} catch (err: unknown) {
|
||||||
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
|
return NextResponse.json({ error: msg }, { status: 500 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue