(calendarId = '', maxResults = 20)
| 13 | * @returns {Promise<Array<import('./types').CalendarEvent>>} |
| 14 | */ |
| 15 | export const getCalendarEvents = async (calendarId = '', maxResults = 20) => { |
| 16 | const currentDate = new Date(); |
| 17 | const nextWeekDate = new Date(); |
| 18 | |
| 19 | nextWeekDate.setDate(currentDate.getDate() + 7); |
| 20 | |
| 21 | const calendarQueryParams = new URLSearchParams({ |
| 22 | calendarId, |
| 23 | maxResults, |
| 24 | singleEvents: true, |
| 25 | timeZone: 'Etc/Utc', |
| 26 | key: SHARED_CALENDAR_KEY, |
| 27 | timeMax: nextWeekDate.toISOString(), |
| 28 | timeMin: currentDate.toISOString(), |
| 29 | }); |
| 30 | |
| 31 | const calendarQueryUrl = new URL(`${BASE_CALENDAR_URL}${calendarId}/events`); |
| 32 | |
| 33 | calendarQueryParams.forEach((value, key) => |
| 34 | calendarQueryUrl.searchParams.append(key, value) |
| 35 | ); |
| 36 | |
| 37 | return fetchWithRetry(calendarQueryUrl) |
| 38 | .then(response => response.json()) |
| 39 | .then(calendar => calendar.items ?? []); |
| 40 | }; |
no test coverage detected