fix: Can cancel an already cancelled booking through the API (#22128)
* fix: can cancel already cancelled booking * add test * fix test * update * Update bookings.service.ts * add commnet * update * tweak
This commit is contained in:
1 parent
b599ce4919
commit
aa3086cfae
5 files changed
+82
No files matched your search
@@ -232,6 +232,15 @@ export class BookingsController_2024_04_15 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bookingUid) {
|
if (bookingUid) {
|
||||||
|
const { bookingInfo } = await getBookingInfo(bookingUid);
|
||||||
|
if (!bookingInfo) {
|
||||||
|
throw new NotFoundException(`Booking with UID=${bookingUid} does not exist.`);
|
||||||
|
}
|
||||||
|
if (bookingInfo.status === "CANCELLED") {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`Can't cancel booking with uid=${bookingUid} because it has been cancelled already. Please provide uid of a booking that is not cancelled.`
|
||||||
|
);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
req.body.uid = bookingUid;
|
req.body.uid = bookingUid;
|
||||||
const bookingRequest = await this.createNextApiBookingRequest(req, oAuthClientId, undefined, isEmbed);
|
const bookingRequest = await this.createNextApiBookingRequest(req, oAuthClientId, undefined, isEmbed);
|
||||||
|
|||||||
@@ -2553,6 +2553,59 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("cant't cancel already cancelled booking", () => {
|
||||||
|
it("should not be able to cancel alraedy cancelled booking", async () => {
|
||||||
|
const cancelledBooking = await bookingsRepositoryFixture.create({
|
||||||
|
status: "CANCELLED",
|
||||||
|
user: {
|
||||||
|
connect: {
|
||||||
|
id: user.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
startTime: new Date(Date.UTC(2050, 0, 8, 13, 0, 0)),
|
||||||
|
endTime: new Date(Date.UTC(2050, 0, 8, 14, 0, 0)),
|
||||||
|
title: "peer coding lets goo",
|
||||||
|
uid: `cancelled-booking-${randomString()}`,
|
||||||
|
eventType: {
|
||||||
|
connect: {
|
||||||
|
id: eventTypeId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
location: "integrations:daily",
|
||||||
|
customInputs: {},
|
||||||
|
metadata: {},
|
||||||
|
responses: {
|
||||||
|
name: "Oldie",
|
||||||
|
email: "[email protected]",
|
||||||
|
},
|
||||||
|
attendees: {
|
||||||
|
create: {
|
||||||
|
email: "[email protected]",
|
||||||
|
name: "Oldie",
|
||||||
|
locale: "lv",
|
||||||
|
timeZone: "Europe/Rome",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const body: CancelBookingInput_2024_08_13 = {
|
||||||
|
cancellationReason: "Going on a vacation",
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await request(app.getHttpServer())
|
||||||
|
.post(`/v2/bookings/${cancelledBooking.uid}/cancel`)
|
||||||
|
.send(body)
|
||||||
|
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||||
|
.set(X_CAL_CLIENT_ID, oAuthClient.id)
|
||||||
|
.expect(400);
|
||||||
|
|
||||||
|
expect(response.body.error.message).toEqual(
|
||||||
|
`Can't cancel booking with uid=${cancelledBooking.uid} because it has been cancelled already. Please provide uid of a booking that is not cancelled.`
|
||||||
|
);
|
||||||
|
await bookingsRepositoryFixture.deleteById(cancelledBooking.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("calendar events", () => {
|
describe("calendar events", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
|
|||||||
@@ -711,6 +711,12 @@ export class InputBookingsService_2024_08_13 {
|
|||||||
throw new NotFoundException(`Booking with uid=${bookingUid} not found`);
|
throw new NotFoundException(`Booking with uid=${bookingUid} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (booking.status === "CANCELLED") {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`Can't cancel booking with uid=${bookingUid} because it has been cancelled already. Please provide uid of a booking that is not cancelled.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const oAuthClientParams = booking.eventTypeId
|
const oAuthClientParams = booking.eventTypeId
|
||||||
? await this.platformBookingsService.getOAuthClientParams(booking.eventTypeId)
|
? await this.platformBookingsService.getOAuthClientParams(booking.eventTypeId)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ export async function getBookingToDelete(id: number | undefined, uid: string | u
|
|||||||
responses: true,
|
responses: true,
|
||||||
iCalUID: true,
|
iCalUID: true,
|
||||||
iCalSequence: true,
|
iCalSequence: true,
|
||||||
|
status: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,19 @@ async function handler(input: CancelBookingInput) {
|
|||||||
arePlatformEmailsEnabled,
|
arePlatformEmailsEnabled,
|
||||||
} = input;
|
} = input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Important: We prevent cancelling an already cancelled booking.
|
||||||
|
* A booking could have been CANCELLED due to a reschedule,
|
||||||
|
* in which case we simply update the existing calendar event and meeting.
|
||||||
|
* We want to avoid deleting them by a subsequent cancellation attempt.
|
||||||
|
*/
|
||||||
|
if (bookingToDelete.status === BookingStatus.CANCELLED) {
|
||||||
|
throw new HttpError({
|
||||||
|
statusCode: 400,
|
||||||
|
message: "This booking has already been cancelled.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!bookingToDelete.userId || !bookingToDelete.user) {
|
if (!bookingToDelete.userId || !bookingToDelete.user) {
|
||||||
throw new HttpError({ statusCode: 400, message: "User not found" });
|
throw new HttpError({ statusCode: 400, message: "User not found" });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user