varierty of implementstions based on platform droplet issuance

This commit is contained in:
JCEEE
2026-08-26 10:17:32 +01:00
parent 7ebabc6e62
commit 8fea21704a
16 changed files with 1118 additions and 452 deletions
@@ -53,15 +53,33 @@ export async function toggle(pb: any, famId: string, memberId: string, body: { a
.getFullList({ filter });
if (existing?.length > 0) {
await pb.collection('completions').delete(existing[0].id);
// Un-completing a cash todo removes its one-time reward.
if (isTodo && existing[0].rewardId) {
await pb.collection('rewards').delete(existing[0].rewardId).catch(() => {});
}
evaluateFam(pb, famId).catch(() => {});
return { completed: false };
}
let rewardId: string | undefined;
if (isTodo && chore?.type === 'money' && Number(chore.value) > 0) {
const reward = await pb.collection('rewards').create({
famId,
memberId,
label: chore.customName || 'Cash todo',
value: Number(chore.value),
rewardType: 'cash',
status: 'unclaimed',
date
});
rewardId = reward.id;
}
const record = await pb.collection('completions').create({
famId,
memberId,
assignedChoreId,
date,
completedAt: new Date().toISOString()
completedAt: new Date().toISOString(),
...(rewardId ? { rewardId } : {})
});
evaluateFam(pb, famId).catch(() => {});
return { completed: true, record };