add select primary calendar (#1133)

* add primary

* fix

* refactor eventmanager to take `CalendarDestination`

* `DestinationCalendar`

* fix

* wip

* wip

* Minor fixes (#1156)

* Followup for #1242

* Updates schema

* Renames fields to destinationCalendar

* Migration fixes

* Updates user destination calendar

* Abstracts convertDate to BaseCalendarApiAdapter

* Type fixes

* Uses abstracted convertDate method

* Abstracts getDuration and getAttendees

* Fixes circular dependecy issue

* Adds notEmpty util

* Reverts empty location string

* Fixes property name

* Removes deprecated code

* WIP

* AppleCal is basically CalDav

* Fixes missing destinationCalendar

* Type fixes

* Select primary calendar on Office and gCal

* Adds pretty basic instructions for destination calendar

* Cleanup

* Type fix

* Test fixes

* Updates test snapshot

* Local test fixes

* Type fixes

Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Omar López <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2021-12-09 15:51:37 +00:00
1 parent 1890d5daf7
commit 850497ea80
26 files changed
+745 -917

No files matched your search

+1
View File
@@ -61,6 +61,7 @@ async function getUserFromSession({
},
},
completedOnboarding: true,
destinationCalendar: true,
locale: true,
},
});
+36 -1
View File
@@ -376,7 +376,42 @@ const loggedInViewerRouter = createProtectedRouter()
// get all the connected integrations' calendars (from third party)
const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
return connectedCalendars;
return {
connectedCalendars,
destinationCalendar: user.destinationCalendar,
};
},
})
.mutation("setUserDestinationCalendar", {
input: z.object({
integration: z.string(),
externalId: z.string(),
}),
async resolve({ ctx, input }) {
const { user } = ctx;
const userId = ctx.user.id;
const calendarCredentials = getCalendarCredentials(user.credentials, user.id);
const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
const allCals = connectedCalendars.map((cal) => cal.calendars ?? []).flat();
if (
!allCals.find((cal) => cal.externalId === input.externalId && cal.integration === input.integration)
) {
throw new TRPCError({ code: "BAD_REQUEST", message: `Could not find calendar ${input.externalId}` });
}
await ctx.prisma.destinationCalendar.upsert({
where: {
userId,
},
update: {
...input,
userId,
},
create: {
...input,
userId,
},
});
},
})
.query("integrations", {