Skip to content

Commit 49e646c

Browse files
committed
Added new field 'email' in NylasCalendars column in UserMeetingSettings record.
In NylasService, creating a virtual calendar returns the result, but extends it with new email field - populated with current user's email. The method 'getAccessToken' is also modified to include the server sent email field in the parsed result. And in UserMeetingSettingsService, method 'stripUnwantedData' was accidentally not stripping the data correctly, but its fixed now. Also, the method 'handleConnectCalendarCallback' has been updated to include the email field when creating/updating calendars in UserMeetingSettings record.
1 parent f4f4aef commit 49e646c

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/common/nylas.js

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ function nylasCalendarsSchema () {
6060
type: Sequelize.STRING(5),
6161
allowNull: false
6262
},
63+
email: {
64+
field: 'email',
65+
type: Sequelize.STRING,
66+
validate: {
67+
isEmail: {
68+
msg: 'Please provide a valid email address'
69+
}
70+
}
71+
},
6372
id: {
6473
field: 'id',
6574
type: Sequelize.STRING(5),

src/services/NylasService.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ async function createVirtualCalendarForUser (userId, userEmail, userFullName, ti
5252
accountId: calendar.account_id,
5353
accessToken,
5454
accountProvider: provider,
55-
isDeleted: false,
56-
isPrimary: calendar.is_primary
55+
email: userEmail,
56+
isPrimary: calendar.is_primary,
57+
isDeleted: false
5758
}
5859
}
5960

@@ -87,9 +88,9 @@ async function getAccessToken (code) {
8788
code
8889
})
8990

90-
const { account_id: accountId, access_token: accessToken, provider } = res.data
91+
const { account_id: accountId, access_token: accessToken, provider, email_address: email } = res.data
9192

92-
return { accountId, accessToken, provider }
93+
return { accountId, accessToken, provider, email }
9394
}
9495

9596
function getAvailableTimeFromSchedulingPage (page) {

src/services/UserMeetingSettingsService.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ async function ensureUserIsPermitted (currentUser, userMeetingSettingsUserId) {
4949
*/
5050
function stripUnwantedData (userMeetingSettings) {
5151
if (userMeetingSettings.nylasCalendars) {
52-
const availableCalendars = _.filter(userMeetingSettings.nylasCalendars, (item) => {
53-
if (!item.isDeleted) {
54-
return _.omit(item, ['accessToken', 'accountId'])
55-
}
56-
})
52+
const availableCalendars = _.flatMap(
53+
userMeetingSettings.nylasCalendars,
54+
(item) => !item.isDeleted ? _.omit(item, ['accessToken', 'accountId', 'isDeleted']) : []
55+
)
5756

5857
userMeetingSettings.nylasCalendars = availableCalendars
5958
}
@@ -205,7 +204,7 @@ async function handleConnectCalendarCallback (reqQuery) {
205204

206205
try {
207206
// getting user's accessToken from Nylas using 'code' found in request query
208-
const { accessToken, accountId, provider } = await NylasService.getAccessToken(reqQuery.code)
207+
const { accessToken, accountId, provider, email } = await NylasService.getAccessToken(reqQuery.code)
209208
// view https://developer.nylas.com/docs/api/#post/oauth/token for error response schema
210209
if (!accessToken || !accountId) {
211210
throw new errors.BadRequestError('Error getting access token for the calendar.')
@@ -223,10 +222,11 @@ async function handleConnectCalendarCallback (reqQuery) {
223222
}
224223

225224
const calendarDetails = {
226-
accessToken,
225+
id: primaryCalendar.id,
227226
accountId,
227+
accessToken,
228228
accountProvider: provider,
229-
id: primaryCalendar.id,
229+
email,
230230
isPrimary: true,
231231
isDeleted: false
232232
}

0 commit comments

Comments
 (0)