@dhyasama/totem-models 11.15.0 → 11.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Investment.js +13 -23
- package/lib/Round.js +38 -0
- package/package.json +1 -1
package/lib/Investment.js
CHANGED
|
@@ -62,15 +62,18 @@ module.exports = function(mongoose, config) {
|
|
|
62
62
|
// Statics operate on the entire collection
|
|
63
63
|
//////////////////////////////////////////////////////
|
|
64
64
|
|
|
65
|
-
Investment.statics.
|
|
65
|
+
Investment.statics.getOrgIds = function(options, cb) {
|
|
66
66
|
|
|
67
67
|
if (!cb) { throw new Error('cb is required'); }
|
|
68
68
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
69
|
-
|
|
70
|
-
if (!
|
|
69
|
+
|
|
70
|
+
if (!options.isWorkerProcess) {
|
|
71
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
72
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
73
|
+
}
|
|
71
74
|
|
|
72
75
|
var self = this;
|
|
73
|
-
var query = self.find({ customer:
|
|
76
|
+
var query = self.find({ customer: options.CUSTOMER_ID });
|
|
74
77
|
|
|
75
78
|
if (options.startDate) {
|
|
76
79
|
var startDate = options.startDate || moment().subtract(20, 'years').startOf('day').toISOString();
|
|
@@ -83,7 +86,7 @@ module.exports = function(mongoose, config) {
|
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
query.exec(function(err, investments) {
|
|
86
|
-
|
|
89
|
+
|
|
87
90
|
if (err) return cb(err, null);
|
|
88
91
|
|
|
89
92
|
Round.find({
|
|
@@ -93,41 +96,28 @@ module.exports = function(mongoose, config) {
|
|
|
93
96
|
|
|
94
97
|
if (err) return cb(err, null);
|
|
95
98
|
|
|
96
|
-
var
|
|
97
|
-
|
|
98
|
-
var fund = null;
|
|
99
|
+
var organizationIds = _.compact(_.map(investments, function(inv) {
|
|
99
100
|
var organization = null;
|
|
100
|
-
var roundName = null;
|
|
101
101
|
|
|
102
102
|
var round = _.find(rounds, function(r) {
|
|
103
|
-
|
|
104
103
|
return _.some(r.vehicles, function(v) {
|
|
105
|
-
|
|
106
104
|
var investmentFound = _.some(v.investments, function(investmentId) {
|
|
107
105
|
return investmentId.toString() === inv._id.toString();
|
|
108
106
|
});
|
|
109
107
|
|
|
110
108
|
if (investmentFound) {
|
|
111
|
-
fund = v.fund;
|
|
112
109
|
organization = r.organization;
|
|
113
|
-
roundName = r.roundName;
|
|
114
110
|
}
|
|
115
111
|
|
|
116
112
|
return investmentFound;
|
|
117
|
-
|
|
118
113
|
});
|
|
119
|
-
|
|
120
114
|
});
|
|
121
115
|
|
|
122
|
-
return
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
fund: fund
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
});
|
|
116
|
+
return organization;
|
|
117
|
+
|
|
118
|
+
}));
|
|
129
119
|
|
|
130
|
-
cb(null,
|
|
120
|
+
cb(null, organizationIds);
|
|
131
121
|
|
|
132
122
|
});
|
|
133
123
|
|
package/lib/Round.js
CHANGED
|
@@ -391,6 +391,44 @@ module.exports = function(mongoose, config) {
|
|
|
391
391
|
|
|
392
392
|
};
|
|
393
393
|
|
|
394
|
+
Round.statics.getByOrgs2 = function getByOrg2(orgIds, options, cb) {
|
|
395
|
+
|
|
396
|
+
const self = this;
|
|
397
|
+
|
|
398
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
399
|
+
if (!orgIds) { throw new Error('orgIds is required'); }
|
|
400
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
401
|
+
|
|
402
|
+
options = helpers.getDefaultOptions(options);
|
|
403
|
+
|
|
404
|
+
if (!options.isWorkerProcess) {
|
|
405
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
406
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
let query = self.find({
|
|
410
|
+
'organization': { $in: orgIds }
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
if (options.isWorkerProcess) {
|
|
414
|
+
query.populate('vehicles.investments');
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
query.populate({
|
|
418
|
+
path: 'vehicles.investments',
|
|
419
|
+
match: { customer: options.CUSTOMER_ID }
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
query.exec(function(err, rounds) {
|
|
424
|
+
|
|
425
|
+
if (err) return cb(err, null);
|
|
426
|
+
return cb(null, rounds);
|
|
427
|
+
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
};
|
|
431
|
+
|
|
394
432
|
Round.statics.getFundInvestments = function getFundInvestments(fundId, options, cb) {
|
|
395
433
|
|
|
396
434
|
const self = this;
|