@dhyasama/totem-models 10.5.0 → 10.7.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.
Files changed (3) hide show
  1. package/helpers.js +35 -14
  2. package/lib/Round.js +29 -31
  3. package/package.json +1 -1
package/helpers.js CHANGED
@@ -16,14 +16,14 @@ const cleanOrg = module.exports.cleanOrg = function cleanOrg(doc, customerId) {
16
16
  // remove customer details if not viewing self
17
17
  if (doc._id.toString() !== customerId.toString()) { doc.customer = {}; }
18
18
 
19
- doc.chairs = _.reject(doc.chairs, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
20
- doc.customFields = _.reject(doc.customFields, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
21
- doc.filters = _.reject(doc.filters, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
22
- doc.lps = _.reject(doc.lps, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
23
- doc.valuations = _.reject(doc.valuations, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
24
- doc.documents = _.reject(doc.documents, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
25
- doc.operating.acquired.private = _.find(doc.operating.acquired.private, function(item) { return item && item.customer && item.customer.toString() === customerId.toString(); });
26
- doc.operating.closed.private = _.find(doc.operating.closed.private, function(item) { return item && item.customer && item.customer.toString() === customerId.toString(); });
19
+ if (doc.chairs) doc.chairs = _.reject(doc.chairs, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
20
+ if (doc.customFields) doc.customFields = _.reject(doc.customFields, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
21
+ if (doc.filters) doc.filters = _.reject(doc.filters, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
22
+ if (doc.lps) doc.lps = _.reject(doc.lps, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
23
+ if (doc.valuations) doc.valuations = _.reject(doc.valuations, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
24
+ if (doc.documents) doc.documents = _.reject(doc.documents, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
25
+ if (doc.operating && doc.operating.acquired) doc.operating.acquired.private = _.find(doc.operating.acquired.private, function(item) { return item && item.customer && item.customer.toString() === customerId.toString(); });
26
+ if (doc.operating && doc.operating.closed) doc.operating.closed.private = _.find(doc.operating.closed.private, function(item) { return item && item.customer && item.customer.toString() === customerId.toString(); });
27
27
 
28
28
  return doc;
29
29
 
@@ -36,12 +36,34 @@ const cleanPerson = module.exports.cleanPerson = function cleanPerson(doc, custo
36
36
  if (!customerId) { return; }
37
37
  if (!mongoose.Types.ObjectId.isValid(customerId)) { return; }
38
38
 
39
- doc.sources = _.reject(doc.sources, function(source) {
40
- let sourceCustomerId = mongoose.Types.ObjectId.isValid(source.customer) ? source.customer : source.customer._id;
41
- return sourceCustomerId.toString() !== customerId.toString();
42
- });
39
+ if (doc.sources) {
40
+ doc.sources = _.reject(doc.sources, function(source) {
41
+ let sourceCustomerId = mongoose.Types.ObjectId.isValid(source.customer) ? source.customer : source.customer._id;
42
+ return sourceCustomerId.toString() !== customerId.toString();
43
+ });
44
+ }
45
+
46
+ if (doc.documents) doc.documents = _.reject(doc.documents, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
47
+
48
+ return doc;
49
+
50
+ };
51
+
52
+ const cleanRound = module.exports.cleanRound = function cleanRound(doc, fundIds, customerId) {
43
53
 
44
- doc.documents = _.reject(doc.documents, function(item) { return !item || !item.customer || item.customer.toString() !== customerId.toString(); });
54
+ if (!doc) { return; }
55
+ if (!doc._id) { return; }
56
+ if (!customerId) { return; }
57
+ if (!mongoose.Types.ObjectId.isValid(customerId)) { return; }
58
+
59
+ fundIds = _.map(fundIds, function(id) { return id.toString(); });
60
+
61
+ if (doc.vehicles) {
62
+ doc.vehicles = _.reject(doc.vehicles, function(item) {
63
+ var fundId = mongoose.Types.ObjectId.isValid(item.fund) ? item.fund : item.fund._id;
64
+ return !_.contains(fundIds, fundId.toString());
65
+ });
66
+ }
45
67
 
46
68
  return doc;
47
69
 
@@ -76,7 +98,6 @@ const getGeolocation = module.exports.getGeolocation = function getGeolocation(i
76
98
 
77
99
  });
78
100
 
79
-
80
101
  };
81
102
 
82
103
  const getPeopleSources = module.exports.getPeopleSources = function getPeopleSources(people) {
package/lib/Round.js CHANGED
@@ -90,8 +90,6 @@ module.exports = function(mongoose, config) {
90
90
 
91
91
  var portfolio = [];
92
92
 
93
- rounds = filterVehicles(rounds, fundIds);
94
-
95
93
  // we now have all the rounds the funds have participated in with other fund information removed from each round
96
94
 
97
95
  // Group rounds by org, for two reasons:
@@ -114,7 +112,6 @@ module.exports = function(mongoose, config) {
114
112
  logoUrl: rounds[0].organization.logoUrl,
115
113
  description: rounds[0].organization.description,
116
114
  status: rounds[0].organization.status,
117
- filters: rounds[0].organization.filters,
118
115
  contact: rounds[0].organization.contact,
119
116
  websites: websites,
120
117
  rounds: rounds
@@ -158,24 +155,6 @@ module.exports = function(mongoose, config) {
158
155
 
159
156
  };
160
157
 
161
- var filterVehicles = function filterVehicles(rounds, fundIds) {
162
-
163
- // Given a collection of rounds, each with a collection of vehicles,
164
- // remove all vehicles that aren't for the given fund ids
165
-
166
- fundIds = _.map(fundIds, function(id) { return id.toString(); });
167
-
168
- _.each(rounds, function(r) {
169
- r.vehicles = _.filter(r.vehicles, function(v) {
170
- var fundid = mongoose.Types.ObjectId.isValid(v.fund) ? v.fund : v.fund._id;
171
- return fundIds.indexOf(fundid.toString()) >= 0;
172
- });
173
- });
174
-
175
- return rounds;
176
-
177
- };
178
-
179
158
  ///////////////////////////////////////////////////////////////////////////////////////
180
159
  // METHODS
181
160
  //
@@ -420,7 +399,7 @@ module.exports = function(mongoose, config) {
420
399
 
421
400
  let query = self.find({ 'vehicles.fund': fundId });
422
401
  query.select('organization roundName vehicles');
423
- query.populate('organization', 'name logoUrl website websiteAliases');
402
+ query.populate('organization', 'name logoUrl website websiteAliases filters status');
424
403
 
425
404
  if (options.isWorkerProcess) {
426
405
  query.populate('vehicles.investments');
@@ -437,17 +416,21 @@ module.exports = function(mongoose, config) {
437
416
  if (err) return cb(err, null);
438
417
  if (!rounds) return cb(null, []);
439
418
 
440
- let fundInvestments = [];
419
+ if (!options.isWorkerProcess) {
420
+ _.each(rounds, function(round) {
421
+ round = helpers.cleanRound(round, [fundId], options.CUSTOMER_ID);
422
+ round.organization = helpers.cleanOrg(round.organization, options.CUSTOMER_ID);
423
+ });
424
+ }
441
425
 
426
+ let fundInvestments = [];
442
427
  _.each(rounds, function(round) {
443
428
  _.each(round.vehicles, function(vehicle) {
444
- if(vehicle.fund.toString() === fundId.toString()) {
445
- _.each(vehicle.investments, function(investment) {
446
- investment.organization = round.organization;
447
- investment.roundName = round.roundName;
448
- fundInvestments.push(investment);
449
- });
450
- }
429
+ _.each(vehicle.investments, function(investment) {
430
+ investment.organization = round.organization;
431
+ investment.roundName = round.roundName;
432
+ fundInvestments.push(investment);
433
+ });
451
434
  });
452
435
  });
453
436
 
@@ -487,7 +470,13 @@ module.exports = function(mongoose, config) {
487
470
  else if (!rounds) return cb(null, null);
488
471
  else if (rounds.length === 0) return cb(null, []);
489
472
 
490
- rounds = filterVehicles(rounds, [fundId]);
473
+ if (!options.isWorkerProcess) {
474
+ _.each(rounds, function(round) {
475
+ round = helpers.cleanRound(round, [fundId], options.CUSTOMER_ID);
476
+ round.organization = helpers.cleanOrg(round.organization, options.CUSTOMER_ID);
477
+ });
478
+ }
479
+
491
480
  return cb(null, calculatePerformance(rounds));
492
481
 
493
482
  });
@@ -536,6 +525,7 @@ module.exports = function(mongoose, config) {
536
525
 
537
526
  if (!options.isWorkerProcess) {
538
527
  _.each(rounds, function(round) {
528
+ round = helpers.cleanRound(round, [fundId], options.CUSTOMER_ID);
539
529
  round.organization = helpers.cleanOrg(round.organization, options.CUSTOMER_ID);
540
530
  });
541
531
  }
@@ -599,6 +589,7 @@ module.exports = function(mongoose, config) {
599
589
 
600
590
  if (!options.isWorkerProcess) {
601
591
  _.each(rounds, function(round) {
592
+ round = helpers.cleanRound(round, fundIds, options.CUSTOMER_ID);
602
593
  round.organization = helpers.cleanOrg(round.organization, options.CUSTOMER_ID);
603
594
  });
604
595
  }
@@ -634,6 +625,13 @@ module.exports = function(mongoose, config) {
634
625
  if (err) return cb(err, null);
635
626
  if (!rounds || rounds.length === 0) return cb(null, []);
636
627
 
628
+ if (!options.isWorkerProcess) {
629
+ _.each(rounds, function(round) {
630
+ round = helpers.cleanRound(round, fundIds, options.CUSTOMER_ID);
631
+ round.organization = helpers.cleanOrg(round.organization, options.CUSTOMER_ID);
632
+ });
633
+ }
634
+
637
635
  let portfolio = [];
638
636
  const grouped = _.groupBy(rounds, function(r) { return r.organization._id; });
639
637
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "10.5.0",
3
+ "version": "10.7.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",