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:
parent
2cf02c4f31
commit
ed8241ac1b
3 changed files with 57 additions and 56 deletions
|
@ -17,7 +17,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||||
import { stripHtml } from "../../emails/helpers";
|
import { stripHtml } from "../../emails/helpers";
|
||||||
import logger from "@lib/logger";
|
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>;
|
type EventBusyDate = Record<"start" | "end", Date>;
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
id: uid,
|
id: uid,
|
||||||
};
|
};
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
log.error(reason);
|
||||||
throw reason;
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
log.error(reason);
|
||||||
throw reason;
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
log.error(reason);
|
||||||
throw reason;
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,7 +260,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
integration: this.integrationName,
|
integration: this.integrationName,
|
||||||
}));
|
}));
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
log.error(reason);
|
||||||
throw reason;
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,58 +281,59 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
const events =
|
if (!objects || objects?.length === 0) {
|
||||||
objects &&
|
return [];
|
||||||
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);
|
|
||||||
|
|
||||||
const calendarTimezone = vcalendar.getFirstSubcomponent("vtimezone")
|
const events = objects
|
||||||
? vcalendar.getFirstSubcomponent("vtimezone").getFirstPropertyValue("tzid")
|
.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
|
const calendarTimezone = vcalendar.getFirstSubcomponent("vtimezone")
|
||||||
? dayjs(event.startDate).tz(calendarTimezone)
|
? vcalendar.getFirstSubcomponent("vtimezone").getFirstPropertyValue("tzid")
|
||||||
: new Date(event.startDate.toUnixTime() * 1000);
|
: "";
|
||||||
const endDate = calendarTimezone
|
|
||||||
? dayjs(event.endDate).tz(calendarTimezone)
|
|
||||||
: new Date(event.endDate.toUnixTime() * 1000);
|
|
||||||
|
|
||||||
return {
|
const startDate = calendarTimezone
|
||||||
uid: event.uid,
|
? dayjs(event.startDate).tz(calendarTimezone)
|
||||||
etag: object.etag,
|
: new Date(event.startDate.toUnixTime() * 1000);
|
||||||
url: object.url,
|
const endDate = calendarTimezone
|
||||||
summary: event.summary,
|
? dayjs(event.endDate).tz(calendarTimezone)
|
||||||
description: event.description,
|
: new Date(event.endDate.toUnixTime() * 1000);
|
||||||
location: event.location,
|
|
||||||
sequence: event.sequence,
|
return {
|
||||||
startDate,
|
uid: event.uid,
|
||||||
endDate,
|
etag: object.etag,
|
||||||
duration: {
|
url: object.url,
|
||||||
weeks: event.duration.weeks,
|
summary: event.summary,
|
||||||
days: event.duration.days,
|
description: event.description,
|
||||||
hours: event.duration.hours,
|
location: event.location,
|
||||||
minutes: event.duration.minutes,
|
sequence: event.sequence,
|
||||||
seconds: event.duration.seconds,
|
startDate,
|
||||||
isNegative: event.duration.isNegative,
|
endDate,
|
||||||
},
|
duration: {
|
||||||
organizer: event.organizer,
|
weeks: event.duration.weeks,
|
||||||
attendees: event.attendees.map((a) => a.getValues()),
|
days: event.duration.days,
|
||||||
recurrenceId: event.recurrenceId,
|
hours: event.duration.hours,
|
||||||
timezone: calendarTimezone,
|
minutes: event.duration.minutes,
|
||||||
};
|
seconds: event.duration.seconds,
|
||||||
}
|
isNegative: event.duration.isNegative,
|
||||||
})
|
},
|
||||||
.filter((e) => e != null);
|
organizer: event.organizer,
|
||||||
|
attendees: event.attendees.map((a) => a.getValues()),
|
||||||
|
recurrenceId: event.recurrenceId,
|
||||||
|
timezone: calendarTimezone,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter((e) => e != null);
|
||||||
|
|
||||||
return events;
|
return events;
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
log.error(reason);
|
||||||
throw reason;
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
"react-select": "^4.3.1",
|
"react-select": "^4.3.1",
|
||||||
"react-timezone-select": "^1.0.7",
|
"react-timezone-select": "^1.0.7",
|
||||||
"short-uuid": "^4.2.0",
|
"short-uuid": "^4.2.0",
|
||||||
"tsdav": "^1.0.6",
|
"tsdav": "1.0.6",
|
||||||
"tslog": "^3.2.1",
|
"tslog": "^3.2.1",
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
|
|
|
@ -7489,10 +7489,10 @@ ts-pnp@^1.1.6:
|
||||||
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
|
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
|
||||||
integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==
|
integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==
|
||||||
|
|
||||||
tsdav@^1.0.6:
|
tsdav@1.0.6:
|
||||||
version "1.1.0"
|
version "1.0.6"
|
||||||
resolved "https://registry.yarnpkg.com/tsdav/-/tsdav-1.1.0.tgz#48fe17df07f852ff8dfddf71fae2396e79ed6735"
|
resolved "https://registry.yarnpkg.com/tsdav/-/tsdav-1.0.6.tgz#65c22fc77d6516db234c1288ff9c9fed6730fef5"
|
||||||
integrity sha512-Cc/VTFgUC/fOOFkGT/xuwrrIrG0+it7WA5ywNM4QyYWAzXVw+WmbM1pr7/7fzHA/OOVQ0a8RyPi4K1C+mFBGJw==
|
integrity sha512-xnKE39wZtyLoyW1UClYAb2Eilx6tHzbqhO2v29P1zrmwLAsKNYUHwHb+lrmJHfZZLsbbzKWRg5dPLYRuEXmMJA==
|
||||||
dependencies:
|
dependencies:
|
||||||
base-64 "^1.0.0"
|
base-64 "^1.0.0"
|
||||||
cross-fetch "^3.1.4"
|
cross-fetch "^3.1.4"
|
||||||
|
|
Loading…
Reference in a new issue