Fix/events from caldav not taken into consideration when checking availability (#637)

* use version 1.0.6

* use logger over console log

fix typing issue

Co-authored-by: Bailey Pumfleet <[email protected]>
This commit is contained in:
Femi OdugbesanandBailey Pumfleet authored and GitHub committed 2021-09-18 17:49:18 +01:00
1 parent 2cf02c4f31
commit ed8241ac1b
3 files changed
+57 -56

No files matched your search

@@ -17,7 +17,7 @@ import { v4 as uuidv4 } from "uuid";
import { stripHtml } from "../../emails/helpers";
import logger from "@lib/logger";
const log = logger.getChildLogger({ prefix: ["[[lib] caldav"] });
const log = logger.getChildLogger({ prefix: ["[lib] caldav"] });
type EventBusyDate = Record<"start" | "end", Date>;
@@ -111,7 +111,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
id: uid,
};
} catch (reason) {
console.error(reason);
log.error(reason);
throw reason;
}
}
@@ -161,7 +161,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
})
);
} catch (reason) {
console.error(reason);
log.error(reason);
throw reason;
}
}
@@ -193,7 +193,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
})
);
} catch (reason) {
console.error(reason);
log.error(reason);
throw reason;
}
}
@@ -260,7 +260,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
integration: this.integrationName,
}));
} catch (reason) {
console.error(reason);
log.error(reason);
throw reason;
}
}
@@ -281,58 +281,59 @@ export class CalDavCalendar implements CalendarApiAdapter {
headers: this.headers,
});
const events =
objects &&
objects?.length > 0 &&
objects
.map((object) => {
if (object?.data) {
const jcalData = ICAL.parse(object.data);
const vcalendar = new ICAL.Component(jcalData);
const vevent = vcalendar.getFirstSubcomponent("vevent");
const event = new ICAL.Event(vevent);
if (!objects || objects?.length === 0) {
return [];
}
const calendarTimezone = vcalendar.getFirstSubcomponent("vtimezone")
? vcalendar.getFirstSubcomponent("vtimezone").getFirstPropertyValue("tzid")
: "";
const events = objects
.map((object) => {
if (object?.data) {
const jcalData = ICAL.parse(object.data);
const vcalendar = new ICAL.Component(jcalData);
const vevent = vcalendar.getFirstSubcomponent("vevent");
const event = new ICAL.Event(vevent);
const startDate = calendarTimezone
? dayjs(event.startDate).tz(calendarTimezone)
: new Date(event.startDate.toUnixTime() * 1000);
const endDate = calendarTimezone
? dayjs(event.endDate).tz(calendarTimezone)
: new Date(event.endDate.toUnixTime() * 1000);
const calendarTimezone = vcalendar.getFirstSubcomponent("vtimezone")
? vcalendar.getFirstSubcomponent("vtimezone").getFirstPropertyValue("tzid")
: "";
return {
uid: event.uid,
etag: object.etag,
url: object.url,
summary: event.summary,
description: event.description,
location: event.location,
sequence: event.sequence,
startDate,
endDate,
duration: {
weeks: event.duration.weeks,
days: event.duration.days,
hours: event.duration.hours,
minutes: event.duration.minutes,
seconds: event.duration.seconds,
isNegative: event.duration.isNegative,
},
organizer: event.organizer,
attendees: event.attendees.map((a) => a.getValues()),
recurrenceId: event.recurrenceId,
timezone: calendarTimezone,
};
}
})
.filter((e) => e != null);
const startDate = calendarTimezone
? dayjs(event.startDate).tz(calendarTimezone)
: new Date(event.startDate.toUnixTime() * 1000);
const endDate = calendarTimezone
? dayjs(event.endDate).tz(calendarTimezone)
: new Date(event.endDate.toUnixTime() * 1000);
return {
uid: event.uid,
etag: object.etag,
url: object.url,
summary: event.summary,
description: event.description,
location: event.location,
sequence: event.sequence,
startDate,
endDate,
duration: {
weeks: event.duration.weeks,
days: event.duration.days,
hours: event.duration.hours,
minutes: event.duration.minutes,
seconds: event.duration.seconds,
isNegative: event.duration.isNegative,
},
organizer: event.organizer,
attendees: event.attendees.map((a) => a.getValues()),
recurrenceId: event.recurrenceId,
timezone: calendarTimezone,
};
}
})
.filter((e) => e != null);
return events;
} catch (reason) {
console.error(reason);
log.error(reason);
throw reason;
}
}