Skip to content

Instantly share code, notes, and snippets.

@alexandremaeda
Last active August 16, 2016 22:01
Show Gist options
  • Save alexandremaeda/f9ae2a44e87b48ed476fa8f2c38b7b48 to your computer and use it in GitHub Desktop.
Save alexandremaeda/f9ae2a44e87b48ed476fa8f2c38b7b48 to your computer and use it in GitHub Desktop.
// repository
const repository = {
findByUserID: (userID) => Simulator.findOne({ user: userID }).exec()
};
// controller
const getModulesAmount = (req, res) => {
var valueMonth = req.param('valueMonth');
var modules = 5; // create a flag
repository.findByUserID(req.decoded._doc._id).then( (doc) => {
if (valueMonth > 126.96) { // create a flag
modules = Math.ceil(((valueMonth - doc.taxaDisponibilidade * doc.tarifaImpostos) * 1000) / (30 * doc.hsp * doc.tarifaImpostos * doc.potenciaModulo));
}
res.status(200).json({modules: modules}).end();
})
.catch( err => {
res.status(500).json({error: err}).end();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment