fix: use destination calendar email (#6886)
* fix: use destination calendar email to display correct primary email Signed-off-by: Udit Takkar <[email protected]> * fix: simplify logic Signed-off-by: Udit Takkar <[email protected]> --------- Signed-off-by: Udit Takkar <[email protected]>
This commit is contained in:
1 parent
39040fca9a
commit
6877d0f693
2 files changed
+10
-4
No files matched your search
@@ -322,6 +322,9 @@ const loggedInViewerRouter = router({
|
||||
// get all the connected integrations' calendars (from third party)
|
||||
const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
|
||||
|
||||
// store email of the destination calendar to display
|
||||
let destinationCalendarEmail = null;
|
||||
|
||||
if (connectedCalendars.length === 0) {
|
||||
/* As there are no connected calendars, delete the destination calendar if it exists */
|
||||
if (user.destinationCalendar) {
|
||||
@@ -335,7 +338,7 @@ const loggedInViewerRouter = router({
|
||||
There are connected calendars, but no destination calendar
|
||||
So create a default destination calendar with the first primary connected calendar
|
||||
*/
|
||||
const { integration = "", externalId = "", credentialId } = connectedCalendars[0].primary ?? {};
|
||||
const { integration = "", externalId = "", credentialId, email } = connectedCalendars[0].primary ?? {};
|
||||
user.destinationCalendar = await ctx.prisma.destinationCalendar.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
@@ -344,6 +347,7 @@ const loggedInViewerRouter = router({
|
||||
credentialId,
|
||||
},
|
||||
});
|
||||
destinationCalendarEmail = email ?? user.destinationCalendar?.externalId;
|
||||
} else {
|
||||
/* There are connected calendars and a destination calendar */
|
||||
|
||||
@@ -354,6 +358,7 @@ const loggedInViewerRouter = router({
|
||||
cal.externalId === user.destinationCalendar?.externalId &&
|
||||
cal.integration === user.destinationCalendar?.integration
|
||||
);
|
||||
|
||||
if (!destinationCal) {
|
||||
// If destinationCalendar is out of date, update it with the first primary connected calendar
|
||||
const { integration = "", externalId = "" } = connectedCalendars[0].primary ?? {};
|
||||
@@ -365,11 +370,13 @@ const loggedInViewerRouter = router({
|
||||
},
|
||||
});
|
||||
}
|
||||
destinationCalendarEmail = destinationCal?.email ?? user.destinationCalendar?.externalId;
|
||||
}
|
||||
|
||||
return {
|
||||
connectedCalendars,
|
||||
destinationCalendar: user.destinationCalendar,
|
||||
destinationCalendarEmail,
|
||||
};
|
||||
}),
|
||||
setDestinationCalendar: authedProcedure
|
||||
|
||||
Reference in new issue
Block a user