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 <pumfleet@hey.com>
This commit is contained in:
Femi Odugbesan 2021-09-18 11:49:18 -05:00 committed by GitHub
parent 2cf02c4f31
commit ed8241ac1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 56 deletions

View File

@ -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;
}
}

View File

@ -63,7 +63,7 @@
"react-select": "^4.3.1",
"react-timezone-select": "^1.0.7",
"short-uuid": "^4.2.0",
"tsdav": "^1.0.6",
"tsdav": "1.0.6",
"tslog": "^3.2.1",
"uuid": "^8.3.2"
},

View File

@ -7489,10 +7489,10 @@ ts-pnp@^1.1.6:
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==
tsdav@^1.0.6:
version "1.1.0"
resolved "https://registry.yarnpkg.com/tsdav/-/tsdav-1.1.0.tgz#48fe17df07f852ff8dfddf71fae2396e79ed6735"
integrity sha512-Cc/VTFgUC/fOOFkGT/xuwrrIrG0+it7WA5ywNM4QyYWAzXVw+WmbM1pr7/7fzHA/OOVQ0a8RyPi4K1C+mFBGJw==
tsdav@1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/tsdav/-/tsdav-1.0.6.tgz#65c22fc77d6516db234c1288ff9c9fed6730fef5"
integrity sha512-xnKE39wZtyLoyW1UClYAb2Eilx6tHzbqhO2v29P1zrmwLAsKNYUHwHb+lrmJHfZZLsbbzKWRg5dPLYRuEXmMJA==
dependencies:
base-64 "^1.0.0"
cross-fetch "^3.1.4"