Skip to content

backend: implement /api/analytics/export endpoint for CSV download #27

@ShantKhatri

Description

@ShantKhatri

Summary

The analytics route at apps/backend/src/routes/analytics.ts currently returns JSON view/click data. Extend it with a CSV export endpoint so card owners can download their analytics data.

Context

Product doc section 5.5 specifies an 'Analytics Dashboard' feature. An export endpoint is a natural next step for power users and aligns with DevCard's privacy-first philosophy (data portability).

Tasks

  • add a new route GET /api/analytics/export in analytics.ts — authenticated, owned data only.
  • query platform link clicks and card views for the authenticated user grouped by date.
  • serialize response as CSV using a lightweight library (e.g. fast-csv or manual string builder).
  • set Content-Type: text/csv and Content-Disposition: attachment; filename=devcard-analytics.csv headers.
  • validate that the requesting user can only export their own data (no IDOR).
  • add tests for the endpoint asserting CSV structure and auth guard.

Acceptance Criteria

  • authenticated users can download a CSV with columns: date, platform, event_type, count.
  • unauthenticated requests return 401.
  • another user's export URL returns 403.

Difficulty

medium — involves HTTP file streaming, CSV serialization, and authorization boundary checks.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions