temp: surface DB error in circles POST for diagnostics

This commit is contained in:
Manohar Gupta 2026-05-24 01:31:26 +05:30
parent d8bda20887
commit acb9d66815

View file

@ -34,17 +34,21 @@ export async function POST(request: Request) {
return NextResponse.json({ error: "Circle name is required" }, { status: 400 });
}
try {
const [circle] = await sql.unsafe(
`INSERT INTO circles (name, created_by) VALUES ($1, $2)
RETURNING id, name, created_by as "createdBy", created_at as "createdAt"`,
[name.trim(), familyId]
);
// Creator is automatically an admin member
await sql.unsafe(
`INSERT INTO circle_members (circle_id, family_id, role) VALUES ($1, $2, 'admin')`,
[circle.id, familyId]
);
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 });
}
}