fix: Booker fix for team + user with same event + event slug (#9654)

Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
Jeroen ReumkensandHariom Balhara authored and GitHub committed 2023-06-21 13:01:55 +05:30
1 parent b070cfb227
commit ab6781cd72
9 files changed
+86 -22

No files matched your search

@@ -76,7 +76,12 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
hidden: true,
});
export const getPublicEvent = async (username: string, eventSlug: string, prisma: PrismaClient) => {
export const getPublicEvent = async (
username: string,
eventSlug: string,
isTeamEvent: boolean | undefined,
prisma: PrismaClient
) => {
const usernameList = username.split("+");
// In case of dynamic group event, we fetch user's data and use the default event.
@@ -141,24 +146,26 @@ export const getPublicEvent = async (username: string, eventSlug: string, prisma
};
}
const usersOrTeamQuery = isTeamEvent
? {
team: {
slug: username,
},
}
: {
users: {
some: {
username,
},
},
team: null,
};
// In case it's not a group event, it's either a single user or a team, and we query that data.
const event = await prisma.eventType.findFirst({
where: {
slug: eventSlug,
OR: [
{
users: {
some: {
username,
},
},
},
{
team: {
slug: username,
},
},
],
...usersOrTeamQuery,
},
select: publicEventSelect,
});