Skip to content

Issue #72 — Backend: Admin Analytics — Bookings Stats, Top Workspaces & Top Members #654

@yusuftomilola

Description

@yusuftomilola

Location: backend/src/dashboard/providers/admin-analytics.provider.ts

Description

The second set of admin analytics covers booking activity and leaderboards. Booking stats are broken down by status so admins can see how many bookings are pending, confirmed, completed, or cancelled. Top workspaces are ranked by booking count and revenue. Top members are ranked by total payment amount. These are added as new methods on the same AdminAnalyticsProvider class from Issue #71.

Acceptance Criteria

  • @InjectRepository decorators for Booking and Workspace are added to AdminAnalyticsProvider (in addition to those from Issue CSV Export for Check-ins #71)
  • A getBookingStats(from?: string, to?: string) method is implemented that returns:
    • byStatus — a Record<string, number> map of booking counts keyed by BookingStatus (e.g. { PENDING: 4, CONFIRMED: 12, COMPLETED: 30, CANCELLED: 2 })
    • trend — array of { month: string, count: number } for the last 6 calendar months using DATE_TRUNC('month', "createdAt"), ordered oldest to newest
  • A getTopWorkspaces(limit = 5, from?: string, to?: string) method is implemented that returns an array of up to limit workspaces ordered by booking count descending, each entry containing:
    • id, name — from the Workspace entity
    • bookings — raw SQL COUNT result
    • revenueKobo — raw SQL SUM of Payment.amountKobo for successful payments linked to that workspace's bookings
  • A getTopMembers(limit = 5, from?: string, to?: string) method is implemented that returns an array of up to limit members ordered by total payment amount descending, each entry containing:
    • id — user ID
    • fullName — concatenated firstname || ' ' || lastname
    • totalKobo — raw SQL SUM of Payment.amountKobo
  • All methods accept optional from / to date range filters
  • npx tsc --noEmit passes with no errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions