Files
chore/.github/specs/active/feat-dynamic-points/feat-tracking.md
Ryan Kegel 3dee8b80a2
All checks were successful
Gitea Actions Demo / build-and-push (push) Successful in 24s
feat: Implement task and reward tracking feature
- Added tracking events for tasks, penalties, and rewards with timestamps.
- Created new TinyDB table for tracking records to maintain audit history.
- Developed backend API for querying tracking events with filters and pagination.
- Implemented logging for tracking events with per-user rotating log files.
- Added unit tests for tracking event creation, querying, and anonymization.
- Deferred frontend changes for future implementation.
- Established acceptance criteria and documentation for the tracking feature.

feat: Introduce account deletion scheduler

- Implemented a scheduler to delete accounts marked for deletion after a configurable threshold.
- Added new fields to the User model to manage deletion status and attempts.
- Created admin API endpoints for managing deletion thresholds and viewing the deletion queue.
- Integrated error handling and logging for the deletion process.
- Developed unit tests for the deletion scheduler and related API endpoints.
- Documented the deletion process and acceptance criteria.
2026-02-09 15:39:43 -05:00

6.3 KiB

Feature: Task and Reward Tracking

Overview

Goal: Tasks, Penalties, and Rewards should be recorded when completed (activated), requested, redeemed, and cancelled. A record of the date and time should also be kept for these actions. A log file shall be produced that shows the child's points before and after the action happened.

User Story:
As an administrator, I want to know what kind and when a task, penalty, or reward was activated. As an administrator, I want a log created detailing when a task, penalty, or reward was activated and how points for the affected child has changed. As a user (parent), when I activate a task or penalty, I want to record the time and what task or penalty was activated. As a user (parent), when I redeem a reward, I want to record the time and what reward was redeeemed. As a user (parent/child), when I cancel a reward, I want to record the time and what reward was cancelled. As a user (child), when I request a reward, I want to record the time and what reward was requested.

Questions:

  • Tasks/Penalty, rewards should be tracked per child. Should the tracking be recorded in the child database, or should a new database be used linking the tracking to the child?
  • If using a new database, should tracking also be linking to user in case of account deletion?
  • Does there need to be any frontend changes for now?

Decisions:

  • Use a new TinyDB table (tracking_events.json) for tracking records (append-only). Do not embed tracking in child to avoid large child docs and preserve audit history. Each record includes child_id and user_id.
  • Track events for: task/penalty activated, reward requested, reward redeemed, reward cancelled.
  • Store timestamps in UTC ISO 8601 with timezone (e.g. 2026-02-09T18:42:15Z). Always use server time for occurred_at to avoid client clock drift.
  • On user deletion: anonymize tracking records by setting user_id to null, preserving child activity history for compliance/audit.
  • Keep an audit log file per user (e.g. tracking_user_<user_id>.log) with points before/after and event metadata. Use rotating file handler.
  • Use offset-based pagination for tracking queries (simpler with TinyDB, sufficient for expected scale).
  • Frontend changes deferred: Ship backend API, models, and SSE events only. No UI components in this phase.

Configuration

Acceptance Criteria (Definition of Done)

Data Model

  • Add TrackingEvent model in backend/models/ with from_dict()/to_dict() and 1:1 TS interface in frontend/vue-app/src/common/models.ts
  • TrackingEvent fields include: id, user_id, child_id, entity_type (task|reward|penalty), entity_id, action (activated|requested|redeemed|cancelled), points_before, points_after, delta, occurred_at, created_at, metadata (optional dict)
  • Ensure delta == points_after - points_before invariant

Backend Implementation

  • Create TinyDB table (e.g., tracking_events.json) with helper functions in backend/db/
  • Add tracking write in all mutation endpoints:
    • task/penalty activation
    • reward request
    • reward redeem
    • reward cancel
  • Build TrackingEvent instances from models (no raw dict writes)
  • Add server-side validation for required fields and action/entity enums
  • Add send_event_for_current_user calls for tracking mutations

Frontend Implementation

Admin API

  • Add admin endpoint to query tracking by child_id, date range, and entity_type (e.g. GET /admin/tracking)
  • Add offset-based pagination parameters (limit, offset) with sensible defaults (e.g. limit=50, max=500)
  • Return total count for pagination UI (future)

SSE Event

Backend Unit Tests

  • Create tests for tracking creation on each mutation endpoint (task/penalty activated, reward requested/redeemed/cancelled)
  • Validate points_before/after and delta are correct
  • Ensure tracking write does not block core mutation (failure behavior defined)

Frontend Unit Tests

  • Test API helper functions for tracking queries
  • Test TypeScript interface matches backend model (type safety)

Edge Cases

  • Reward cancel after redeem should not create duplicate inconsistent entries
  • Multiple activations in rapid sequence must be ordered by occurred_at then created_at
  • Child deleted: tracking records retained and still queryable by admin (archive mode)
  • User deleted: anonymize tracking by setting user_id to null, retain all other fields for audit history

Integration Tests

  • End-to-end: activate task -> tracking created -> SSE event emitted -> audit log written
  • Verify user deletion anonymizes tracking records without breaking queries

Logging & Monitoring

  • Add dedicated tracking logger with per-user rotating file handler (e.g. logs/tracking_user_<user_id>.log)
  • Log one line per tracking event with user_id, child_id, entity_type, entity_id, action, points_before, points_after, delta, occurred_at
  • Configure max file size and backup count (e.g. 10MB, 5 backups)

Documentation

  • Update README or docs to include tracking endpoints, schema, and sample responses
  • Add migration note for new tracking_events.json

Future Considerations

  • Reward tracking will be used to determine child ranking (badges and certificates!)
  • is_good vs not is_good in task tracking can be used to show the child their balance in good vs not good