@speakr/speakr-module-services
Version:
SPEAKR Shared Service Module
43 lines (35 loc) • 975 B
JavaScript
;
const db = require('../../db/');
module.exports = {
byName,
byInitiativeId
};
function byName(options) {
let where = { name: options.platform };
return db.platforms.findOne({ where: where })
.then(platforms => {
if(!!platforms) {
options.platforms = platforms;
return Promise.resolve(options);
} else {
return Promise.resolve(options);
}
})
}
function byInitiativeId(options){
const id = options.initiatives.dataValues ?
options.initiatives.dataValues.platform_id :
options.initiatives.platform_id;
const where = { id };
return db.platforms.findOne({ where })
.then(platform => {
if(!platform) throw new Error('no platform')
options.platforms = platform.dataValues ?
platform.dataValues :
platform;
return options;
})
.catch(err => {
return Promise.reject(err)
})
}