fix bonus completeions

This commit is contained in:
JCEEE
2026-09-14 13:00:13 +01:00
parent e441c3d2a7
commit da6a6e372c
7 changed files with 60 additions and 12 deletions
+13 -1
View File
@@ -252,8 +252,20 @@ export async function evaluateFam(pb: any, famId: string) {
}
if (cfg.occurrence === 'once' && (existingRewards.length > 0 || createdReward)) {
// Status write via superuser: evaluate often runs as a child token
// (fire-and-forget after a chore toggle) and bonus_configs updates
// are parent-only — the user-token write 403s and the config stays
// `active` forever. Stamp who earned it + when.
const earner =
existingRewards.find((r: any) => r.memberId)?.memberId ||
allMembers[0]?.id ||
'auto';
try {
await pb.collection('bonus_configs').update(cfg.id, { status: 'completed' });
await pbAdmin.update('bonus_configs', cfg.id, {
status: 'completed',
completedAt: new Date().toISOString().slice(0, 10),
completedBy: earner
});
} catch {}
}
}