fix: query Host table directly to determine isCurrentUserHost flag (#27268)
The previous implementation relied on the hosts array returned from findTeamEventTypes, which is limited to 5 hosts for display purposes. This caused the 'Assigned' badge to not show for users who were hosts but not in the first 5 returned by the query. This fix queries the Host table directly with a single batch query to get all event type IDs where the current user is a host, ensuring the badge shows correctly regardless of how many hosts an event type has. Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: ali@cal.com <ali@cal.com>
This commit is contained in:
co-authored by
ali@cal.com
parent
de02a96525
commit
101cef72ac
@@ -152,10 +152,21 @@ export const getEventTypesFromGroup = async ({
|
||||
|
||||
const mappedEventTypes: MappedEventType[] = await Promise.all(eventTypes.map(mapEventType));
|
||||
|
||||
// Add isCurrentUserHost flag to each event type
|
||||
const eventTypeIds = mappedEventTypes.map((et) => et.id);
|
||||
const userHostEntries = await prisma.host.findMany({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
eventTypeId: { in: eventTypeIds },
|
||||
},
|
||||
select: {
|
||||
eventTypeId: true,
|
||||
},
|
||||
});
|
||||
const eventTypeIdsWhereUserIsHost = new Set(userHostEntries.map((h) => h.eventTypeId));
|
||||
|
||||
const eventTypesWithHostFlag = mappedEventTypes.map((eventType) => ({
|
||||
...eventType,
|
||||
isCurrentUserHost: eventType.hosts?.some((host) => host.user.id === ctx.user.id) ?? false,
|
||||
isCurrentUserHost: eventTypeIdsWhereUserIsHost.has(eventType.id),
|
||||
}));
|
||||
|
||||
const membership = await prisma.membership.findFirst({
|
||||
|
||||
Reference in New Issue
Block a user