|
@@ -6,6 +6,7 @@ import async_c from 'async';
|
|
|
import UnitPriceFileModel from "../../glj/models/unit_price_file_model";
|
|
|
import UnitPriceFiles from '../../glj/models/schemas/unit_price_file';
|
|
|
import {defaultDecimal, billsQuantityDecimal, basicInformation, projectFeature,displaySetting} from './project_property_template';
|
|
|
+import fixedFlag from '../../common/const/bills_fixed';
|
|
|
let FeeRateFiles = mongoose.model('fee_rate_file');
|
|
|
let counter = require("../../../public/counter/counter.js");
|
|
|
|
|
@@ -15,6 +16,7 @@ let feeRateFacade = require('../../fee_rates/facade/fee_rates_facade');
|
|
|
let labourCoeFacade = require('../../main/facade/labour_coe_facade');
|
|
|
let calcProgramFacade = require('../../main/facade/calc_program_facade');
|
|
|
let logger = require("../../../logs/log_helper").logger;
|
|
|
+let BillsModel = require("../../main/models/bills").model;
|
|
|
|
|
|
let Projects = require("./project_schema");
|
|
|
let projectType = {
|
|
@@ -30,14 +32,19 @@ let fileType = {
|
|
|
|
|
|
let ProjectsDAO = function(){};
|
|
|
|
|
|
-ProjectsDAO.prototype.getUserProjects = function(userId, compilation, callback){
|
|
|
- Projects.find({'$or': [{'userID': userId, 'compilation': compilation, 'deleteInfo': null}, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]}, '-_id', function(err, templates){
|
|
|
- if (err) {
|
|
|
- callback(1, 'Error', null);
|
|
|
- } else {
|
|
|
- callback(0, '', templates);
|
|
|
+ProjectsDAO.prototype.getUserProjects = async function(userId, compilation, callback){
|
|
|
+ try {
|
|
|
+ let projects = await Projects.find({'$or': [{'userID': userId, 'compilation': compilation, 'deleteInfo': null}, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]}, '-_id');
|
|
|
+ for(let i = 0 , len = projects.length; i < len; i++){
|
|
|
+ let proj = projects[i];
|
|
|
+ let engineeringCost = await BillsModel.find({projectID: proj.ID, 'flags.flag': fixedFlag.ENGINEERINGCOST, 'fees.totalFee': {$exists: true}});
|
|
|
+ proj._doc.engineeringCost = engineeringCost.length > 0 ? engineeringCost[0].fees[0].totalFee : 0;
|
|
|
}
|
|
|
- });
|
|
|
+ callback(0, '', projects);
|
|
|
+ }
|
|
|
+ catch (err){
|
|
|
+ callback(1, 'Error', null);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
ProjectsDAO.prototype.getUserProject = function (userId, ProjId, callback) {
|