Minimized msgraph calls while event listing by batching
This commit is contained in:
parent
90d6f8faee
commit
496fcdfabc
1 changed files with 32 additions and 22 deletions
|
@ -225,28 +225,38 @@ const MicrosoftOffice365Calendar = (credential): CalendarApiAdapter => {
|
||||||
? listCalendars().then((cals) => cals.map((e) => e.externalId))
|
? listCalendars().then((cals) => cals.map((e) => e.externalId))
|
||||||
: Promise.resolve(selectedCalendarIds).then((x) => x)
|
: Promise.resolve(selectedCalendarIds).then((x) => x)
|
||||||
).then((ids: string[]) => {
|
).then((ids: string[]) => {
|
||||||
const urls = ids.map(
|
const requests = ids.map((calendarId, id) => ({
|
||||||
(calendarId) =>
|
id,
|
||||||
"https://graph.microsoft.com/v1.0/me/calendars/" + calendarId + "/events" + filter
|
method: "GET",
|
||||||
);
|
headers: {
|
||||||
return Promise.all(
|
Prefer: 'outlook.timezone="Etc/GMT"',
|
||||||
urls.map((url) =>
|
},
|
||||||
fetch(url, {
|
url: `/me/calendars/${calendarId}/events${filter}`,
|
||||||
method: "get",
|
}));
|
||||||
headers: {
|
|
||||||
Authorization: "Bearer " + accessToken,
|
return fetch("https://graph.microsoft.com/v1.0/$batch", {
|
||||||
Prefer: 'outlook.timezone="Etc/GMT"',
|
method: "POST",
|
||||||
},
|
headers: {
|
||||||
})
|
Authorization: "Bearer " + accessToken,
|
||||||
.then(handleErrorsJson)
|
"Content-Type": "application/json",
|
||||||
.then((responseBody) =>
|
},
|
||||||
responseBody.value.map((evt) => ({
|
body: JSON.stringify({ requests }),
|
||||||
start: evt.start.dateTime + "Z",
|
})
|
||||||
end: evt.end.dateTime + "Z",
|
.then(handleErrorsJson)
|
||||||
}))
|
.then((responseBody) =>
|
||||||
)
|
responseBody.responses.reduce(
|
||||||
)
|
(acc, subResponse) =>
|
||||||
).then((results) => results.reduce((acc, events) => acc.concat(events), []));
|
acc.concat(
|
||||||
|
subResponse.body.value.map((evt) => {
|
||||||
|
return {
|
||||||
|
start: evt.start.dateTime + "Z",
|
||||||
|
end: evt.end.dateTime + "Z",
|
||||||
|
};
|
||||||
|
})
|
||||||
|
),
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
Loading…
Reference in a new issue