Service Layer high complexity backend
2
Dependencies
3
Dependents
10
Entities
0
Integrations

Description

Server-side Next.js service that aggregates activity records from PostgreSQL scoped strictly to the requesting organization's tenant, maps internal fields to the Bufdir schema version, and persists the generated report to bufdir_exports with status tracking. Versioned schema config allows field mapping updates without a client release.

Feature: Bufdir Report Generation

bufdir-report-service

Sources & reasoning

Core server-side service implementing the report generation pipeline. Tenant-scoped PostgreSQL aggregation, versioned field mapping, and persistence to bufdir_exports are all explicitly required in the implementation notes. This is the highest-complexity component in the feature.

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

Responsibilities

  • Aggregate activities filtered by org tenant, period, and required field completeness
  • Map internal fields (type, duration, contact_category, date) to Bufdir output structure
  • Persist generated export record to bufdir_exports with status, period, and generating_user_id
  • Enforce Org Admin role guard before any aggregation or export
  • Load versioned Bufdir schema config from server-side configuration

Interfaces

previewReport(orgId: string, period: DateRange): Promise<BufdirPreview>
generateReport(orgId: string, period: DateRange, userId: string): Promise<BufdirExportRecord>
getExportStatus(exportId: string): Promise<ExportStatus>
loadSchemaVersion(version: string): BufdirFieldSchema
aggregateActivities(orgId: string, period: DateRange): Promise<ActivityAggregate[]>

Relationships

Dependencies (2)

Components this component depends on

Dependents (3)

Components that depend on this component