Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function stats() {
  2.   return mongoose.models.Account
  3.     .find()
  4.     .then((accounts) => {
  5.       const pilotEmails = pilotUsers.map(p => p.Email);
  6.       const activeAccounts = accounts.filter(a => a.active).map(a => a.email);
  7.       const inactiveAccounts = accounts.filter(a => !a.active).map(a => a.email);
  8.  
  9.       const activePilots = _.intersection(activeAccounts, pilotEmails).length;
  10.       const inactivePilots = _.intersection(inactiveAccounts, pilotEmails).length;
  11.  
  12.       const activeRegular = activeAccounts.length - activePilots;
  13.       const inactiveRegular = inactiveAccounts.length - inactivePilots;
  14.  
  15.  
  16.       return Promise.resolve({
  17.         totalUsers: accounts.length,
  18.         regular: {
  19.           active: activeRegular,
  20.           inactive: inactiveRegular,
  21.         },
  22.         pilots: {
  23.           active: activePilots,
  24.           inactive: inactivePilots,
  25.         },
  26.       });
  27.     })
  28.     .catch((err) => {
  29.       console.error(err);
  30.     });
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement