Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
If the calendar couldn't be returned for whatever reason, exclude it …
Browse files Browse the repository at this point in the history
…from the output
  • Loading branch information
MatsAnd committed Sep 18, 2020
1 parent f7c90b2 commit 504ec46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions lib/get-user-event-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ module.exports = async (context, token, graphUser) => {

context.log('user tabs', userTabs)

const tabEvents = await Promise.all(userTabs.map(async tab => ({
tabName: tab.TabName,
sortOrder: tab.SortOrder,
events: await getGraphEvents(context, token, userPrincipalName, tab.CalendarUrl)
})))

const sortedTabs = tabEvents.sort((a, b) => a.sortOrder - b.sortOrder)
const tabEvents = await Promise.all(userTabs.map(async tab => {
const events = await getGraphEvents(context, token, userPrincipalName, tab.CalendarUrl)
if (!events) {
context.log.error(['events', userPrincipalName, 'err', `No events found for: ${tab.CalendarUrl}`])
return null // will be filtered out later
}

return {
tabName: tab.TabName,
sortOrder: tab.SortOrder,
events
}
}))

// Remove calendar tabs that wasn't found, and sort them by sortOrder.
const sortedTabs = tabEvents.filter(events => !!events).sort((a, b) => a.sortOrder - b.sortOrder)

context.log(sortedTabs)

Expand Down
2 changes: 1 addition & 1 deletion lib/graph/get-graph-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ module.exports = async (context, token, userPrincipalName, graphUserUrl) => {
return data.value
} catch (err) {
context.log.error(['events', 'get-graph-events', 'err', err])
throw err
return null
}
}

0 comments on commit 504ec46

Please # to comment.