@dhyasama/totem-models 8.47.0 → 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 +17 -53
- 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
|
}
|
|
@@ -405,12 +376,13 @@ module.exports = function(mongoose, config) {
|
|
|
405
376
|
// reverse chronological
|
|
406
377
|
rounds = _.sortBy(rounds, function(r) {
|
|
407
378
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
date = r.vehicles[0].investments[0].date;
|
|
379
|
+
if (r.vehicles.length && r.vehicles[0].investments.length) {
|
|
380
|
+
return r.vehicles[0].investments[0].date;
|
|
411
381
|
}
|
|
412
382
|
|
|
413
|
-
|
|
383
|
+
else {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
414
386
|
|
|
415
387
|
}).reverse();
|
|
416
388
|
|
|
@@ -465,12 +437,13 @@ module.exports = function(mongoose, config) {
|
|
|
465
437
|
// reverse chronological
|
|
466
438
|
rounds = _.sortBy(rounds, function(r) {
|
|
467
439
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
date = r.vehicles[0].investments[0].date;
|
|
440
|
+
if (r.vehicles.length && r.vehicles[0].investments.length) {
|
|
441
|
+
return r.vehicles[0].investments[0].date;
|
|
471
442
|
}
|
|
472
443
|
|
|
473
|
-
|
|
444
|
+
else {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
474
447
|
|
|
475
448
|
}).reverse();
|
|
476
449
|
|
|
@@ -557,7 +530,7 @@ module.exports = function(mongoose, config) {
|
|
|
557
530
|
|
|
558
531
|
let totalInvestment = _.reduce(rounds, function(memo, round) {
|
|
559
532
|
let roundInvestment = _.reduce(round.vehicles, function(memo, vehicle) { return memo + vehicle.investment; }, 0);
|
|
560
|
-
return memo +
|
|
533
|
+
return memo + roundInvestment;
|
|
561
534
|
}, 0);
|
|
562
535
|
|
|
563
536
|
let totalUnrealized = _.reduce(rounds, function(memo, round) {
|
|
@@ -870,15 +843,6 @@ module.exports = function(mongoose, config) {
|
|
|
870
843
|
|
|
871
844
|
if (!doc || !doc.vehicles) { return next(); }
|
|
872
845
|
|
|
873
|
-
// note participating people are public as there is no investment, i.e., private, data attached to them
|
|
874
|
-
|
|
875
|
-
// participating vehicles are public
|
|
876
|
-
// merge private data that was matched for customer
|
|
877
|
-
|
|
878
|
-
doc.vehicles = _.filter(doc.vehicles, function(vehicle) {
|
|
879
|
-
return vehicle.investments.length > 0;
|
|
880
|
-
});
|
|
881
|
-
|
|
882
846
|
next();
|
|
883
847
|
|
|
884
848
|
});
|