@speakr/speakr-module-services
Version:
SPEAKR Shared Service Module
65 lines (56 loc) • 1.42 kB
JavaScript
;
const db = require('../../db');
module.exports = {
byId,
byIdHash
};
function byId(options) {
let update = {
title: options.req.body.title,
name: options.req.body.name,
phone: options.req.body.phone,
email: options.req.body.email,
type: options.req.body.type
};
let where = { id: options.req.params.id };
return db.contacts.update(update, {where})
.then(contacts => {
if(!!contacts) {
return db.contacts.findOne({where})
.then(contacts => {
options.contacts = contacts;
return Promise.resolve(options);
});
}
else {
return Promise.reject();
}
}).catch(err => {
return Promise.reject(err);
})
}
function byIdHash(options) {
let update = {
title: options.req.body.title,
name: options.req.body.name,
phone: options.req.body.phone,
email: options.req.body.email,
type: options.req.body.type
};
let where = { id_hash: options.req.params.id_hash };
return db.contacts.update(update, {where})
.then(contacts => {
if(!!contacts) {
return db.contacts.findOne({where})
.then(contacts => {
options.contacts = contacts;
return Promise.resolve(options);
});
}
else {
return Promise.reject();
}
}).catch(err => {
return Promise.reject(err);
})
}