Skip to content

Added new field 'email' in NylasCalendars column in UserMeetingSettin… #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/common/nylas.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ function nylasCalendarsSchema () {
type: Sequelize.STRING(5),
allowNull: false
},
email: {
field: 'email',
type: Sequelize.STRING,
validate: {
isEmail: {
msg: 'Please provide a valid email address'
}
}
},
id: {
field: 'id',
type: Sequelize.STRING(5),
Expand Down
9 changes: 5 additions & 4 deletions src/services/NylasService.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ async function createVirtualCalendarForUser (userId, userEmail, userFullName, ti
accountId: calendar.account_id,
accessToken,
accountProvider: provider,
isDeleted: false,
isPrimary: calendar.is_primary
email: userEmail,
isPrimary: calendar.is_primary,
isDeleted: false
}
}

Expand Down Expand Up @@ -87,9 +88,9 @@ async function getAccessToken (code) {
code
})

const { account_id: accountId, access_token: accessToken, provider } = res.data
const { account_id: accountId, access_token: accessToken, provider, email_address: email } = res.data

return { accountId, accessToken, provider }
return { accountId, accessToken, provider, email }
}

function getAvailableTimeFromSchedulingPage (page) {
Expand Down
16 changes: 8 additions & 8 deletions src/services/UserMeetingSettingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ async function ensureUserIsPermitted (currentUser, userMeetingSettingsUserId) {
*/
function stripUnwantedData (userMeetingSettings) {
if (userMeetingSettings.nylasCalendars) {
const availableCalendars = _.filter(userMeetingSettings.nylasCalendars, (item) => {
if (!item.isDeleted) {
return _.omit(item, ['accessToken', 'accountId'])
}
})
const availableCalendars = _.flatMap(
userMeetingSettings.nylasCalendars,
(item) => !item.isDeleted ? _.omit(item, ['accessToken', 'accountId', 'isDeleted']) : []
)

userMeetingSettings.nylasCalendars = availableCalendars
}
Expand Down Expand Up @@ -205,7 +204,7 @@ async function handleConnectCalendarCallback (reqQuery) {

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

const calendarDetails = {
accessToken,
id: primaryCalendar.id,
accountId,
accessToken,
accountProvider: provider,
id: primaryCalendar.id,
email,
isPrimary: true,
isDeleted: false
}
Expand Down