fix chore count rewards for members
This commit is contained in:
@@ -522,20 +522,21 @@
|
||||
(c) => c.memberId === memberId && completionInWindow(c, win)
|
||||
);
|
||||
|
||||
// Percent thresholds are "X% of the chores done this period" — the
|
||||
// natural unit is chore COUNT. Absolute thresholds keep their own
|
||||
// unit (count for type 'count', points for type 'threshold').
|
||||
const isPercent = cfg.thresholdType === 'percent';
|
||||
const isCount = cfg.type === 'count';
|
||||
|
||||
// Resolve the per-member target chore (multi-target map wins,
|
||||
// then the legacy scalar targetChoreId).
|
||||
const memberTargetChoreId =
|
||||
(cfg.targetChoreIds && cfg.targetChoreIds[memberId]) || cfg.targetChoreId || '';
|
||||
|
||||
// Count-type rewards pinned to a single chore scoped their count
|
||||
// (and the period's reclaimable potential) to that chore only.
|
||||
const countChores = isCount && cfg.targetChoreId
|
||||
? myChores.filter((a) => a.id === cfg.targetChoreId)
|
||||
: myChores;
|
||||
const countChores =
|
||||
isCount && memberTargetChoreId
|
||||
? myChores.filter((a) => a.id === memberTargetChoreId)
|
||||
: myChores;
|
||||
|
||||
// Frequency-aware total potential (a daily chore = `periodDays`
|
||||
// instances, a weekly chore = 1).
|
||||
const totalPotential = countChores.reduce(
|
||||
(sum, a) => sum + (a.frequency === 'daily' ? periodDays : 1),
|
||||
0
|
||||
@@ -545,8 +546,8 @@
|
||||
if (isPercent) {
|
||||
current = periodCompletions.length;
|
||||
} else if (isCount) {
|
||||
current = cfg.targetChoreId
|
||||
? periodCompletions.filter((c) => c.assignedChoreId === cfg.targetChoreId).length
|
||||
current = memberTargetChoreId
|
||||
? periodCompletions.filter((c) => c.assignedChoreId === memberTargetChoreId).length
|
||||
: periodCompletions.length;
|
||||
} else {
|
||||
current = periodCompletions.reduce((sum, c) => {
|
||||
|
||||
Reference in New Issue
Block a user