Skip to content

Commit 5002aeb

Browse files
authored
Merge pull request #607 from mahidulalvi-bonic/feature/interview-update
Added new field 'email' in NylasCalendars column in UserMeetingSettin…
2 parents 971cc5f + 49e646c commit 5002aeb

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
}
@@ -215,7 +214,7 @@ async function handleConnectCalendarCallback (reqQuery) {
215214

216215
try {
217216
// getting user's accessToken from Nylas using 'code' found in request query
218-
const { accessToken, accountId, provider } = await NylasService.getAccessToken(reqQuery.code)
217+
const { accessToken, accountId, provider, email } = await NylasService.getAccessToken(reqQuery.code)
219218
// view https://developer.nylas.com/docs/api/#post/oauth/token for error response schema
220219
if (!accessToken || !accountId) {
221220
throw new errors.BadRequestError('Error getting access token for the calendar.')
@@ -233,10 +232,11 @@ async function handleConnectCalendarCallback (reqQuery) {
233232
}
234233

235234
const calendarDetails = {
236-
accessToken,
235+
id: primaryCalendar.id,
237236
accountId,
237+
accessToken,
238238
accountProvider: provider,
239-
id: primaryCalendar.id,
239+
email,
240240
isPrimary: true,
241241
isDeleted: false
242242
}

0 commit comments

Comments
 (0)