Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

feat: rework event roles tables - #965

Merged
ojeytonwilliams merged 24 commits into
freeCodeCamp:mainfrom
gikf:feat/event-roles-tables
May 11, 2022
Merged

ojeytonwilliams merged 24 commits into
freeCodeCamp:mainfrom
gikf:feat/event-roles-tables

Conversation

@gikf

@gikf gikf commented Mar 15, 2022 •

Copy link
Copy Markdown
Member
  • I have read Chapter's contributing guidelines.
  • My pull request has a descriptive title (not a vague title like Update README.md).
  • My pull request targets the main branch of Chapter.

  • Updates schema, client queries, resolver, graphql types to conform with event (user) roles tables defined on https://dbdiagram.io/d/617ae3f8fa17df5ea673e3ea. As a side-effect this changes also rsvps.
  • Adds seeding event permissions, event roles and updates seeding rsvps.
  • In resolver and graphql types including event_user requires going as deep as event_user -> event_role -> event_role_permissions -> event_permission. This could be changed with making event_role or event_role_permissions optional in graphql type.
  • Some name changing might still be needed where focus was changed from rsvp to event user.
  • Updates tests.
  • I've added couple rsvps, this might need some refining. I used no rsvp as a canceled rsvp. It is set in client when user cancels.
  • I've added couple example event permissions and event roles. Event permissions are not checked.

@gitpod-io

gitpod-io Bot commented Mar 15, 2022

Copy link
Copy Markdown

@ghost

ghost commented Mar 15, 2022 •

Copy link
Copy Markdown

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

Hey, @gikf I'm just merging main into this (in part to understand how things are supposed to fit together)

