Skip to content

Event Registration Control Constraints and Cascade Schema Handling #430

Open
Pcmhacker-piro wants to merge 1 commit into
Dev-Card:mainfrom
Pcmhacker-piro:fix/event-rsvp-cascade
Open

Event Registration Control Constraints and Cascade Schema Handling #430
Pcmhacker-piro wants to merge 1 commit into
Dev-Card:mainfrom
Pcmhacker-piro:fix/event-rsvp-cascade

Conversation

@Pcmhacker-piro

@Pcmhacker-piro Pcmhacker-piro commented May 31, 2026

Copy link
Copy Markdown
Contributor

Summary
Adds cascade deletion constraints to Event/EventAttendee relations and implements RSVP endpoints with organizer and duplicate validation. Closes #308

Type of Change

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • UI / Design change
  • Tests only
  • Documentation
  • Infrastructure / DevOps
  • Security

What Changed

  • apps/backend/prisma/schema.prisma — Added onDelete: Cascade to Event.organizer, EventAttendee.event, and EventAttendee.user relations to prevent deletion failures when a user or event is removed.
  • apps/backend/src/routes/event.ts — Added POST /:id/rsvp endpoint that validates event existence, blocks organizers from RSVPing to their own event (400), and catches duplicate RSVPs gracefully (400 instead of crash).
  • apps/backend/src/routes/event.ts — Added DELETE /:id/rsvp endpoint that validates event existence and returns 404 if no RSVP record is found.

How to Test

  1. Register a user, create an event, then attempt POST /api/events/:id/rsvp with the organizer's token — expect 400 "Organizer cannot RSVP to their own event".
  2. As a different user, POST /api/events/:id/rsvp twice to the same event — expect 400 "Already RSVPed to this event" on the second attempt.
  3. DELETE /api/events/:id/rsvp after RSVPing — expect 204. Call it again — expect 404 "RSVP not found".
  4. Delete a user account that is organizing events — verify events and their attendee records are cleaned up via cascade.

Checklist

  • My code follows the project's coding style (pnpm -r run lint passes).
  • TypeScript compiles without errors (pnpm -r run typecheck).
  • I have added or updated tests for the changes I made.
  • All tests pass locally (pnpm -r run test).
  • I have updated documentation where necessary.
  • No new console.log or debug statements left in the code.
  • Breaking changes are documented in this PR description.

@Pcmhacker-piro

Pcmhacker-piro commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Harxhit ,

all code changes have been completed. The only failing check is the Vercel authorization check, which appears to be a repository-side permission issue. Could you please review the PR when you get a chance? Thank you!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use any breaks type safety.

})

return reply.status(201).send({message: 'RSVP confirmed'})
} catch (error:any) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have util function to catch db errors.

@Harxhit Harxhit added the gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. label May 31, 2026
@Pcmhacker-piro

Copy link
Copy Markdown
Contributor Author

heyy @Harxhit

All 47 tests now pass after fixing 3 issues introduced by the type-safety + handleDbError migration:

  1. handleDbError used instanceof Prisma.PrismaClientKnownRequestError, but mock errors in tests are plain Error objects with a .code property — switched to duck-type check on error.code
  2. jwtVerify mock in buildApp() wasn't setting request.user after resolving, so (request.user as { id: string }).id threw TypeError — added .then(user => { this.user = user }) to match real @fastify/jwt
  3. Paginated attendees test mocks omitted _count: { attendees: N } — the route handler references event._count.attendees which crashed on undefined
    All existing tests pass unchanged. 0 new PR comments needed on the original diff.

@Harxhit

Harxhit commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

heyy @Harxhit

All 47 tests now pass after fixing 3 issues introduced by the type-safety + handleDbError migration:

1. handleDbError used instanceof Prisma.PrismaClientKnownRequestError, but mock errors in tests are plain Error objects with a .code property — switched to duck-type check on error.code

2. jwtVerify mock in buildApp() wasn't setting request.user after resolving, so (request.user as { id: string }).id threw TypeError — added .then(user => { this.user = user }) to match real @fastify/jwt

3. Paginated attendees test mocks omitted _count: { attendees: N } — the route handler references event._count.attendees which crashed on undefined
   All existing tests pass unchanged. 0 new PR comments needed on the original diff.

Please allow me some time.

@Harxhit Harxhit added backend critical Includes schema, architecture, or other critical core functionality changes. labels Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend critical Includes schema, architecture, or other critical core functionality changes. gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event Registration Control Constraints and Cascade Schema Handling

2 participants