const Agenda = require('agenda'); const { getConnection } = require('../../connectDb.js'); const handleAttendClassJob = require('../../handlers'); class Events { setup(app) { this.collectionName = 'events'; // Reuse mongoose connection const connection = getConnection(); this.agenda = new Agenda(); this.agenda.mongo( connection.collection(this.collectionName).conn.db, this.collectionName ); // Define jobs this.agenda.define('attend class', handleAttendClassJob); return this.agenda.start(); }; async create(data, params) { return this.agenda.schedule(data.date, 'attend class', data); }; } module.exports = app => app.use('/events', new Events());