Comment on lines +151 to +152
if (oldUserRole) {
await prisma.event_users.delete({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this logic works with the new db schema. Before, if the rsvp existed, then rsvpEvent should cancel that rsvp and allow someone on the waitlist to join.

Now an event_user entry will exist if a user has some relationship to a given event (they've been invited, they've canceled, etc) so, the logic should be (crudely):

if (userIsGoingToEvent) {
  cancelRsvp();
  moveUserOffWaitlist();
} else {
  confirmUserRsvp();
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, there's some ambiguousness when somebody presses cancel by their rsvp/request. After merging main I'll change it to not remove from event_user, but assign another rsvp.

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

@gikf I'm struggling a little with this merge, to be honest. There's a lot of moving parts and I'm pretty sure I'm going to break things.

If you're feeling brave, could you take a look?

Once we've got this in I'll try and clean up the resolvers a bit. They're a bit too sprawling to wrap my brain around at the moment.

@gikf

gikf commented Mar 19, 2022

Copy link
Copy Markdown
Member Author

@ojeytonwilliams I've merged main, this was rough, I really hope I didn't botch anything in it 👀

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

I know how tough that was, so nice one! I'll give it a proper look next week and see if I can find anything amiss.

@ojeytonwilliams ojeytonwilliams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @gikf this looks really solid. Thanks again for fixing all those conflicts.

I only spotted one thing that looked like a bug, the rest are nitpicks:

Comment thread server/prisma/schema.prisma Outdated
notifying Boolean @default(false)
event events @relation(fields: [event_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
user users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
rsvp rsvp @relation(fields: [rsvp_id], references: [id], onDelete: Cascade, onUpdate: NoAction)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this reference event_users? The rsvp table just stores the types of rsvps, now.

Since this didn't trip up any tests, it would be good to add some coverage for the reminders.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't know honestly, but not necessarily. It definitely can have such reference added. I found simply replacing old rsvps with event_users a bit redundant. Other than rsvp -> name (due to it being in the reminder text placeholder), there isn't anything else in event_user needed, that's not already available from events or users relations.

Therefore it was for me either leaving relations with events, users and adding missing new rsvp, or replacing all three with event_users. Does this make sense? What do you think?

As for tests - there were merge conflicts triggered! 😛

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, so reminders can only exist if there's an event_user because if someone has no relationship to an event, they definitely don't want a reminder. To me, it makes most sense to go with your idea of replacing all three with a single event_user reference.

I've been messing with this locally, do you mind if I push a commit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not at all, go ahead. 👍

But make sure you have the latest changes, I was correcting merge conflicts earlier today.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the warning, I'll double-check!

Comment thread server/src/graphql-types/EventUser.ts Resolved
@gikf
gikf marked this pull request as ready for review April 23, 2022 11:44
@allella allella mentioned this pull request Apr 29, 2022
Comment on lines +32 to +42
interface RsvpInvitationUser {
first_name: string;
email: string;
}
interface RsvpInvitationEvent {
name: string;
start_at: Date;
ends_at: Date;
description: string;
venue: Venue | null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
interface RsvpInvitationUser {
first_name: string;
email: string;
}
interface RsvpInvitationEvent {
name: string;
start_at: Date;
ends_at: Date;
description: string;
venue: Venue | null;
}

Rather than recreating these types, we can pull them out of prisma, I'll add a suggestion below.

EventUser,
EventWithRelations,
EventWithChapter,
Venue,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Venue,
User,

See below

Comment on lines +43 to +45
const sendRsvpInvitation = async (
user: RsvpInvitationUser,
event: RsvpInvitationEvent,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const sendRsvpInvitation = async (
user: RsvpInvitationUser,
event: RsvpInvitationEvent,
const sendRsvpInvitation = async (
user: User,
event: events & { venue: venues | null },

This also avoids mixing the GraphQL types (like Venue) with the Prisma return types. This doesn't matter a great deal, but it makes 100% clear where things are coming from.

Comment on lines +70 to +77
interface RsvpNotificationUser {
first_name: string;
last_name: string;
}
interface RsvpNotificationEvent {
name: string;
event_users: Pick<EventUser, 'user' | 'event_role'>[];
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
interface RsvpNotificationUser {
first_name: string;
last_name: string;
}
interface RsvpNotificationEvent {
name: string;
event_users: Pick<EventUser, 'user' | 'event_role'>[];
}
type RsvpNotificationEvent = events & {
event_users: { event_role: event_roles; user: users }[];
};

Same principle as above, but this is a little bigger, so it seemed better to create an alias.

event_users: Pick<EventUser, 'user' | 'event_role'>[];
}
const rsvpNotifyOrganizer = async (
user: RsvpNotificationUser,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
user: RsvpNotificationUser,
user: User,

Comment on lines +92 to +96
interface EventRsvpName {
capacity: number;
event_users: Pick<EventUser, 'rsvp'>[];
invite_only: boolean;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
interface EventRsvpName {
capacity: number;
event_users: Pick<EventUser, 'rsvp'>[];
invite_only: boolean;
}
type EventRsvpName = events & { event_users: (event_users & { rsvp: rsvp })[] };

Same principle again.

Comment thread server/prisma/schema.prisma Outdated
notifying Boolean @default(false)
event events @relation(fields: [event_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
user users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
rsvp rsvp @relation(fields: [rsvp_id], references: [id], onDelete: Cascade, onUpdate: NoAction)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, so reminders can only exist if there's an event_user because if someone has no relationship to an event, they definitely don't want a reminder. To me, it makes most sense to go with your idea of replacing all three with a single event_user reference.

I've been messing with this locally, do you mind if I push a commit?

Also various minor refactors
@ojeytonwilliams

Copy link
Copy Markdown
Contributor

@gikf all done. Let me know if you're happy with these last changes. If you are, we can finally get this in!

@gikf

gikf commented May 10, 2022

Copy link
Copy Markdown
Member Author

I didn't find anything sticking out 👍

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

Great, thanks for checking. I'm very happy to finally get this in.

@ojeytonwilliams
ojeytonwilliams merged commit 545e083 into freeCodeCamp:main May 11, 2022
@gikf
gikf deleted the feat/event-roles-tables branch May 11, 2022 08:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants