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;