Skip to content

fix(chores): return completed recurring bonus chores to the bonus pool at nightly cleanup - #386

Open
adamecker wants to merge 1 commit into
jherforth:mainfrom
adamecker:feature/bonus-chore-return-to-pool
Open

adamecker wants to merge 1 commit into
jherforth:mainfrom
adamecker:feature/bonus-chore-return-to-pool

Conversation

@adamecker

Copy link
Copy Markdown
Contributor

What this fixes

A recurring bonus chore claimed from the bonus pool never cycled back to the pool. Once a kid claimed a daily bonus chore (a schedule with a crontab and a clam_value > 0), it stayed assigned to them forever, even after they completed it — so nobody else ever got a turn at it.

The cause is in the nightly cleanup in dailyBackgroundProcessing (server/index.js): the existing reset that returns bonus chores to the pool only covers one-time cards, because it filters crontab IS NULL. A recurring daily bonus chore never matches that filter, so it was never returned.

The fix

After the existing reset, the nightly job now also looks for recurring bonus schedules (crontab IS NOT NULL, visible, clam_value > 0, currently assigned) where the current holder has a completion history entry for the day that just ended, and sets those schedules' user_id back to NULL — returning them to the bonus pool for the next day. The result is reported as returnedBonusSchedulesCount alongside the existing nightly counts.

Two cases are deliberately left alone:

  • Claimed but never completed: the schedule stays assigned to the holder — they still owe the chore.
  • Manual transfer-back: untouched; a parent can still move a chore back to the pool with the Transfer dialog at any time.

Tests

New test file server/tests/bonusChoreReturnToPool.test.js (5 tests):

  • a claimed + completed recurring bonus chore returns to the pool overnight
  • a claimed but uncompleted recurring bonus chore stays assigned
  • a completion today does not return it to the pool early
  • a non-bonus recurring chore is unaffected
  • manually transferring a recurring bonus chore back to the pool still works

Results on this branch head, rebased onto current upstream/main (811c9b7):

  • New test file: 5/5 pass
  • Full server suite: 774/774 pass, 0 fail
  • Full client suite: 1064/1064 pass (98 files)
  • Client vite build: succeeds

As a control, the new tests were also run against the unmodified base: 4/5 pass there, with exactly the bug test failing (the schedule kept user_id: 1 instead of returning to NULL), confirming the tests capture the bug and the fix resolves it.

Verification

Verified locally on a local demo stack with a live database, running the real nightly job:

  • Repro on the unmodified base: a recurring bonus chore claimed and completed for the day stayed assigned after the nightly run (user_id still set).
  • With the fix: the nightly run returned it to the pool:
Found 1 completed recurring bonus chores to return to the pool
  - Completed recurring bonus chores returned to pool: 1
returnedBonusSchedulesCount: 1
user_id: NULL
  • Negative case: a recurring bonus chore claimed but never completed was left alone by the same nightly run:
returnedBonusSchedulesCount: 0
user_id: unchanged (still assigned to the claimer)

No UI change, so no screenshot.

Generated with Muse AI 🤖

…l at nightly cleanup

The nightly reset only touched one-time cards (crontab IS NULL), so a
recurring daily bonus chore claimed from the pool kept its claimer after
completion: the schedule row itself carries the assignment, and nothing
ever cleared it. Extend dailyBackgroundProcessing with a second reset
that returns a recurring bonus schedule to the pool once its current
holder completed it for the day that just ended. A claim that was never
completed stays assigned — the holder still owes it, and a parent can
move it back with the Transfer dialog. Completing today does not return
it early, so nobody can claim and complete the same chore twice in a
day.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant