Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve] Do not delete original booking when rescheduling #91

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions packages/core/EventManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DestinationCalendar } from "@prisma/client";
import { BookingStatus } from "@prisma/client";
import merge from "lodash/merge";
import { v5 as uuidv5 } from "uuid";
import { z } from "zod";
Expand All @@ -9,7 +10,6 @@ import { MeetLocationType } from "@calcom/app-store/locations";
import getApps from "@calcom/app-store/utils";
import logger from "@calcom/lib/logger";
import prisma from "@calcom/prisma";
import { Attendee } from "@calcom/prisma/client";
import { createdEventSchema } from "@calcom/prisma/zod-utils";
import type {
AdditionalInformation,
Expand Down Expand Up @@ -277,26 +277,17 @@ export default class EventManager {
});
}

// Now we can delete the old booking and its references.
const bookingReferenceDeletes = prisma.bookingReference.deleteMany({
where: {
bookingId: booking.id,
},
});
const attendeeDeletes = prisma.attendee.deleteMany({
where: {
bookingId: booking.id,
},
});

const bookingDeletes = prisma.booking.delete({
const bookingUpdate = prisma.booking.update({
where: {
id: booking.id,
},
data: {
// TODO: use RESCHEDULED status
status: BookingStatus.CANCELLED,
},
});

// Wait for all deletions to be applied.
await Promise.all([bookingReferenceDeletes, attendeeDeletes, bookingDeletes]);
await Promise.all([bookingUpdate]);

// Very similar to what is done in create(). But a reschedule might update an event or create a new one.
const referencesToCreate = results.map((result) => {
Expand Down
Loading