summaryrefslogtreecommitdiff
path: root/src/handlers/index.js
blob: 188547c479df38b42aa68a535c77934ad48e7800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { Types } = require('mongoose');
const Bluebird = require('bluebird');
const UserModel = require('../services/users/user.model.js');
const launchUserSession = require('./launchUserSession.js');


const handleJobAsUser = async (job, user) => {
  console.log(`Running job as ${user.username}`);
  return launchUserSession(user);
};

const handleJob = async job => {
  console.log('Running attend class job');
  const { data } = job.attrs;

  const participants = await UserModel.find({
    _id: {
      $in: data.participantIds.map(Types.ObjectId)
    }
  });

  console.log({ participants })

  return Bluebird.map(participants, participant => handleJobAsUser(job, participant));
};


module.exports = handleJob;