Outlook - list all calendars (#6004)

pull/5653/head^2
Joe Au-Yeung 2022-12-14 06:04:32 -05:00 committed by GitHub
parent 77b8eb8a7f
commit 2078f12a85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 6 deletions

View File

@ -157,13 +157,32 @@ export default class Office365CalendarService implements Calendar {
}
async listCalendars(): Promise<IntegrationCalendar[]> {
const response = await this.fetcher(`/me/calendars`);
let responseBody = await handleErrorsJson<{ value: OfficeCalendar[] }>(response);
// If responseBody is valid then parse the JSON text
if (typeof responseBody === "string") {
responseBody = JSON.parse(responseBody) as { value: OfficeCalendar[] };
const officeCalendars: OfficeCalendar[] = [];
// List calendars from MS are paginated
let finishedParsingCalendars = false;
// Store @odata.nextLink if in response
let requestLink = "/me/calendars";
while (!finishedParsingCalendars) {
const response = await this.fetcher(requestLink);
let responseBody = await handleErrorsJson<{ value: OfficeCalendar[]; "@odata.nextLink"?: string }>(
response
);
// If responseBody is valid then parse the JSON text
if (typeof responseBody === "string") {
responseBody = JSON.parse(responseBody) as { value: OfficeCalendar[] };
}
officeCalendars.push(...responseBody.value);
if (responseBody["@odata.nextLink"]) {
requestLink = responseBody["@odata.nextLink"].replace(this.apiGraphUrl, "");
} else {
finishedParsingCalendars = true;
}
}
return responseBody?.value.map((cal: OfficeCalendar) => {
return officeCalendars.map((cal: OfficeCalendar) => {
const calendar: IntegrationCalendar = {
externalId: cal.id ?? "No Id",
integration: this.integrationName,