fix bugs
This commit is contained in:
@@ -55,14 +55,13 @@ export async function toggle(pb: any, famId: string, memberId: string, body: { a
|
||||
const chore = choreList?.[0];
|
||||
const isTodo = chore?.isTodo;
|
||||
const isShared = chore?.shared === true || !chore?.memberId;
|
||||
// Only one-off shared todos are claimed (winner takes it). Recurring
|
||||
// shared chores stay unassigned so every member completes independently
|
||||
// each period — claiming them permanently hides the chore from siblings.
|
||||
const isClaimable = isShared && !!isTodo;
|
||||
|
||||
let filter: string;
|
||||
if (isShared && !isTodo) {
|
||||
// Shared non-todo: any completion in the period = already claimed
|
||||
const { payday, tz } = await famMetaSU(famId);
|
||||
const { from, to } = periodWindow(chore?.frequency, payday, tz);
|
||||
filter = `assignedChoreId = '${assignedChoreId}' && date >= '${from}' && date < '${to}'`;
|
||||
} else if (isTodo) {
|
||||
if (isTodo) {
|
||||
filter = `assignedChoreId = '${assignedChoreId}' && memberId = '${memberId}'`;
|
||||
} else {
|
||||
const { payday, tz } = await famMetaSU(famId);
|
||||
@@ -78,8 +77,8 @@ export async function toggle(pb: any, famId: string, memberId: string, body: { a
|
||||
if (isTodo && existing[0].rewardId) {
|
||||
await pb.collection('rewards').delete(existing[0].rewardId).catch(() => {});
|
||||
}
|
||||
// If this was a shared chore claimed by this member, un-share it
|
||||
if (isShared && existing[0].memberId === memberId) {
|
||||
// If this was a claimed one-off todo, release it back to shared.
|
||||
if (isClaimable && existing[0].memberId === memberId) {
|
||||
await claimChore(assignedChoreId, famId, '');
|
||||
}
|
||||
evaluateFam(pb, famId).catch(() => {});
|
||||
@@ -107,8 +106,9 @@ export async function toggle(pb: any, famId: string, memberId: string, body: { a
|
||||
completedAt: new Date().toISOString(),
|
||||
...(rewardId ? { rewardId } : {})
|
||||
});
|
||||
// Claim the shared chore by setting memberId
|
||||
if (isShared) {
|
||||
// Claim a shared one-off todo by setting memberId (recurring shared
|
||||
// chores stay unassigned — see isClaimable above).
|
||||
if (isClaimable) {
|
||||
await claimChore(assignedChoreId, famId, memberId);
|
||||
}
|
||||
evaluateFam(pb, famId).catch(() => {});
|
||||
|
||||
Reference in New Issue
Block a user