@@ -17,7 +17,7 @@ import { v4 as uuidv4 } from "uuid";
1717import { stripHtml } from "../../emails/helpers" ;
1818import logger from "@lib/logger" ;
1919
20- const log = logger . getChildLogger ( { prefix : [ "[[ lib] caldav" ] } ) ;
20+ const log = logger . getChildLogger ( { prefix : [ "[lib] caldav" ] } ) ;
2121
2222type EventBusyDate = Record < "start" | "end" , Date > ;
2323
@@ -111,7 +111,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
111111 id : uid ,
112112 } ;
113113 } catch ( reason ) {
114- console . error ( reason ) ;
114+ log . error ( reason ) ;
115115 throw reason ;
116116 }
117117 }
@@ -161,7 +161,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
161161 } )
162162 ) ;
163163 } catch ( reason ) {
164- console . error ( reason ) ;
164+ log . error ( reason ) ;
165165 throw reason ;
166166 }
167167 }
@@ -193,7 +193,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
193193 } )
194194 ) ;
195195 } catch ( reason ) {
196- console . error ( reason ) ;
196+ log . error ( reason ) ;
197197 throw reason ;
198198 }
199199 }
@@ -260,7 +260,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
260260 integration : this . integrationName ,
261261 } ) ) ;
262262 } catch ( reason ) {
263- console . error ( reason ) ;
263+ log . error ( reason ) ;
264264 throw reason ;
265265 }
266266 }
@@ -281,58 +281,59 @@ export class CalDavCalendar implements CalendarApiAdapter {
281281 headers : this . headers ,
282282 } ) ;
283283
284- const events =
285- objects &&
286- objects ?. length > 0 &&
287- objects
288- . map ( ( object ) => {
289- if ( object ?. data ) {
290- const jcalData = ICAL . parse ( object . data ) ;
291- const vcalendar = new ICAL . Component ( jcalData ) ;
292- const vevent = vcalendar . getFirstSubcomponent ( "vevent" ) ;
293- const event = new ICAL . Event ( vevent ) ;
294-
295- const calendarTimezone = vcalendar . getFirstSubcomponent ( "vtimezone" )
296- ? vcalendar . getFirstSubcomponent ( "vtimezone" ) . getFirstPropertyValue ( "tzid" )
297- : "" ;
298-
299- const startDate = calendarTimezone
300- ? dayjs ( event . startDate ) . tz ( calendarTimezone )
301- : new Date ( event . startDate . toUnixTime ( ) * 1000 ) ;
302- const endDate = calendarTimezone
303- ? dayjs ( event . endDate ) . tz ( calendarTimezone )
304- : new Date ( event . endDate . toUnixTime ( ) * 1000 ) ;
305-
306- return {
307- uid : event . uid ,
308- etag : object . etag ,
309- url : object . url ,
310- summary : event . summary ,
311- description : event . description ,
312- location : event . location ,
313- sequence : event . sequence ,
314- startDate,
315- endDate,
316- duration : {
317- weeks : event . duration . weeks ,
318- days : event . duration . days ,
319- hours : event . duration . hours ,
320- minutes : event . duration . minutes ,
321- seconds : event . duration . seconds ,
322- isNegative : event . duration . isNegative ,
323- } ,
324- organizer : event . organizer ,
325- attendees : event . attendees . map ( ( a ) => a . getValues ( ) ) ,
326- recurrenceId : event . recurrenceId ,
327- timezone : calendarTimezone ,
328- } ;
329- }
330- } )
331- . filter ( ( e ) => e != null ) ;
284+ if ( ! objects || objects ?. length === 0 ) {
285+ return [ ] ;
286+ }
287+
288+ const events = objects
289+ . map ( ( object ) => {
290+ if ( object ?. data ) {
291+ const jcalData = ICAL . parse ( object . data ) ;
292+ const vcalendar = new ICAL . Component ( jcalData ) ;
293+ const vevent = vcalendar . getFirstSubcomponent ( "vevent" ) ;
294+ const event = new ICAL . Event ( vevent ) ;
295+
296+ const calendarTimezone = vcalendar . getFirstSubcomponent ( "vtimezone" )
297+ ? vcalendar . getFirstSubcomponent ( "vtimezone" ) . getFirstPropertyValue ( "tzid" )
298+ : "" ;
299+
300+ const startDate = calendarTimezone
301+ ? dayjs ( event . startDate ) . tz ( calendarTimezone )
302+ : new Date ( event . startDate . toUnixTime ( ) * 1000 ) ;
303+ const endDate = calendarTimezone
304+ ? dayjs ( event . endDate ) . tz ( calendarTimezone )
305+ : new Date ( event . endDate . toUnixTime ( ) * 1000 ) ;
306+
307+ return {
308+ uid : event . uid ,
309+ etag : object . etag ,
310+ url : object . url ,
311+ summary : event . summary ,
312+ description : event . description ,
313+ location : event . location ,
314+ sequence : event . sequence ,
315+ startDate,
316+ endDate,
317+ duration : {
318+ weeks : event . duration . weeks ,
319+ days : event . duration . days ,
320+ hours : event . duration . hours ,
321+ minutes : event . duration . minutes ,
322+ seconds : event . duration . seconds ,
323+ isNegative : event . duration . isNegative ,
324+ } ,
325+ organizer : event . organizer ,
326+ attendees : event . attendees . map ( ( a ) => a . getValues ( ) ) ,
327+ recurrenceId : event . recurrenceId ,
328+ timezone : calendarTimezone ,
329+ } ;
330+ }
331+ } )
332+ . filter ( ( e ) => e != null ) ;
332333
333334 return events ;
334335 } catch ( reason ) {
335- console . error ( reason ) ;
336+ log . error ( reason ) ;
336337 throw reason ;
337338 }
338339 }
0 commit comments