summaryrefslogtreecommitdiff
path: root/src/services/events/event.service.js
blob: 5c5bcffb8c0993574ffd18f708664a20d03dffb5 (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
30
31
32
33
34
35
const Agenda = require('agenda');
const { getConnection } = require('../../connectDb.js');


class Events {
  setup(app) {
    this.collectionName = 'events';

    const connection = getConnection();
    this.agenda = new Agenda();
    this.agenda.mongo(
      connection.collection(this.collectionName).conn.db,
      this.collectionName
    );

    this.defineJobs();

    return this.agenda.start();
  };

  defineJobs() {
    this.agenda.define('attend class', async job => {
      console.log('Running attend class job with attrs:');
      console.log(job.attrs);
    });
  };

  async create(data, params) {
    return this.agenda.schedule(data.date, 'attend class', { data });
  };
}


module.exports = app => app.use('/events', new Events());