mirror of
https://github.com/urosran/cally.git
synced 2025-07-16 01:56:16 +00:00
- Introduced a button for syncing Microsoft calendar
- Implemented saving of the microsoft event data in db
This commit is contained in:
40
calendar-integration/microsoft-calendar-utils.js
Normal file
40
calendar-integration/microsoft-calendar-utils.js
Normal file
@ -0,0 +1,40 @@
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user