@dhyasama/totem-models 8.47.1 → 8.48.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/Round.js +7 -45
- package/package.json +1 -1
package/lib/Round.js
CHANGED
|
@@ -54,14 +54,9 @@ module.exports = function(mongoose, config) {
|
|
|
54
54
|
// These references are removed by the Investment post-remove hook calling Round.removeInvestment
|
|
55
55
|
investments: [{ type: Schema.ObjectId, ref: 'Investment', required: false }],
|
|
56
56
|
|
|
57
|
-
// computed from investments
|
|
58
|
-
investment: { type: Number, default: 0 },
|
|
59
|
-
unrealized: { type: Number, default: 0 },
|
|
60
|
-
realized: { type: Number, default: 0 },
|
|
61
|
-
|
|
62
57
|
_id: false
|
|
63
58
|
|
|
64
|
-
}]
|
|
59
|
+
}],
|
|
65
60
|
|
|
66
61
|
});
|
|
67
62
|
|
|
@@ -202,19 +197,6 @@ module.exports = function(mongoose, config) {
|
|
|
202
197
|
|
|
203
198
|
};
|
|
204
199
|
|
|
205
|
-
///////////////////////////////////////////////////////////////////////////////////////
|
|
206
|
-
// VIRTUALS
|
|
207
|
-
// Properties that are not persisted to the database
|
|
208
|
-
///////////////////////////////////////////////////////////////////////////////////////
|
|
209
|
-
|
|
210
|
-
Round.virtual('value').get(function () {
|
|
211
|
-
// sums the value (realized and unrealized) of all vehicles in the round
|
|
212
|
-
var self = this;
|
|
213
|
-
return _.reduce(self.vehicles, function(memo, vehicle) {
|
|
214
|
-
return memo + vehicle.unrealized + vehicle.realized;
|
|
215
|
-
}, 0);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
200
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
219
201
|
// METHODS
|
|
220
202
|
//
|
|
@@ -227,7 +209,7 @@ module.exports = function(mongoose, config) {
|
|
|
227
209
|
// will add a bunch of things and then just get saved once.
|
|
228
210
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
229
211
|
|
|
230
|
-
Round.methods.addInvestment = function addInvestment(investment, fund
|
|
212
|
+
Round.methods.addInvestment = function addInvestment(investment, fund) {
|
|
231
213
|
|
|
232
214
|
// Add an investment reference
|
|
233
215
|
// Investment data is private
|
|
@@ -252,7 +234,7 @@ module.exports = function(mongoose, config) {
|
|
|
252
234
|
}
|
|
253
235
|
|
|
254
236
|
// Create or update
|
|
255
|
-
var vehicle = self.addVehicle(fund
|
|
237
|
+
var vehicle = self.addVehicle(fund);
|
|
256
238
|
var fid = mongoose.Types.ObjectId.isValid(vehicle.fund) ? vehicle.fund : vehicle.fund._id;
|
|
257
239
|
|
|
258
240
|
// The vehicle returned by addVehicle, appears to be a copy not a reference which is odd to me.
|
|
@@ -304,7 +286,7 @@ module.exports = function(mongoose, config) {
|
|
|
304
286
|
|
|
305
287
|
};
|
|
306
288
|
|
|
307
|
-
Round.methods.addVehicle = function addVehicle(fund
|
|
289
|
+
Round.methods.addVehicle = function addVehicle(fund) {
|
|
308
290
|
|
|
309
291
|
// Add a vehicle, which is a fund
|
|
310
292
|
// This data is public
|
|
@@ -322,10 +304,6 @@ module.exports = function(mongoose, config) {
|
|
|
322
304
|
if (!mongoose.Types.ObjectId.isValid(fund)) throw new Error('Need a valid fund objectid!');
|
|
323
305
|
}
|
|
324
306
|
|
|
325
|
-
data = data || {};
|
|
326
|
-
data.unrealized = data.unrealized || 0;
|
|
327
|
-
data.realized = data.realized || 0;
|
|
328
|
-
|
|
329
307
|
// Check if vehicle is already added
|
|
330
308
|
let vehicle = _.find(self.vehicles, function(v) {
|
|
331
309
|
let fundid = mongoose.Types.ObjectId.isValid(v.fund) ? v.fund : v.fund._id;
|
|
@@ -333,17 +311,10 @@ module.exports = function(mongoose, config) {
|
|
|
333
311
|
});
|
|
334
312
|
|
|
335
313
|
// update data on existing vehicle
|
|
336
|
-
if (vehicle) {
|
|
337
|
-
vehicle.unrealized = data.unrealized;
|
|
338
|
-
vehicle.realized = data.realized;
|
|
339
|
-
}
|
|
340
|
-
// create vehicle
|
|
341
|
-
else {
|
|
314
|
+
if (!vehicle) {
|
|
342
315
|
vehicle = {
|
|
343
316
|
fund: fund,
|
|
344
|
-
investments: []
|
|
345
|
-
unrealized: data.unrealized,
|
|
346
|
-
realized: data.realized
|
|
317
|
+
investments: []
|
|
347
318
|
};
|
|
348
319
|
self.vehicles.push(vehicle);
|
|
349
320
|
}
|
|
@@ -559,7 +530,7 @@ module.exports = function(mongoose, config) {
|
|
|
559
530
|
|
|
560
531
|
let totalInvestment = _.reduce(rounds, function(memo, round) {
|
|
561
532
|
let roundInvestment = _.reduce(round.vehicles, function(memo, vehicle) { return memo + vehicle.investment; }, 0);
|
|
562
|
-
return memo +
|
|
533
|
+
return memo + roundInvestment;
|
|
563
534
|
}, 0);
|
|
564
535
|
|
|
565
536
|
let totalUnrealized = _.reduce(rounds, function(memo, round) {
|
|
@@ -872,15 +843,6 @@ module.exports = function(mongoose, config) {
|
|
|
872
843
|
|
|
873
844
|
if (!doc || !doc.vehicles) { return next(); }
|
|
874
845
|
|
|
875
|
-
// note participating people are public as there is no investment, i.e., private, data attached to them
|
|
876
|
-
|
|
877
|
-
// participating vehicles are public
|
|
878
|
-
// merge private data that was matched for customer
|
|
879
|
-
|
|
880
|
-
doc.vehicles = _.filter(doc.vehicles, function(vehicle) {
|
|
881
|
-
return vehicle.investments.length > 0;
|
|
882
|
-
});
|
|
883
|
-
|
|
884
846
|
next();
|
|
885
847
|
|
|
886
848
|
});
|