Improved with some try catch and removed old behaviour (#9650)
parent
4323b0c2d1
commit
3559e0d082
|
@ -278,6 +278,7 @@ async function handler(req: CustomRequest) {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await Promise.all(integrationsToDelete).then(async () => {
|
||||
if (lastAttendee) {
|
||||
await prisma.booking.update({
|
||||
|
@ -290,6 +291,10 @@ async function handler(req: CustomRequest) {
|
|||
});
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
// Shouldn't stop code execution if integrations fail
|
||||
// as integrations was already deleted
|
||||
}
|
||||
|
||||
const tAttendees = await getTranslation(attendee.locale ?? "en", "common");
|
||||
|
||||
|
@ -510,14 +515,6 @@ async function handler(req: CustomRequest) {
|
|||
apiDeletes.push(deleteMeeting(videoCredential, uid));
|
||||
}
|
||||
}
|
||||
// For bookings made before this refactor we go through the old behaviour of running through each video credential
|
||||
} else {
|
||||
bookingToDelete.user.credentials
|
||||
.filter((credential) => credential.type.endsWith("_video"))
|
||||
.forEach((credential) => {
|
||||
const uidToDelete = bookingToDelete?.references?.[0]?.uid ?? bookingToDelete.uid;
|
||||
apiDeletes.push(deleteMeeting(credential, uidToDelete));
|
||||
});
|
||||
}
|
||||
|
||||
// Avoiding taking care of recurrence for now as Payments are not supported with Recurring Events at the moment
|
||||
|
@ -626,7 +623,11 @@ async function handler(req: CustomRequest) {
|
|||
});
|
||||
|
||||
// We skip the deletion of the event, because that would also delete the payment reference, which we should keep
|
||||
try {
|
||||
await apiDeletes;
|
||||
} catch (error) {
|
||||
console.error("Error deleting event", error);
|
||||
}
|
||||
req.statusCode = 200;
|
||||
return { message: "Booking successfully cancelled." };
|
||||
}
|
||||
|
@ -655,10 +656,15 @@ async function handler(req: CustomRequest) {
|
|||
|
||||
const prismaPromises: Promise<unknown>[] = [bookingReferenceDeletes];
|
||||
|
||||
// @TODO: find a way in the future if a promise fails don't stop the rest of the promises
|
||||
// Also if emails fails try to requeue them
|
||||
try {
|
||||
await Promise.all(prismaPromises.concat(apiDeletes));
|
||||
|
||||
await sendCancelledEmails(evt, { eventName: bookingToDelete?.eventType?.eventName });
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error deleting event", error);
|
||||
}
|
||||
req.statusCode = 200;
|
||||
return { message: "Booking successfully cancelled." };
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue