Is your feature request related to a problem? Please describe
When someone submits a registration via POST /api/event-registrations, there is no logic to check whether the event has space, whether the user is already registered, or whether the event is still accepting sign-ups.
Describe the solution you'd like
Create a beforeChange hook at src/payload/hooks/eventRegistrations/checkCapacity.ts that runs automatically whenever a new registration is created. The hook will be wired into the EventRegistrations collection (#10).
Logic (in order):
- Skip if the operation is not
create
- Fetch the event by ID — throw
"Event not found" if it doesn't exist
- If event status is
completed or cancelled, throw "This event is no longer accepting registrations"
- Check for a duplicate — query for an existing non-cancelled registration matching the same event + user (or event + guestEmail). Throw
"You are already registered for this event" if found
- Count current
registered registrations for the event. Throw "This event is full" if count >= maxCapacity
- If the request has a logged-in user, auto-set
data.user from the session
- Return
data so Payload can save it
Once this ticket and Ticket 4 are both merged, add checkCapacity to the beforeChange hooks array in EventRegistrations.ts.
Describe alternatives you've considered
A custom Next.js route handler was considered but a Payload hook keeps all business logic inside the Payload layer, meaning it runs regardless of how the collection is accessed (REST, Local API, admin panel).
Additional context
Depends on the Events (#9) and EventRegistrations (#10) collections. After this is wired up, the confirmation email call will also be added to the end of this hook.
Ref: https://payloadcms.com/docs/hooks/collections
BEFORE MERGING
Is your feature request related to a problem? Please describe
When someone submits a registration via
POST /api/event-registrations, there is no logic to check whether the event has space, whether the user is already registered, or whether the event is still accepting sign-ups.Describe the solution you'd like
Create a
beforeChangehook atsrc/payload/hooks/eventRegistrations/checkCapacity.tsthat runs automatically whenever a new registration is created. The hook will be wired into the EventRegistrations collection (#10).Logic (in order):
create"Event not found"if it doesn't existcompletedorcancelled, throw"This event is no longer accepting registrations""You are already registered for this event"if foundregisteredregistrations for the event. Throw"This event is full"if count >=maxCapacitydata.userfrom the sessiondataso Payload can save itOnce this ticket and Ticket 4 are both merged, add
checkCapacityto thebeforeChangehooks array inEventRegistrations.ts.Describe alternatives you've considered
A custom Next.js route handler was considered but a Payload hook keeps all business logic inside the Payload layer, meaning it runs regardless of how the collection is accessed (REST, Local API, admin panel).
Additional context
Depends on the Events (#9) and EventRegistrations (#10) collections. After this is wired up, the confirmation email call will also be added to the end of this hook.
Ref: https://payloadcms.com/docs/hooks/collections
BEFORE MERGING
pnpm typegen)