Files
cally/calendar-integration/microsoft-calendar-utils.js
Dejan 8161accdb6 - Introduced a button for syncing Microsoft calendar
- Implemented saving of the microsoft event data in db
2024-10-05 00:32:57 +02:00

41 lines
1007 B
JavaScript

export async function fetchMicrosoftCalendarEvents(token, 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();
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,
};
microsoftEvents.push(microsoftEvent);
});
return microsoftEvents;
}