export async function fetchMicrosoftCalendarEvents(token, email, familyId, startDate, endDate) { const response = await fetch( `https://graph.microsoft.com/v1.0/me/calendar/calendarView?startDateTime=${startDate}&endDateTime=${endDate}`, { headers: { Authorization: `Bearer ${token}`, }, }, ); const data = await response.json(); console.log(data, startDate, endDate) const microsoftEvents = []; data?.value?.forEach((item) => { const start = item.start; let startDateTime; if (start !== undefined) { const stringDate = start.dateTime; startDateTime = new Date(stringDate); } const end = item.end; let endDateTime; if (end !== undefined) { const stringDate = end.dateTime; endDateTime = new Date(stringDate); } const microsoftEvent = { id: item.uid, title: item.subject, startDate: startDateTime, endDate: endDateTime, allDay: item.isAllDay, familyId, email }; microsoftEvents.push(microsoftEvent); }); return microsoftEvents; }