I use google calendar api to import events into Google Sheet.
I'm trying to omit event.creator from representation if he isn't a participant (for example assistant created an event) and can't find the solution.
I'm new to programming, so I just suppose I need to add a filter or write a new function.
Here is the snippet:
function transformCalendarEvents(rawCalendarEvents) {
/**
*
* @param {Calendar_v3.Calendar.V3.Schema.Event} event
* @return {EventAttendee[]}
*/
function getEventAttendees(event){
/**
*
* @param {Object} event
* @return {EventAttendee}
*/
function createEventAttendee(srcAttendee) {
return {
name: srcAttendee.displayName,
email: srcAttendee.email,
responseStatus: srcAttendee.responseStatus,
organizer: srcAttendee.organizer || false,
optional: srcAttendee.optional || false,
}
}
let attendees = event.attendees || []
if (event.creator && !attendees.map(a => a.email).includes(event.creator.email)) {
attendees.push({
...event.creator,
organizer: true,
optional: false,
responseStatus: event.creator.responseStatus || 'declined',
})
}
if (event.organizer && !attendees.map(a => a.email).includes(event.organizer.email)) {
attendees.push({
...event.organizer,
organizer: true,
optional: false,
responseStatus: event.creator.responseStatus || 'declined',
})
}
attendees = attendees.filter(
atd => atd.email.indexOf('@resource.calendar.google.com') == -1
).sort(
(a1, a2) => +!!a2.organizer - +!!a1.organizer
)
return attendees.map(createEventAttendee)
}
Any help would be appreciated