Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. function createCalendarEvent(dateTimeStart, dateTimeEnd, appointment_type) {
  2. return new Promise((resolve, reject) => {
  3. calendar.events.list({
  4. auth: serviceAccountAuth, // List events for time period
  5. calendarId: calendarId,
  6. timeMin: dateTimeStart.toISOString(),
  7. timeMax: dateTimeEnd.toISOString()
  8. }, (err, calendarResponse) => {
  9. // Check if there is a event already on the Calendar
  10. if (err || calendarResponse.data.items.length > 0) {
  11. reject(err || new Error('Requested time conflicts with another appointment'));
  12. } else {
  13. // Create event for the requested time period
  14. calendar.events.insert({
  15. auth: serviceAccountAuth,
  16. calendarId: calendarId,
  17. resource: {
  18. summary: appointment_type + ' Appointment', description: appointment_type,
  19. start: { dateTime: dateTimeStart },
  20. end: { dateTime: dateTimeEnd }
  21. }
  22. }, (err, event) => {
  23. if (err !== null) {
  24. reject(err);
  25. } else {
  26. resolve(event);
  27. }
  28. });
  29. }
  30. });
  31. });
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement