@speakr/speakr-module-services
Version:
SPEAKR Shared Service Module
48 lines (44 loc) • 1.07 kB
JavaScript
;
const db = require('../../db');
module.exports = {
byReportId: byReportId,
byId: byId
};
function byReportId(options) {
const id = options.report.id;
const where = {report_id: id}
return db.reports_engagements.findAll({
where
})
.then(engagements => {
if(!engagements) throw new Error(`Engagements not found with report id :: ${id}`);
options.engagements = engagements;
return options;
})
.catch(err => {
return Promise.reject({
code: 404,
message: 'Error finding engagements',
purpose: err.message
})
})
}
function byId(options) {
const id = options.req.params.id;
const where = { id };
return db.reports_engagements.findOne({
where
})
.then(engagement => {
if(!engagement) throw new Error(`Engagement not found with ID :: ${id}`);
options.engagement = engagement;
return options;
})
.catch(err => {
return Promise.reject({
code: 404,
message: 'Error finding engagements',
purpose: err.message
})
})
}