Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createCalendarEvent(dateTimeStart, dateTimeEnd, appointment_type) {
- return new Promise((resolve, reject) => {
- calendar.events.list({
- auth: serviceAccountAuth, // List events for time period
- calendarId: calendarId,
- timeMin: dateTimeStart.toISOString(),
- timeMax: dateTimeEnd.toISOString()
- }, (err, calendarResponse) => {
- // Check if there is a event already on the Calendar
- if (err || calendarResponse.data.items.length > 0) {
- reject(err || new Error('Requested time conflicts with another appointment'));
- } else {
- // Create event for the requested time period
- calendar.events.insert({
- auth: serviceAccountAuth,
- calendarId: calendarId,
- resource: {
- summary: appointment_type + ' Appointment', description: appointment_type,
- start: { dateTime: dateTimeStart },
- end: { dateTime: dateTimeEnd }
- }
- }, (err, event) => {
- if (err !== null) {
- reject(err);
- } else {
- resolve(event);
- }
- });
- }
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement