Scheduling infrastructure for absolutely everyone.
fix: Selected calendar unhandled promise when removing calendars (#11281)
Joe Au-Yeung75f9dad16eb6
diff --git a/packages/trpc/server/routers/loggedInViewer/deleteCredential.handler.ts b/packages/trpc/server/routers/loggedInViewer/deleteCredential.handler.tsindex 601c3ea0584..2b6e4446337 100644--- a/packages/trpc/server/routers/loggedInViewer/deleteCredential.handler.ts+++ b/packages/trpc/server/routers/loggedInViewer/deleteCredential.handler.ts@@ -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 }: DeleteCredentialOpbookingFields: true,seatsPerTimeSlot: true,seatsShowAttendees: true,- seatsShowAvailabilityCount: true,eventName: true,},},@@ -296,7 +296,6 @@ export const deleteCredentialHandler = async ({ ctx, input }: DeleteCredentialOpcancellationReason: "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 SelectedCalendarsif (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 }: DeleteCredentialOpintegration: 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}`);+ });}}