@speakr/speakr-module-services
Version:
SPEAKR Shared Service Module
35 lines (30 loc) • 857 B
JavaScript
const db = require('../../db');
module.exports = {
newRow,
};
function newRow(options) {
const account = options.accounts.dataValues ?
options.accounts.dataValues :
options.accounts;
if(!account) return Promise.reject({
code: 409,
message: 'Error Updating Account',
purpose: 'Did not have an account to update accounts_offer_prices table'
})
const account_id = options.accounts.id;
return db.accounts_offer_prices.create({
account_id,
fair_offer_price: account.fair_offer_price,
min_offer_price: account.min_offer_price,
})
.then(() => {
return Promise.resolve(options)
})
.catch(err => {
console.log('\n\n ERROR CREATING OFFER PRICE', err)
return Promise.reject({
message: 'Trouble adding row to offer prices',
purpose: err.message
})
})
}