fix chore count rewards for members
This commit is contained in:
@@ -522,20 +522,21 @@
|
|||||||
(c) => c.memberId === memberId && completionInWindow(c, win)
|
(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 isPercent = cfg.thresholdType === 'percent';
|
||||||
const isCount = cfg.type === 'count';
|
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
|
// Count-type rewards pinned to a single chore scoped their count
|
||||||
// (and the period's reclaimable potential) to that chore only.
|
// (and the period's reclaimable potential) to that chore only.
|
||||||
const countChores = isCount && cfg.targetChoreId
|
const countChores =
|
||||||
? myChores.filter((a) => a.id === cfg.targetChoreId)
|
isCount && memberTargetChoreId
|
||||||
|
? myChores.filter((a) => a.id === memberTargetChoreId)
|
||||||
: myChores;
|
: myChores;
|
||||||
|
|
||||||
// Frequency-aware total potential (a daily chore = `periodDays`
|
|
||||||
// instances, a weekly chore = 1).
|
|
||||||
const totalPotential = countChores.reduce(
|
const totalPotential = countChores.reduce(
|
||||||
(sum, a) => sum + (a.frequency === 'daily' ? periodDays : 1),
|
(sum, a) => sum + (a.frequency === 'daily' ? periodDays : 1),
|
||||||
0
|
0
|
||||||
@@ -545,8 +546,8 @@
|
|||||||
if (isPercent) {
|
if (isPercent) {
|
||||||
current = periodCompletions.length;
|
current = periodCompletions.length;
|
||||||
} else if (isCount) {
|
} else if (isCount) {
|
||||||
current = cfg.targetChoreId
|
current = memberTargetChoreId
|
||||||
? periodCompletions.filter((c) => c.assignedChoreId === cfg.targetChoreId).length
|
? periodCompletions.filter((c) => c.assignedChoreId === memberTargetChoreId).length
|
||||||
: periodCompletions.length;
|
: periodCompletions.length;
|
||||||
} else {
|
} else {
|
||||||
current = periodCompletions.reduce((sum, c) => {
|
current = periodCompletions.reduce((sum, c) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user