Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
fix: event-type filters (calcom#11552)
Browse files Browse the repository at this point in the history
Co-authored-by: Udit Takkar <[email protected]>
  • Loading branch information
SomayChauhan and Udit-takkar authored Sep 28, 2023
1 parent 2021b64 commit 57e712d
Showing 1 changed file with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,22 @@ export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) =>

const image = user?.username ? `${CAL_URL}/${user.username}/avatar.png` : undefined;

eventTypeGroups.push({
teamId: null,
membershipRole: null,
profile: {
slug: user.username,
name: user.name,
image,
},
eventTypes: orderBy(unmanagedEventTypes, ["position", "id"], ["desc", "asc"]),
metadata: {
membershipCount: 1,
readOnly: false,
},
});
if (!input?.filters || !hasFilter(input?.filters) || input?.filters?.userIds?.includes(user.id)) {
eventTypeGroups.push({
teamId: null,
membershipRole: null,
profile: {
slug: user.username,
name: user.name,
image,
},
eventTypes: orderBy(unmanagedEventTypes, ["position", "id"], ["desc", "asc"]),
metadata: {
membershipCount: 1,
readOnly: false,
},
});
}

const teamMemberships = user.teams.map((membership) => ({
teamId: membership.team.id,
Expand All @@ -222,13 +224,19 @@ export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) =>
}
return input?.filters?.teamIds?.includes(eventType?.team?.id || 0) ?? false;
};

eventTypeGroups = ([] as EventTypeGroup[]).concat(
eventTypeGroups,
user.teams
.filter((mmship) => {
const metadata = teamMetadataSchema.parse(mmship.team.metadata);
return !metadata?.isOrganization;
if (metadata?.isOrganization) {
return false;
} else {
if (!input?.filters || !hasFilter(input?.filters)) {
return true;
}
return input?.filters?.teamIds?.includes(mmship?.team?.id || 0) ?? false;
}
})
.map((membership) => {
const orgMembership = teamMemberships.find(
Expand Down

0 comments on commit 57e712d

Please sign in to comment.