Невозможно прочитать свойство 'data' из undefined в calendar.events.list - PullRequest
0 голосов
/ 08 мая 2019

Я пытаюсь удалить событие из календаря Google, у меня есть список всех событий в определенное время и извлекать идентификатор, если событие выполняет код правильно, но при достижении метода удаления он выдает «ошибка отклонения от unhandeled» и «Не удается прочитать»свойство 'data' не определено в calendar.events.list "

function deleteEvent(agent){

    // Use the Dialogflow's date and time parameters to create Javascript Date instances, 'dateTimeStart' and 'dateTimeEnd',
    // which are used to specify the appointment's time.
    const appointmentDuration = 1;// Define the length of the appointment to be one hour.
    const dateTimeStart = convertParametersDateD(agent.parameters.date, agent.parameters.time);
    const dateTimeEnd = addHours(dateTimeStart, appointmentDuration);
    const appointmentTimeString = getLocaleTimeString(dateTimeStart);
    const appointmentDateString = getLocaleDateString(dateTimeStart);


    //Check the availability of the time slot and delete appointment if the time slot is available on the calendar
    return deleteCalendarEvent(dateTimeStart,dateTimeEnd).then(() => {
        agent.add(`Got it. I delete your appointment scheduled on ${appointmentDateString} at ${appointmentTimeString} and i send the sendNotifications. See you soon. Good-bye.`);
}).catch(() => {
    agent.add(`Sorry, we are not booked on ${appointmentDateString} at ${appointmentTimeString}. Please choose another time and date`);
});

}//deleteEvent functin

function deleteCalendarEvent(dateTimeStart,dateTimeEnd){
    console.log("delete calender event function");

    return new Promise((resolve, reject) => {
        calendar.events.list({  // List all events in the specified time period
            auth: serviceAccountAuth,
            calendarId: calendarId,
            timeMin: dateTimeStart.toISOString(),
            timeMax: dateTimeEnd.toISOString()
        }, (err, calendarResponse) => {
            // Check if there exists any event on the calendar given the specified the time period
            if (calendarResponse.data.items.length > 0) {
            var lstOfEvent = calendarResponse.data.items;////all the events
    console.log(lstOfEvent);
    console.log('id= '+lstOfEvent[0]['id']);
    eventId=lstOfEvent[0]['id'];
    /////delete
    calendar.events.delete({

        auth: serviceAccountAuth,
        calendarId: calendarId,

        eventId:eventId
    }, (err, event) => {
        err ? reject(err) : resolve(event);
}
        );
/////delete
} else {
    reject(err);
}
});
});

}
...