Skip to content

feat(trpc): add getBookingStats query procedure#6

Open
AdamWalkerQodo wants to merge 1 commit into
walkers4u:mainfrom
AdamWalkerQodo:feat/get-booking-stats
Open

feat(trpc): add getBookingStats query procedure#6
AdamWalkerQodo wants to merge 1 commit into
walkers4u:mainfrom
AdamWalkerQodo:feat/get-booking-stats

Conversation

@AdamWalkerQodo

Copy link
Copy Markdown

Summary

  • Adds a getBookingStats tRPC query on loggedInViewerRouter
  • Returns booking counts grouped by status for the authenticated user: total, accepted, pending, cancelled, rejected, awaiting_host
  • Accepts an optional startDate / endDate ISO string filter for scoping the query to a date range
  • Follows the existing handler + schema pattern used by markNoShow and other procedures

Changed files

  • packages/trpc/server/routers/loggedInViewer/getBookingStats.schema.ts (new)
  • packages/trpc/server/routers/loggedInViewer/getBookingStats.handler.ts (new)
  • packages/trpc/server/routers/loggedInViewer/_router.tsx (register procedure)

Usage

const { data } = trpc.viewer.getBookingStats.useQuery({
  startDate: "2025-01-01T00:00:00.000Z",
  endDate: "2025-12-31T23:59:59.999Z",
});
// { total: 42, accepted: 30, pending: 5, cancelled: 4, rejected: 2, awaiting_host: 1 }

Test plan

  • Call the query without filters and verify counts match all bookings for the logged-in user
  • Call with a narrow date range and verify counts reflect only bookings in that window
  • Verify statuses with zero bookings return 0 rather than undefined

🤖 Generated with Claude Code

Returns booking counts grouped by status (accepted, pending, cancelled,
rejected, awaiting_host) for the authenticated user, with optional
date range filtering.
@walkers4u walkers4u marked this pull request as ready for review April 29, 2026 10:57
@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Add getBookingStats query procedure for booking statistics

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Adds getBookingStats tRPC query procedure to retrieve booking counts grouped by status
• Supports optional date range filtering via startDate and endDate ISO string parameters
• Returns booking counts for all statuses (accepted, pending, cancelled, rejected, awaiting_host)
  with zero defaults
• Follows existing handler + schema pattern for consistency with other procedures
Diagram
flowchart LR
  A["User Request"] -->|"getBookingStats query"| B["Schema Validation"]
  B -->|"Input validation"| C["Handler Logic"]
  C -->|"Filter by userId & dates"| D["Prisma groupBy"]
  D -->|"Count by status"| E["Response Object"]
  E -->|"Return stats"| F["Client Data"]
Loading

Grey Divider

File Changes

1. packages/trpc/server/routers/loggedInViewer/getBookingStats.handler.ts ✨ Enhancement +42/-0

Handler for booking statistics aggregation

• Implements handler function that queries bookings grouped by status for authenticated user
• Constructs dynamic where clause supporting optional date range filtering on startTime
• Returns object with total count and individual counts for each booking status (defaulting to 0)
• Uses Prisma groupBy with _count aggregation for efficient database query

packages/trpc/server/routers/loggedInViewer/getBookingStats.handler.ts


2. packages/trpc/server/routers/loggedInViewer/getBookingStats.schema.ts ✨ Enhancement +10/-0

Input schema for booking stats query

• Defines Zod schema for input validation with optional startDate and endDate fields
• Both date fields use ISO datetime format validation
• Exports TypeScript type inferred from schema for type safety
• Entire input object is optional to allow parameterless queries

packages/trpc/server/routers/loggedInViewer/getBookingStats.schema.ts


3. packages/trpc/server/routers/loggedInViewer/_router.tsx ✨ Enhancement +5/-0

Register getBookingStats query in router

• Imports ZGetBookingStatsInputSchema from new schema file
• Registers getBookingStats as authed query procedure with schema validation
• Uses dynamic import pattern consistent with other procedures in router
• Follows existing code style and structure for procedure registration

packages/trpc/server/routers/loggedInViewer/_router.tsx


Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

Looking for bugs?

Check back in a few minutes. An AI review agent is analyzing this pull request.

Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant