feat: v2 subsequent recurring booking cancellation (#17645)
* refactor: cancelling all remaining seated recurring bookings not possible * chore: document cancel booking endpoint * chore: remove unused imports * feat: cancel subsequent bookigns * fix: flaky test * refactor: getCanceledSubsequentBookings * refactor: after cancellation return whole recurrence sequence
This commit is contained in:
1 parent
ce0d685849
commit
2b1041460c
16 files changed
+814
-343
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsFile, { GenerateIcsRole } from "../lib/generateIcsFile";
|
||||
import AttendeeScheduledEmail from "./attendee-scheduled-email";
|
||||
@@ -17,11 +19,15 @@ export default class AttendeeCancelledEmail extends AttendeeScheduledEmail {
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(),
|
||||
})}`,
|
||||
html: await renderEmail("AttendeeCancelledEmail", {
|
||||
calEvent: this.calEvent,
|
||||
attendee: this.attendee,
|
||||
}),
|
||||
html: await this.getHtml(this.calEvent, this.attendee),
|
||||
text: this.getTextBody("event_request_cancelled", "emailed_you_and_any_other_attendees"),
|
||||
};
|
||||
}
|
||||
|
||||
protected async getHtml(calEvent: CalendarEvent, attendee: Person) {
|
||||
return await renderEmail("AttendeeCancelledEmail", {
|
||||
calEvent,
|
||||
attendee,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
|
||||
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
|
||||
|
||||
import { renderEmail } from "../";
|
||||
import generateIcsFile, { GenerateIcsRole } from "../lib/generateIcsFile";
|
||||
@@ -20,11 +21,15 @@ export default class OrganizerCancelledEmail extends OrganizerScheduledEmail {
|
||||
title: this.calEvent.title,
|
||||
date: this.getFormattedDate(),
|
||||
})}`,
|
||||
html: await renderEmail("OrganizerCancelledEmail", {
|
||||
attendee: this.calEvent.organizer,
|
||||
calEvent: this.calEvent,
|
||||
}),
|
||||
html: await this.getHtml(this.calEvent, this.calEvent.organizer),
|
||||
text: this.getTextBody("event_request_cancelled"),
|
||||
};
|
||||
}
|
||||
|
||||
protected async getHtml(calEvent: CalendarEvent, organizer: Person) {
|
||||
return await renderEmail("OrganizerCancelledEmail", {
|
||||
calEvent,
|
||||
attendee: organizer,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -155,8 +155,15 @@ export type HandleCancelBookingResponse = {
|
||||
};
|
||||
|
||||
async function handler(req: CustomRequest) {
|
||||
const { id, uid, allRemainingBookings, cancellationReason, seatReferenceUid, cancelledBy } =
|
||||
bookingCancelInput.parse(req.body);
|
||||
const {
|
||||
id,
|
||||
uid,
|
||||
allRemainingBookings,
|
||||
cancellationReason,
|
||||
seatReferenceUid,
|
||||
cancelledBy,
|
||||
cancelSubsequentBookings,
|
||||
} = bookingCancelInput.parse(req.body);
|
||||
req.bookingToDelete = await getBookingToDelete(id, uid);
|
||||
const {
|
||||
bookingToDelete,
|
||||
@@ -406,14 +413,19 @@ async function handler(req: CustomRequest) {
|
||||
|
||||
// by cancelling first, and blocking whilst doing so; we can ensure a cancel
|
||||
// action always succeeds even if subsequent integrations fail cancellation.
|
||||
if (bookingToDelete.eventType?.recurringEvent && bookingToDelete.recurringEventId && allRemainingBookings) {
|
||||
if (
|
||||
bookingToDelete.eventType?.recurringEvent &&
|
||||
bookingToDelete.recurringEventId &&
|
||||
(allRemainingBookings || cancelSubsequentBookings)
|
||||
) {
|
||||
const recurringEventId = bookingToDelete.recurringEventId;
|
||||
const gte = cancelSubsequentBookings ? bookingToDelete.startTime : new Date();
|
||||
// Proceed to mark as cancelled all remaining recurring events instances (greater than or equal to right now)
|
||||
await prisma.booking.updateMany({
|
||||
where: {
|
||||
recurringEventId,
|
||||
startTime: {
|
||||
gte: new Date(),
|
||||
gte,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
|
||||
@@ -5,8 +5,10 @@ import { CalendarService as IcsFeedCalendarService } from "@calcom/app-store/ics
|
||||
import type { CredentialOwner } from "@calcom/app-store/types";
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import type { CredentialDataWithTeamName, LocationOption } from "@calcom/app-store/utils";
|
||||
import AttendeeCancelledEmail from "@calcom/emails/templates/attendee-cancelled-email";
|
||||
import AttendeeDeclinedEmail from "@calcom/emails/templates/attendee-declined-email";
|
||||
import AttendeeScheduledEmail from "@calcom/emails/templates/attendee-scheduled-email";
|
||||
import OrganizerCancelledEmail from "@calcom/emails/templates/organizer-cancelled-email";
|
||||
import OrganizerScheduledEmail from "@calcom/emails/templates/organizer-scheduled-email";
|
||||
import { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
|
||||
import getBookingInfo from "@calcom/features/bookings/lib/getBookingInfo";
|
||||
@@ -194,3 +196,7 @@ export { AttendeeScheduledEmail };
|
||||
export { OrganizerScheduledEmail };
|
||||
|
||||
export { AttendeeDeclinedEmail };
|
||||
|
||||
export { AttendeeCancelledEmail };
|
||||
|
||||
export { OrganizerCancelledEmail };
|
||||
@@ -1,11 +1,19 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsOptional, IsString } from "class-validator";
|
||||
import { IsBoolean, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CancelBookingInput_2024_08_13 {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({ example: "User requested cancellation" })
|
||||
cancellationReason?: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@ApiProperty({
|
||||
description:
|
||||
"For recurring non-seated booking - if true, cancel booking with the bookingUid of the individual recorrence and all recurrences that come after it.",
|
||||
})
|
||||
cancelSubsequentBookings?: boolean;
|
||||
}
|
||||
|
||||
export class CancelSeatedBookingInput_2024_08_13 {
|
||||
|
||||
@@ -327,7 +327,10 @@ export const bookingCreateBodySchemaForApi = extendedBookingCreateBody.merge(
|
||||
export const bookingCancelSchema = z.object({
|
||||
id: z.number().optional(),
|
||||
uid: z.string().optional(),
|
||||
// note(Lauris): allRemainingBookings will cancel all bookings that have start time greater than this moment.
|
||||
allRemainingBookings: z.boolean().optional(),
|
||||
// note(Lauris): cancelSubsequentBookings will cancel all bookings after one specified by id or uid.
|
||||
cancelSubsequentBookings: z.boolean().optional(),
|
||||
cancellationReason: z.string().optional(),
|
||||
seatReferenceUid: z.string().optional(),
|
||||
cancelledBy: z.string().email({ message: "Invalid email" }).optional(),
|
||||
|
||||
Reference in new issue
Block a user