From 2078f12a854bec52aa829cb571a08e1b4a428c3e Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Wed, 14 Dec 2022 06:04:32 -0500 Subject: [PATCH] Outlook - list all calendars (#6004) --- .../office365calendar/lib/CalendarService.ts | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/app-store/office365calendar/lib/CalendarService.ts b/packages/app-store/office365calendar/lib/CalendarService.ts index 522a399bc2..8287404886 100644 --- a/packages/app-store/office365calendar/lib/CalendarService.ts +++ b/packages/app-store/office365calendar/lib/CalendarService.ts @@ -157,13 +157,32 @@ export default class Office365CalendarService implements Calendar { } async listCalendars(): Promise { - 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,