From f09cce67f4c73bb18d9e081363b5f9e93f3943fd Mon Sep 17 00:00:00 2001 From: Daniel Heinrich <148484595+danielatgoogle@users.noreply.github.com> Date: Wed, 6 Dec 2023 08:41:09 -0800 Subject: [PATCH] Update Code.js to account for changes from Calendar API Worked with the Calendar API team to update this code sample. --- vacation-calendar/src/Code.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/vacation-calendar/src/Code.js b/vacation-calendar/src/Code.js index 094c3e5..74fa9ab 100644 --- a/vacation-calendar/src/Code.js +++ b/vacation-calendar/src/Code.js @@ -79,7 +79,6 @@ function sync() { * calendar. * @param {string} username The team member that is attending the event. * @param {Calendar.Event} event The event to import. - * @return {boolean} True if the event was imported. */ function importEvent(username, event) { event.summary = '[' + username + '] ' + event.summary; @@ -87,17 +86,25 @@ function importEvent(username, event) { id: TEAM_CALENDAR_ID, }; event.attendees = []; + + // If the event is not of type 'default', it can't be imported, so it needs + // to be changed. + if (event.eventType != 'default') { + event.eventType = 'default'; + delete event.outOfOfficeProperties; + delete event.focusTimeProperties; + } + console.log('Importing: %s', event.summary); try { Calendar.Events.import(event, TEAM_CALENDAR_ID); - return true; } catch (e) { console.error('Error attempting to import event: %s. Skipping.', e.toString()); - return false; } } + /** * In a given user's calendar, look for occurrences of the given keyword * in events within the specified date range and return any such events