function listEvents(auth, startDate) {
    return __awaiter(this, void 0, void 0, function* () {
        const calendar = googleapis_1.google.calendar({ version: 'v3', auth });
        const promises = calendarIds_json_1.default.map(calendarId => calendar.events
            .list({
            calendarId: calendarId,
            timeMin: startDate.toISOString(),
            timeMax: new Date(startDate.getTime() + 1000 * 60 * 60 * 24 * 7).toISOString(),
            singleEvents: true,
            orderBy: 'startTime',
        })
            .then(res => {
            const events = res.data.items;
            if (events.length) {
                return events.map(event => {
                    const start = event.start.dateTime || event.start.date;
                    console.log(`${start} - ${event.summary}`);
                    const summary = event.summary.includes('Sikakaato') ? 'Sikakaato' : event.summary;
                    return { name: summary, date: new Date(event.start.dateTime || `${event.start.date}T00:00:00`) };
                });
            }
            return [];
        })
            .catch(err => {
            return [];
        }));
        return yield Promise.all(promises).then(res => res.reduce((acc, val) => acc.concat(val), []));
    });
}
/**
 * Lists the next 10 events on the user's primary calendar.
 * @param {google.auth.OAuth2} auth An authorized OAuth2 client.
 */
Lists the next 10 events on the user's primary calendar.
@param {google.auth.OAuth2} auth An authorized OAuth2 client.
Lists the next 10 events on the user ' s primary calendar . @param { google . auth . OAuth2 } auth An authorized OAuth2 client .
function listEvents(auth, startDate) {
    return __awaiter(this, void 0, void 0, function* () {
        const calendar = googleapis_1.google.calendar({ version: 'v3', auth });
        const promises = calendarIds_json_1.default.map(calendarId => calendar.events
            .list({
            calendarId: calendarId,
            timeMin: startDate.toISOString(),
            timeMax: new Date(startDate.getTime() + 1000 * 60 * 60 * 24 * 7).toISOString(),
            singleEvents: true,
            orderBy: 'startTime',
        })
            .then(res => {
            const events = res.data.items;
            if (events.length) {
                return events.map(event => {
                    const start = event.start.dateTime || event.start.date;
                    console.log(`${start} - ${event.summary}`);
                    const summary = event.summary.includes('Sikakaato') ? 'Sikakaato' : event.summary;
                    return { name: summary, date: new Date(event.start.dateTime || `${event.start.date}T00:00:00`) };
                });
            }
            return [];
        })
            .catch(err => {
            return [];
        }));
        return yield Promise.all(promises).then(res => res.reduce((acc, val) => acc.concat(val), []));
    });
}
function listEvents ( auth , startDate ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { const calendar = googleapis_1 . google . calendar ( { version : 'v3' , auth } ) ; const promises = calendarIds_json_1 . default . map ( calendarId => calendar . events . list ( { calendarId : calendarId , timeMin : startDate . toISOString ( ) , timeMax : new Date ( startDate . getTime ( ) + 1000 * 60 * 60 * 24 * 7 ) . toISOString ( ) , singleEvents : true , orderBy : 'startTime' , } ) . then ( res => { const events = res . data . items ; if ( events . length ) { return events . map ( event => { const start = event . start . dateTime || event . start . date ; console . log ( ` ${ start } ${ event . summary } ` ) ; const summary = event . summary . includes ( 'Sikakaato' ) ? 'Sikakaato' : event . summary ; return { name : summary , date : new Date ( event . start . dateTime || ` ${ event . start . date } ` ) } ; } ) ; } return [ ] ; } ) . catch ( err => { return [ ] ; } ) ) ; return yield Promise . all ( promises ) . then ( res => res . reduce ( ( acc , val ) => acc . concat ( val ) , [ ] ) ) ; } ) ; }
Lists the next 10 events on the user's primary calendar.
Lists the next 10 events on the user ' s primary calendar .