Skip to content

Commit

Permalink
fix: adds teamId to team events payload (#12417)
Browse files Browse the repository at this point in the history
  • Loading branch information
manpoffc authored Nov 22, 2023
1 parent 2171a32 commit 36d3153
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core/builders/CalendarEvent/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CalendarEventClass implements CalendarEvent {
organizer!: Person;
attendees!: Person[];
description?: string | null;
team?: { name: string; members: Person[] };
team?: { name: string; members: Person[]; id: number };
location?: string | null;
conferenceData?: ConferenceData;
additionalInformation?: AdditionalInformation;
Expand Down
20 changes: 13 additions & 7 deletions packages/features/bookings/lib/handleCancelBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ async function getBookingToDelete(id: number | undefined, uid: string | undefine
hideBranding: true,
},
},
teamId: true,
team: {
select: {
id: true,
name: true,
},
},
recurringEvent: true,
title: true,
eventName: true,
Expand Down Expand Up @@ -151,11 +156,10 @@ async function handler(req: CustomRequest) {

const teamId = await getTeamIdFromEventType({
eventType: {
team: { id: bookingToDelete.eventType?.teamId ?? null },
team: { id: bookingToDelete.eventType?.team?.id ?? null },
parentId: bookingToDelete?.eventType?.parentId ?? null,
},
});

const triggerForUser = !teamId || (teamId && bookingToDelete.eventType?.parentId);

const subscriberOptions = {
Expand Down Expand Up @@ -255,7 +259,9 @@ async function handler(req: CustomRequest) {
? [bookingToDelete?.user.destinationCalendar]
: [],
cancellationReason: cancellationReason,
...(teamMembers && { team: { name: "", members: teamMembers } }),
...(teamMembers && {
team: { name: bookingToDelete?.eventType?.team?.name || "Nameless", members: teamMembers, id: teamId! },
}),
seatsPerTimeSlot: bookingToDelete.eventType?.seatsPerTimeSlot,
seatsShowAttendees: bookingToDelete.eventType?.seatsShowAttendees,
};
Expand Down Expand Up @@ -408,7 +414,7 @@ async function handler(req: CustomRequest) {
if (bookingToDelete.location === DailyLocationType) {
bookingToDelete.user.credentials.push({
...FAKE_DAILY_CREDENTIAL,
teamId: bookingToDelete.eventType?.teamId || null,
teamId: bookingToDelete.eventType?.team?.id || null,
});
}

Expand Down Expand Up @@ -540,10 +546,10 @@ async function handler(req: CustomRequest) {
let eventTypeOwnerId;
if (bookingToDelete.eventType?.owner) {
eventTypeOwnerId = bookingToDelete.eventType.owner.id;
} else if (bookingToDelete.eventType?.teamId) {
} else if (bookingToDelete.eventType?.team?.id) {
const teamOwner = await prisma.membership.findFirst({
where: {
teamId: bookingToDelete.eventType.teamId,
teamId: bookingToDelete.eventType?.team.id,
role: MembershipRole.OWNER,
},
select: {
Expand Down
2 changes: 1 addition & 1 deletion packages/features/bookings/lib/handleNewBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ async function handler(
},
};
});

const teamMembers = await Promise.all(teamMemberPromises);

const attendeesList = [...invitee, ...guests];
Expand Down Expand Up @@ -1887,6 +1886,7 @@ async function handler(
evt.team = {
members: teamMembers,
name: eventType.team?.name || "Nameless",
id: eventType.team?.id ?? 0,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/Calendar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export interface CalendarEvent {
team?: {
name: string;
members: TeamMember[];
id: number;
};
location?: string | null;
conferenceCredentialId?: number;
Expand Down

0 comments on commit 36d3153

Please sign in to comment.