Attach credential id to destinationCalendar records (#3197)

This commit is contained in:
Joe Au-Yeung authored and GitHub committed 2022-07-01 21:55:27 +01:00
1 parent 2cbf46a323
commit 201d17264c
8 files changed
+31 -1

No files matched your search

+7 -1
View File
@@ -550,7 +550,11 @@ const loggedInViewerRouter = createProtectedRouter()
const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
const allCals = connectedCalendars.map((cal) => cal.calendars ?? []).flat();
if (!allCals.find((cal) => cal.externalId === externalId && cal.integration === integration)) {
const credentialId = allCals.find(
(cal) => cal.externalId === externalId && cal.integration === integration && cal.readOnly === false
)?.credentialId;
if (!credentialId) {
throw new TRPCError({ code: "BAD_REQUEST", message: `Could not find calendar ${input.externalId}` });
}
@@ -565,11 +569,13 @@ const loggedInViewerRouter = createProtectedRouter()
update: {
integration,
externalId,
credentialId,
},
create: {
...where,
integration,
externalId,
credentialId,
},
});
},