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):
- Fetch the event by ID — return
404 if not found
- Count registrations with
registrationStatus: registered for this event
- Count registrations with
registrationStatus: waitlisted for this event
- 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
- 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
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.tsand wire it into the Events collection so it is available atGET /api/events/:id/availability.Logic (in order):
404if not foundregistrationStatus: registeredfor this eventregistrationStatus: waitlistedfor this eventregistrationOpenAtexists and is in the future → not open yetregistrationCloseAtexists and is in the past → closedResponse shape:
{ "eventId": "string", "maxCapacity": 40, "registeredCount": 12, "spotsLeft": 28, "waitlistCapacity": 10, "waitlistCount": 0, "registrationOpen": true, "opensAt": null, "userStatus": "registered" | "waitlisted" | "not-registered" | null }userStatusshould benullfor unauthenticated requests.opensAtshould be an ISO date string if registration hasn't opened yet, otherwisenull.Once this ticket and events collection ticket are both merged, add the endpoint to the
endpointsarray inEvents.tsat path/:id/availabilitywith methodget.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
pnpm typegen)