Use proper upsert for awarding achievements to avoid duplicate key errors

cgen-5db038e31ab84dcd92d09aa52e4a0291
This commit is contained in:
Builder.io 2025-09-28 07:14:49 +00:00
parent caef767bf9
commit 2b8e99ca8e

View file

@ -214,7 +214,7 @@ export function createServer() {
if (!rows.length) return res.json({ ok: true, awarded: [] });
const { error: iErr } = await adminSupabase
.from("user_achievements")
.insert(rows, { upsert: true });
.upsert(rows, { onConflict: "user_id,achievement_id" as any });
if (iErr && iErr.code !== "23505")
return res.status(500).json({ error: iErr.message });
return res.json({ ok: true, awarded: rows.length });