@dhyasama/totem-models 11.15.0 → 11.16.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/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
|
|