Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function unlinkGoogleUserAndCalendars(calendarId) {
  2.   const calendar = await Calendar.findOne({ where: { id: calendarId } });
  3.   const googleUser = await GoogleUser.findOne({
  4.     where: { id: calendar.provider_user_id },
  5.   });
  6.   await googleUser.update({ status: 'UNLINKED' });
  7.   const calendars = await Calendar.findAll({
  8.     where: {
  9.       provider_user_id: googleUser.id,
  10.       provider_user_type: 'google',
  11.     },
  12.   });
  13.   await Promise.all(
  14.     calendars.map(calendar => {
  15.       return calendar.unlinkAndForceDestroyFutureEvents();
  16.     }),
  17.   );
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement