fix: Selected calendar unhandled promise when removing calendars (#11281)

pull/11285/head
Joe Au-Yeung 2023-09-11 14:39:27 -04:00 committed by GitHub
parent 0a0d212373
commit 75f9dad16e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 12 deletions

View File

@ -1,3 +1,4 @@
import { Prisma } from "@prisma/client";
import z from "zod";
import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
@ -206,7 +207,6 @@ export const deleteCredentialHandler = async ({ ctx, input }: DeleteCredentialOp
bookingFields: true,
seatsPerTimeSlot: true,
seatsShowAttendees: true,
seatsShowAvailabilityCount: true,
eventName: true,
},
},
@ -296,7 +296,6 @@ export const deleteCredentialHandler = async ({ ctx, input }: DeleteCredentialOp
cancellationReason: "Payment method removed by organizer",
seatsPerTimeSlot: booking.eventType?.seatsPerTimeSlot,
seatsShowAttendees: booking.eventType?.seatsShowAttendees,
seatsShowAvailabilityCount: booking.eventType?.seatsShowAvailabilityCount,
},
{
eventName: booking?.eventType?.eventName,
@ -310,14 +309,14 @@ export const deleteCredentialHandler = async ({ ctx, input }: DeleteCredentialOp
// If it's a calendar remove it from the SelectedCalendars
if (credential.app?.categories.includes(AppCategories.calendar)) {
try {
const calendar = await getCalendar(credential);
const calendar = await getCalendar(credential);
const calendars = await calendar?.listCalendars();
const calendars = await calendar?.listCalendars();
if (calendars && calendars.length > 0) {
calendars.map(async (cal) => {
await prisma.selectedCalendar.delete({
if (calendars && calendars.length > 0) {
calendars.map(async (cal) => {
prisma.selectedCalendar
.delete({
where: {
userId_integration_externalId: {
userId: user.id,
@ -325,11 +324,18 @@ export const deleteCredentialHandler = async ({ ctx, input }: DeleteCredentialOp
integration: cal.integration as string,
},
},
})
.catch((error) => {
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2025") {
console.log(
`Error deleting selected calendars for user ${user.id} and calendar ${credential.appId}. Could not find selected calendar.`
);
}
console.log(
`Error deleting selected calendars for user ${user.id} and calendar ${credential.appId} with error: ${error}`
);
});
});
}
} catch {
console.log(`Error deleting selected calendars for user ${user.id} and calendar ${credential.appId}`);
});
}
}