Data Layer medium complexity backend
0
Dependencies
0
Dependents
1
Entities
0
Integrations

Description

Data access layer responsible for persisting and querying activity log records in the database. Abstracts all SQL or ORM operations behind a clean interface so the service layer has no direct database dependency. Handles indexing strategies to support efficient queries by mentor, contact, and date range.

Feature: Simple Activity Logging

activity-repository

Sources & reasoning

All four organizations named this the top-priority function (line 14-18). The 30-min default, under-two-clicks target, and HLF's 380-registration example (lines 20-22) directly define the UX contract. Phase matrix marks it Fase 1 / MUST HAVE, mapping to MVP.

  • NHF: Word-skjemaer sendes manuelt til regioner → manuell Excel-aggregering sentralt. Mål: registrering på under to klikk.
  • HLF: En likeperson hadde 380 enkeltregistreringer på ett år. Standardverdier (dagens dato, 30 min) som kan overstyres.
  • Designprinsipp: Lavest mulig kognitiv belastning. Standardvalg, gjenkjennelig logikk, færrest mulig steg.

Responsibilities

  • Insert new activity log records with all required fields and timestamps
  • Query activities by contact ID with optional date-range filtering
  • Query activities by mentor ID for reporting and history views
  • Provide count and aggregation queries for dashboard statistics
  • Manage database indexes on mentor_id, contact_id, and logged_at columns

Interfaces

create(activity: NewActivity): Promise<Activity>
findByContactId(contactId: string, options?: QueryOptions): Promise<Activity[]>
findByMentorId(mentorId: string, options?: QueryOptions): Promise<Activity[]>
findById(activityId: string): Promise<Activity | null>
countByMentor(mentorId: string, dateRange: DateRange): Promise<number>

Related Data Entities (1)

Data entities managed by this component