updated rewards assignment and reward progress

This commit is contained in:
JCEEE
2026-08-31 16:44:37 +01:00
parent cda2cbfcab
commit 3bf78d777c
10 changed files with 549 additions and 209 deletions
+9 -13
View File
@@ -4,7 +4,9 @@ import {
periodStart,
periodEnd,
nextPaydayAfter,
weekStart
weekStart,
bonusWindow,
completionInWindow
} from '@shared/timezone';
import { famMeta } from './fam';
@@ -55,13 +57,8 @@ export async function evaluateFam(pb: any, famId: string) {
for (const cfg of configs) {
// Pocket money pauses until the parent sets an amount.
if (cfg.isPocketMoney && !cfg.rewardValue) continue;
const pStart2 = cfg.period ? periodStart(cfg.period, paydayEval, tzEval) : '';
const pEnd = cfg.period ? periodEnd(cfg.period, pStart2) : '';
const periodCompletions = cfg.period
? allCompletions.filter(
(c: any) => (c.date || '').slice(0, 10) >= pStart2 && (c.date || '').slice(0, 10) <= pEnd
)
: allCompletions;
const win = bonusWindow(cfg, paydayEval, tzEval);
const periodCompletions = allCompletions.filter((c: any) => completionInWindow(c, win));
const existingRewards = allRewards.filter((r: any) => r.bonusConfigId === cfg.id);
let createdReward = false;
@@ -241,11 +238,10 @@ export async function progress(pb: any, famId: string) {
for (const cfg of configsData) {
const cfgRewards = allRewards.filter((r: any) => r.bonusConfigId === cfg.id);
const pStart = cfg.period ? periodStart(cfg.period, payday, tz) : '';
const pEnd = cfg.period ? periodEnd(cfg.period, pStart) : '';
const periodCompletions = cfg.period
? completionsList.filter((c: any) => c.date >= pStart && c.date <= pEnd)
: completionsList;
const win = bonusWindow(cfg, payday, tz);
const pStart = win.from;
const pEnd = win.to;
const periodCompletions = completionsList.filter((c: any) => completionInWindow(c, win));
const progressRows: any[] = [];