@ -204,22 +204,24 @@ const googleApi = {
*
*
* @ param { Object } entry - The google calendar entry .
* @ param { Object } entry - The google calendar entry .
* @ returns { {
* @ returns { {
* i d: string ,
* calendarI d: string ,
* startDate : string ,
* description : string ,
* endDate : string ,
* endDate : string ,
* title : string ,
* id : string ,
* location : string ,
* location : string ,
* description : string } }
* startDate : string ,
* title : string } }
* @ private
* @ private
* /
* /
_convertCalendarEntry ( entry ) {
_convertCalendarEntry ( entry ) {
return {
return {
i d: entry . i d,
calendarI d: entry . calendarI d,
startDate : entry . start . dateTime ,
description : entry . description ,
endDate : entry . end . dateTime ,
endDate : entry . end . dateTime ,
title : entry . summary ,
id : entry . id ,
location : entry . location ,
location : entry . location ,
description : entry . description
startDate : entry . start . dateTime ,
title : entry . summary
} ;
} ;
} ,
} ,
@ -240,6 +242,8 @@ const googleApi = {
return null ;
return null ;
}
}
// user can edit the events, so we want only those that
// can be edited
return this . _getGoogleApiClient ( )
return this . _getGoogleApiClient ( )
. client . calendar . calendarList . list ( ) ;
. client . calendar . calendarList . list ( ) ;
} )
} )
@ -251,14 +255,20 @@ const googleApi = {
}
}
const calendarIds
const calendarIds
= calendarList . result . items . map ( en => en . id ) ;
= calendarList . result . items . map ( en => {
const promises = calendarIds . map ( id => {
return {
id : en . id ,
accessRole : en . accessRole
} ;
} ) ;
const promises = calendarIds . map ( ( { id , accessRole } ) => {
const startDate = new Date ( ) ;
const startDate = new Date ( ) ;
const endDate = new Date ( ) ;
const endDate = new Date ( ) ;
startDate . setDate ( startDate . getDate ( ) + fetchStartDays ) ;
startDate . setDate ( startDate . getDate ( ) + fetchStartDays ) ;
endDate . setDate ( endDate . getDate ( ) + fetchEndDays ) ;
endDate . setDate ( endDate . getDate ( ) + fetchEndDays ) ;
// retrieve the events and adds to the result the calendarId
return this . _getGoogleApiClient ( )
return this . _getGoogleApiClient ( )
. client . calendar . events . list ( {
. client . calendar . events . list ( {
'calendarId' : id ,
'calendarId' : id ,
@ -267,17 +277,73 @@ const googleApi = {
'showDeleted' : false ,
'showDeleted' : false ,
'singleEvents' : true ,
'singleEvents' : true ,
'orderBy' : 'startTime'
'orderBy' : 'startTime'
} ) ;
} )
. then ( result => result . result . items
. map ( item => {
const resultItem = { ... item } ;
// add the calendarId only for the events
// we can edit
if ( accessRole === 'writer'
|| accessRole === 'owner' ) {
resultItem . calendarId = id ;
}
return resultItem ;
} ) ) ;
} ) ;
} ) ;
return Promise . all ( promises )
return Promise . all ( promises )
. then ( results =>
. then ( results => [ ] . concat ( ... results ) )
[ ] . concat ( ... results . map ( rItem => rItem . result . items ) ) )
. then ( entries =>
. then ( entries =>
entries . map ( e => this . _convertCalendarEntry ( e ) ) ) ;
entries . map ( e => this . _convertCalendarEntry ( e ) ) ) ;
} ) ;
} ) ;
} ,
} ,
/* eslint-disable max-params */
/ * *
* Updates the calendar event and adds a location and text .
*
* @ param { string } id - The event id to update .
* @ param { string } calendarId - The calendar id to use .
* @ param { string } location - The location to add to the event .
* @ param { string } text - The description text to set / append .
* @ returns { Promise < T | never > }
* @ private
* /
_updateCalendarEntry ( id , calendarId , location , text ) {
return this . get ( )
. then ( ( ) => this . isSignedIn ( ) )
. then ( isSignedIn => {
if ( ! isSignedIn ) {
return null ;
}
return this . _getGoogleApiClient ( )
. client . calendar . events . get ( {
'calendarId' : calendarId ,
'eventId' : id
} ) . then ( event => {
let newDescription = text ;
if ( event . result . description ) {
newDescription = ` ${ event . result . description } \n \n ${
text } ` ;
}
return this . _getGoogleApiClient ( )
. client . calendar . events . patch ( {
'calendarId' : calendarId ,
'eventId' : id ,
'description' : newDescription ,
'location' : location
} ) ;
} ) ;
} ) ;
} ,
/* eslint-enable max-params */
/ * *
/ * *
* Returns the global Google API Client Library object . Direct use of this
* Returns the global Google API Client Library object . Direct use of this
* method is discouraged ; instead use the { @ link get } method .
* method is discouraged ; instead use the { @ link get } method .