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
+19
View File
@@ -440,6 +440,25 @@ async function ensureBonusFields(): Promise<void> {
fields.push({ name: "isPocketMoney", type: "bool", required: false });
changed = true;
}
// Standalone-reward progress window (bonus_configs only): how far progress
// counts (`completeBy`) and the window's start/custom-end dates.
if (name === "bonus_configs") {
if (!has("completeBy")) {
fields.push({
name: "completeBy", type: "select", required: false,
values: ["unlimited", "week", "custom"], maxSelect: 1,
});
changed = true;
}
if (!has("startDate")) {
fields.push({ name: "startDate", type: "text", required: false });
changed = true;
}
if (!has("completeByDate")) {
fields.push({ name: "completeByDate", type: "text", required: false });
changed = true;
}
}
// rewardValue must be optional so an unset pocket-money droplet can exist.
const rv = fields.find((f: any) => f.name === "rewardValue");
if (rv && rv.required) {
+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[] = [];