@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_impressions.findAll({
where
})
.then(impressions => {
if(!impressions) throw new Error(`Impressions not found with report id :: ${id}`);
options.impressions = impressions;
return options;
})
.catch(err => {
return Promise.reject({
code: 404,
message: 'Error finding impressions',
purpose: err.message
})
})
}
function byId(options) {
const id = options.req.params.id;
const where = { id };
return db.reports_impressions.findOne({
where
})
.then(impression => {
if(!impression) throw new Error(`Engagement not found with ID :: ${id}`);
options.impression = impression;
return options;
})
.catch(err => {
return Promise.reject({
code: 404,
message: 'Error finding impressions',
purpose: err.message
})
})
}