Bufdir Report Service
Component Detail
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.
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
Dependents (3)
Components that depend on this component
Related Data Entities (10)
Data entities managed by this component