From 75f9dad16eb6e0b88e33777a6e45d85ddfabb763 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:39:27 -0400 Subject: [PATCH] fix: Selected calendar unhandled promise when removing calendars (#11281) --- .../deleteCredential.handler.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/trpc/server/routers/loggedInViewer/deleteCredential.handler.ts b/packages/trpc/server/routers/loggedInViewer/deleteCredential.handler.ts index 601c3ea058..2b6e444633 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 }: 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}`); + }); } }