Skip to content

[BACKEND] Availability endpoint #14

@aleckshen

Description

@aleckshen

Is your feature request related to a problem? Please describe

The frontend has no way to know whether an event has spots available or whether sign-ups are currently open, making it impossible to conditionally render the "Sign Up" button without exposing raw registration data publicly.

Describe the solution you'd like

Create a Payload custom endpoint handler at src/payload/endpoints/eventAvailability.ts and wire it into the Events collection so it is available at GET /api/events/:id/availability.

Logic (in order):

  1. Fetch the event by ID — return 404 if not found
  2. Count registrations with registrationStatus: registered for this event
  3. Count registrations with registrationStatus: waitlisted for this event
  4. Determine if registration is open:
    • If registrationOpenAt exists and is in the future → not open yet
    • If registrationCloseAt exists and is in the past → closed
    • Otherwise → open
  5. If the user is logged in, look up their registration status for this event

Response shape:

{
  "eventId": "string",
  "maxCapacity": 40,
  "registeredCount": 12,
  "spotsLeft": 28,
  "waitlistCapacity": 10,
  "waitlistCount": 0,
  "registrationOpen": true,
  "opensAt": null,
  "userStatus": "registered" | "waitlisted" | "not-registered" | null
}

userStatus should be null for unauthenticated requests. opensAt should be an ISO date string if registration hasn't opened yet, otherwise null.

Once this ticket and events collection ticket are both merged, add the endpoint to the endpoints array in Events.ts at path /:id/availability with method get.

Describe alternatives you've considered

Exposing raw registration counts via the existing Payload REST API was considered, but it would require the frontend to do derived calculations and would expose more data than necessary to unauthenticated users.

Additional context

All data querying uses req.payload (the Local API) — no separate database calls. Depends on the Events (#9) and EventRegistrations (#10) collections.

Ref: https://payloadcms.com/docs/rest-api/overview#custom-endpoints

BEFORE MERGING

  • Code generation run (hint: pnpm typegen)
  • PR Reviewed (For non-trivial changes)
  • All required PR checks passing

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature being worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions