@dhyasama/totem-models 1.16.0 → 1.17.1

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 CHANGED
@@ -77,6 +77,26 @@ module.exports = function(mongoose, config) {
77
77
 
78
78
 
79
79
 
80
+ ///////////////////////////////////////////////////////////////////////////////////////
81
+ // VIRTUALS
82
+ // Properties that are not persisted to the database
83
+ ///////////////////////////////////////////////////////////////////////////////////////
84
+
85
+ Investment.virtual('month').get(function () {
86
+ var self = this;
87
+ var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
88
+ if (!self.investmentDate) return 'Unknown';
89
+ else return monthNames[self.investmentDate.getMonth()];
90
+ });
91
+
92
+ Investment.virtual('year').get(function () {
93
+ var self = this;
94
+ if (!self.investmentDate) return 'Unknown';
95
+ else return self.investmentDate.getFullYear();
96
+ });
97
+
98
+
99
+
80
100
  //////////////////////////////////////////////////////
81
101
  // STATICS
82
102
  // Statics operate on the entire collection
@@ -409,12 +409,29 @@ module.exports = function(mongoose, config) {
409
409
  LimitedPartner.statics.getByPersonId = function(personId, role, cb) {
410
410
 
411
411
  var self = this;
412
+ var query;
412
413
 
413
- self
414
- .find({'people': personId}, this.getReadFilterKeys(role))
415
- .populate('fundsInvested.fund')
416
- .populate('people', 'name')
417
- .exec(cb);
414
+ var getLps = function(q) {
415
+ q.populate('fundsInvested.fund')
416
+ q.populate('people', 'name')
417
+ q.exec(function (err, lps) {
418
+ if (err) return cb(err, null);
419
+ lps = _.sortBy(lps, function(lp) { return lp.name ? lp.name.toLowerCase() : ''; });
420
+ return cb(null, lps);
421
+ });
422
+ };
423
+
424
+ if (CUSTOMER_ID == 'GLOBAL_PROCESS') {
425
+ query = self.find({'people': personId}, this.getReadFilterKeys(role))
426
+ getLps(query);
427
+ }
428
+ else {
429
+ getFundIdsForCustomer(function(err, fundIds) {
430
+ if (err) return cb(err, null);
431
+ query = self.find({'people': personId, 'fundsInvested.fund': { $in : fundIds }}, self.getReadFilterKeys(role));
432
+ getLps(query);
433
+ });
434
+ }
418
435
 
419
436
  };
420
437
 
@@ -426,29 +443,25 @@ module.exports = function(mongoose, config) {
426
443
 
427
444
  var self = this;
428
445
  var query;
429
- var getLps = function() {
430
- query.populate('fundsInvested.fund')
431
- query.exec(function (err, lps) {
432
446
 
447
+ var getLps = function(q) {
448
+ q.populate('fundsInvested.fund')
449
+ q.exec(function (err, lps) {
433
450
  if (err) return cb(err, null);
434
-
435
- lps = _.sortBy(lps, function(lp) {
436
- return lp.name ? lp.name.toLowerCase() : '';
437
- });
438
-
451
+ lps = _.sortBy(lps, function(lp) { return lp.name ? lp.name.toLowerCase() : ''; });
439
452
  return cb(null, lps);
440
453
  });
441
454
  };
442
455
 
443
456
  if (CUSTOMER_ID == 'GLOBAL_PROCESS') {
444
457
  query = self.find({}, self.getReadFilterKeys(role));
445
- getLps();
458
+ getLps(query);
446
459
  }
447
460
  else {
448
461
  getFundIdsForCustomer(function(err, fundIds) {
449
462
  if (err) return cb(err, null);
450
463
  query = self.find({ 'fundsInvested.fund': { $in : fundIds }}, self.getReadFilterKeys(role));
451
- getLps();
464
+ getLps(query);
452
465
  });
453
466
  }
454
467
 
package/lib/Round.js CHANGED
@@ -408,7 +408,6 @@ module.exports = function(mongoose, config) {
408
408
  .populate('organization', 'name logoUrl')
409
409
  .populate('people.person', 'name avatarUrl title')
410
410
  .populate('vehicles.fund', 'name shortName')
411
- .populate('vehicles.investments')
412
411
  .populate({
413
412
  path: 'vehicles.investments',
414
413
  match: { customer: config.CUSTOMER_ID }
@@ -453,7 +452,10 @@ module.exports = function(mongoose, config) {
453
452
  .populate('organization', 'name logoUrl')
454
453
  .populate('people.person', 'name avatarUrl')
455
454
  .populate('vehicles.fund')
456
- .populate('vehicles.investments')
455
+ .populate({
456
+ path: 'vehicles.investments',
457
+ match: { customer: config.CUSTOMER_ID }
458
+ })
457
459
  .exec(function(err, rounds) {
458
460
 
459
461
  if (err) return cb(err, null);
@@ -533,7 +535,10 @@ module.exports = function(mongoose, config) {
533
535
  .select('organization vehicles preMoneyValuation')
534
536
  .populate('organization', 'name logoUrl description contact industries status ipo closed acquired operating')
535
537
  .populate('vehicles.fund')
536
- .populate('vehicles.investments')
538
+ .populate({
539
+ path: 'vehicles.investments',
540
+ match: { customer: config.CUSTOMER_ID }
541
+ })
537
542
  .exec(function(err, rounds) {
538
543
 
539
544
  if (err) return cb(err, null);
@@ -560,7 +565,10 @@ module.exports = function(mongoose, config) {
560
565
  .select('organization vehicles preMoneyValuation')
561
566
  .populate('organization', 'name logoUrl description contact industries status ipo closed acquired operating')
562
567
  .populate('vehicles.fund')
563
- .populate('vehicles.investments')
568
+ .populate({
569
+ path: 'vehicles.investments',
570
+ match: { customer: config.CUSTOMER_ID }
571
+ })
564
572
  .exec(function(err, rounds) {
565
573
 
566
574
  if (err) return cb(err, null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "1.16.0",
3
+ "version": "1.17.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",