/** * Created by zhang on 2017/11/22. */ let mongoose = require('mongoose'); let projectsModel = mongoose.model('projects'); let _ = require('lodash'); module.exports ={ getProjectDecimal:getProjectDecimal, getBillsQuantityDecimal:getBillsQuantityDecimal } async function getProjectDecimal(projectID) { let decimal = null; let project =await projectsModel.findOne({ID:projectID}); if(project){ decimal = project.property.decimal } return decimal; } async function getBillsQuantityDecimal(projectID,unit) { let decimal = null; let project =await projectsModel.findOne({ID:projectID}); if(project){ let billsQuantityDecimal = project.property.billsQuantityDecimal; let el = _.find(billsQuantityDecimal,{'unit':unit}); if(!el){ el = billsQuantityDecimal[0]; } decimal = el.decimal } return decimal; }