Service Layer high complexity backend
0
Dependencies
0
Dependents
8
Entities
0
Integrations

Description

Backend service that executes tenant-scoped aggregation queries against the activities, users, and user_organization_roles tables to produce filtered team report data. All queries carry strict WHERE clauses enforcing multi-tenancy so one organization cannot read another's data. Supports cursor-based pagination for large datasets such as NHF's 1,400-chapter network.

Feature: Team Reports

report-generation-service

Sources & reasoning

The Report Generation Service is the core business logic layer translating raw activity registrations into actionable oversight data. Strict tenant scoping is non-negotiable in a multi-organization platform, and cursor-based pagination is required to handle NHF-scale query results without timeout or memory issues.

No source references — this artifact was included based on reasoning alone (see above).

Responsibilities

  • Execute tenant-scoped aggregation queries with date range, activity type, and peer mentor filters
  • Enforce multi-tenancy via WHERE clauses on users and user_organization_roles
  • Implement cursor-based pagination for large result sets
  • Persist generated report metadata to the reports table for audit reference
  • Apply role guard - reject requests from roles other than Coordinator and Org Admin

Interfaces

generateReport(orgId: string, filters: ReportFilters, cursor?: string): ReportPage
aggregateByMentor(orgId: string, filters: ReportFilters): MentorSummary[]
aggregateByActivityType(orgId: string, filters: ReportFilters): ActivityTypeSummary[]
saveReportMetadata(orgId: string, filters: ReportFilters, rowCount: number): Report