varierty of implementstions based on platform droplet issuance
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -6,10 +6,10 @@ const RESOURCES: Record<
|
||||
string,
|
||||
{ col: string; listFilter: (famId: string) => string; bonus?: 'config' | 'template' }
|
||||
> = {
|
||||
'chore-templates': { col: 'chore_templates', listFilter: (f) => `famId = '${f}'` },
|
||||
'chore-templates': { col: 'chore_templates', listFilter: (f) => `(famId = '${f}' || global = true)` },
|
||||
members: { col: 'users', listFilter: (f) => `famId = '${f}' && role = 'child'` },
|
||||
'assigned-chores': { col: 'assigned_chores', listFilter: (f) => `famId = '${f}'` },
|
||||
'bonus-templates': { col: 'bonus_templates', listFilter: (f) => `famId = '${f}'`, bonus: 'template' },
|
||||
'bonus-templates': { col: 'bonus_templates', listFilter: (f) => `(famId = '${f}' || global = true)`, bonus: 'template' },
|
||||
'bonus-configs': { col: 'bonus_configs', listFilter: (f) => `famId = '${f}'`, bonus: 'config' },
|
||||
completions: { col: 'completions', listFilter: (f) => `famId = '${f}'` },
|
||||
rewards: { col: 'rewards', listFilter: (f) => `famId = '${f}'` },
|
||||
|
||||
Reference in New Issue
Block a user