Data Layer low complexity backend
0
Dependencies
3
Dependents
1
Entities
0
Integrations

Description

Data access layer for the generated_reports table. Each export attempt creates a record with org scope, period, format, status, and file reference for audit purposes. Supports listing history and retrieving file URLs.

Feature: Bufdir Report Export

generated-reports-repository

Summaries

The Generated Reports Repository ensures every export attempt is permanently recorded, giving the organisation a complete audit trail for regulatory compliance and accountability. By capturing scope, period, format, status, and file references, leadership can demonstrate to auditors and funders exactly when reports were produced and by whom. This reduces compliance risk and eliminates disputes about whether submissions were made. The history retrieval capability also enables teams to re-download previous exports without reprocessing, saving staff time and reducing operational overhead across reporting cycles.

This is a low-complexity data component with no external dependencies, making it one of the safest deliverables in the export pipeline. It should be built and tested early as it is a dependency for the Bufdir Export Edge Function. Testing requires a migration script for the generated_reports table and basic CRUD integration tests against Supabase. Risk is minimal — the primary concern is ensuring the status enum and schema match what downstream services expect.

Estimated effort is half a sprint. Coordinate schema definition with the edge function team before finalising column names to avoid rework.

Implements the data access layer for the generated_reports table using the Supabase client. All methods are parameterised to prevent SQL injection. createReport() inserts a pending record before generation begins, enabling failure auditing even if downstream steps crash. updateStatus(), setFileUrl(), and setSubmissionRef() are discrete update methods to minimise row-lock contention during async processing.

getReportsByScope() should use an index on (scope_id, created_at DESC) for pagination performance. No ORM — raw Supabase query builder calls for predictability. Keep this module stateless; all state lives in the database row.

Responsibilities

  • Create export audit records before generation starts
  • Update record status on completion or failure
  • Store file URL or submission reference
  • Retrieve export history by scope

Interfaces

createReport(params)
updateStatus(reportId, status)
setFileUrl(reportId, url)
setSubmissionRef(reportId, ref)
getReportById(reportId)
getReportsByScope(scopeId, limit)
deleteReport(reportId)

Relationships

Dependents (3)

Components that depend on this component

Related Data Entities (1)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/generated-reports 5 endpoints
GET /api/v1/generated-reports List all generated reports
GET /api/v1/generated-reports/:report_id Get a single generated report record
POST /api/v1/generated-reports Create a new generated report record
PUT /api/v1/generated-reports/:report_id Update status, file URL, or submission reference on a report
DELETE /api/v1/generated-reports/:report_id Delete a generated report record