summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-11-15 02:41:51 +0300
committereug-vs <eug-vs@keemail.me>2020-11-15 02:41:51 +0300
commitd113caace46ee53b86a31da2879d991562de45a1 (patch)
tree469eee3f1aeb9ac9928ae103da2f61391258277d
parent3cbf42a8d4ffef02b92067bf0083abd9a15836c1 (diff)
downloadbsu-fantom-d113caace46ee53b86a31da2879d991562de45a1.tar.gz
feat: add CRUD methods
-rw-r--r--package.json1
-rw-r--r--src/services/events/event.service.js26
2 files changed, 24 insertions, 3 deletions
diff --git a/package.json b/package.json
index d568fe4..ab2c639 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"feathers-mongoose": "^8.3.1",
+ "lodash": "^4.17.20",
"mongoose": "^5.10.14",
"puppeteer": "^5.4.1"
}
diff --git a/src/services/events/event.service.js b/src/services/events/event.service.js
index 5391443..1be4449 100644
--- a/src/services/events/event.service.js
+++ b/src/services/events/event.service.js
@@ -1,4 +1,6 @@
+const { Types } = require('mongoose');
const Agenda = require('agenda');
+const _ = require('lodash');
const { getConnection } = require('../../connectDb.js');
const handleAttendClassJob = require('../../handlers');
@@ -25,14 +27,32 @@ class Events {
this.agenda.on('fail', (err, job) => console.log(`Job failed with the error ${err}`));
return this.agenda.start();
- };
+ }
create(data, params) {
return this.agenda.schedule(data.date, 'attend class', data);
- };
+ }
find(params) {
- return this.agenda.jobs();
+ return this.agenda.jobs({}, { nextRunAt: -1, 'data.participants': -1 });
+ }
+
+ findOneById(id) {
+ return this.agenda
+ .jobs({ _id: Types.ObjectId(id) })
+ .then(results => results[0]);
+ }
+
+ async patch(id, attrs, params) {
+ console.log(`Patch ${id}`);
+ const job = await this.findOneById(id);
+ job.attrs = _.merge(job.attrs, attrs);
+ return this.agenda.saveJob(job);
+ }
+
+ async remove(id) {
+ console.log(`Remove ${id}`);
+ return this.agenda.cancel({ _id: Types.ObjectId(id) });
}
}