Skip to content

Commit

Permalink
chore: use Promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
Udit-takkar committed Oct 14, 2024
1 parent d409e75 commit 84385ff
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions packages/trpc/server/routers/viewer/bookings/confirm.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,24 @@ const checkIfUserIsAuthorizedToConfirmBooking = async ({

// Check if user is associated with the event type
if (eventTypeId) {
const eventType = await prisma.eventType.findUnique({
where: {
id: eventTypeId,
OR: [{ hosts: { some: { userId: loggedInUserId } } }, { users: { some: { id: loggedInUserId } } }],
},
});
if (eventType) return;
const [loggedInUserAsHostOfEventType, loggedInUserAsUserOfEventType] = await Promise.all([
prisma.eventType.findUnique({
where: {
id: eventTypeId,
hosts: { some: { userId: loggedInUserId } },
},
select: { id: true },
}),
prisma.eventType.findUnique({
where: {
id: eventTypeId,
users: { some: { id: loggedInUserId } },
},
select: { id: true },
}),
]);

if (loggedInUserAsHostOfEventType || loggedInUserAsUserOfEventType) return;
}

// Check if the user is an admin/owner of the team the booking belongs to
Expand All @@ -449,7 +460,9 @@ const checkIfUserIsAuthorizedToConfirmBooking = async ({
where: {
userId: loggedInUserId,
teamId: teamId,
OR: [{ role: MembershipRole.OWNER }, { role: MembershipRole.ADMIN }],
role: {
in: [MembershipRole.OWNER, MembershipRole.ADMIN],
},
},
});
if (membership) return;
Expand Down

0 comments on commit 84385ff

Please sign in to comment.