@dhyasama/totem-models 10.21.0 → 10.21.2

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/CapTable.js CHANGED
@@ -12,7 +12,6 @@
12
12
  //
13
13
  ///////////////////////////////////////////////////////////////////////////////////////
14
14
 
15
- const _ = require("underscore");
16
15
  module.exports = function(mongoose, config) {
17
16
 
18
17
  var Schema = mongoose.Schema;
@@ -425,6 +424,8 @@ module.exports = function(mongoose, config) {
425
424
  // combine provided and default options
426
425
  options = _.defaults(options || {}, defaultOptions);
427
426
 
427
+ const path = 'stakeholders.name';
428
+
428
429
  self.aggregate([
429
430
  {
430
431
  "$search": {
@@ -434,14 +435,11 @@ module.exports = function(mongoose, config) {
434
435
  {
435
436
  text: {
436
437
  query: value,
437
- path: [
438
- 'stakeholders.name'
439
- ],
438
+ path: path,
440
439
  fuzzy: {
441
440
  maxEdits: options.maxEdits,
442
441
  maxExpansions: options.maxExpansions
443
- },
444
- score: { boost: { value: 3 } }
442
+ }
445
443
  }
446
444
  }
447
445
  ],
@@ -454,16 +452,25 @@ module.exports = function(mongoose, config) {
454
452
  }
455
453
  ],
456
454
  minimumShouldMatch: 1
455
+ },
456
+ highlight: {
457
+ path: path
457
458
  }
458
459
  }
459
460
  },
460
461
  {
461
462
  $limit: options.limit,
462
463
  },
464
+ {
465
+ $addFields: {
466
+ name: "$stakeholders.name"
467
+ }
468
+ },
463
469
  {
464
470
  $project: {
465
- stakeholders: 1,
466
- score: { $meta: "searchScore" }
471
+ name: 1,
472
+ score: { $meta: "searchScore" },
473
+ highlights: { $meta: "searchHighlights" }
467
474
  }
468
475
  }
469
476
  ]).exec(cb);
package/lib/Financials.js CHANGED
@@ -7,7 +7,6 @@
7
7
  //
8
8
  ///////////////////////////////////////////////////////////////////////////////////////
9
9
 
10
- const _ = require("underscore");
11
10
  module.exports = function(mongoose, config) {
12
11
 
13
12
  var Schema = mongoose.Schema;
package/lib/Fund.js CHANGED
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
 
3
- const _ = require("underscore");
4
- const helpers = require("../helpers");
5
3
  module.exports = function(mongoose, config) {
6
4
 
7
5
  var Schema = mongoose.Schema;
8
- var Round = mongoose.model('Round');
9
6
  var _ = require('underscore');
10
7
 
11
8
  var Fund = new Schema({
@@ -13,10 +10,10 @@ module.exports = function(mongoose, config) {
13
10
  slug: { type: String, required: true, unique: true },
14
11
  abbreviation: { type: String },
15
12
  customFields: { type: Schema.Types.Mixed },
16
-
13
+
17
14
  // the stakeholders names we match to on cap tables
18
15
  stakeholders: [{ type: String, unique: true, partialFilterExpression : { type :"string" }, trim: true }]
19
-
16
+
20
17
  });
21
18
 
22
19
  /************* BASIC FIELDS **********************/
@@ -172,6 +169,7 @@ module.exports = function(mongoose, config) {
172
169
  {
173
170
  $project: {
174
171
  name: 1,
172
+ abbreviation: 1,
175
173
  score: { $meta: "searchScore" }
176
174
  }
177
175
  }
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const _ = require("underscore");
4
- const helpers = require("@dhyasama/totem-models/helpers");
5
3
  module.exports = function(mongoose, config) {
6
4
 
7
5
  let
@@ -116,18 +114,24 @@ module.exports = function(mongoose, config) {
116
114
 
117
115
  /////////////////////
118
116
 
119
- LimitedPartner.virtual('totalCommitment').get(function () {
120
- var self = this;
121
- return _.reduce(self.transactions, function(memo, transaction) {
117
+ const calculateTotalCommitment = function (transactions) {
118
+ return _.reduce(transactions, function(memo, transaction) {
122
119
  return memo + ((transaction.type === 'commitment' && Math.abs(transaction.amount) > 0) ? transaction.amount : 0);
123
120
  }, 0);
121
+ };
122
+
123
+ LimitedPartner.virtual('totalCommitment').get(function () {
124
+ return calculateTotalCommitment(this.transactions);
124
125
  });
125
126
 
126
- LimitedPartner.virtual('totalContribution').get(function () {
127
- var self = this;
128
- return _.reduce(self.transactions, function(memo, transaction) {
127
+ const calculateTotalContribution = function (transactions) {
128
+ return _.reduce(transactions, function(memo, transaction) {
129
129
  return memo + ((transaction.type === 'contribution' && Math.abs(transaction.amount) > 0) ? transaction.amount : 0);
130
130
  }, 0);
131
+ };
132
+
133
+ LimitedPartner.virtual('totalContribution').get(function () {
134
+ return calculateTotalContribution(this.transactions);
131
135
  });
132
136
 
133
137
  LimitedPartner.virtual('totalDistribution').get(function () {
@@ -864,10 +868,24 @@ module.exports = function(mongoose, config) {
864
868
  {
865
869
  $project: {
866
870
  name: 1,
871
+ transactions: 1,
867
872
  score: { $meta: "searchScore" }
868
873
  }
869
874
  }
870
- ]).exec(cb);
875
+ ]).exec(function(err, result) {
876
+
877
+ if (err) return cb(err);
878
+
879
+ _.each(result, function(item) {
880
+ item.commitment = calculateTotalCommitment(item.transactions);
881
+ item.contribution = calculateTotalContribution(item.transactions);
882
+ delete item.transactions;
883
+ });
884
+
885
+ return cb(null, result);
886
+
887
+
888
+ });
871
889
 
872
890
  };
873
891
 
@@ -1,8 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const _ = require("underscore");
4
- const utilities = require("@dhyasama/totem-utilities");
5
- const helpers = require("../helpers");
6
3
  module.exports = function(mongoose, config) {
7
4
 
8
5
  let
@@ -2071,6 +2068,13 @@ module.exports = function(mongoose, config) {
2071
2068
  // combine provided and default options
2072
2069
  options = _.defaults(options || {}, defaultOptions);
2073
2070
 
2071
+ const path = [
2072
+ 'name',
2073
+ 'aliases',
2074
+ 'websiteAliases',
2075
+ 'stakeholders'
2076
+ ];
2077
+
2074
2078
  self.aggregate([
2075
2079
  {
2076
2080
  "$search": {
@@ -2080,18 +2084,7 @@ module.exports = function(mongoose, config) {
2080
2084
  {
2081
2085
  text: {
2082
2086
  query: value,
2083
- path: [
2084
- 'name',
2085
- 'aliases',
2086
- 'website',
2087
- 'websiteAliases',
2088
- 'stakeholders'
2089
- ],
2090
- fuzzy: {
2091
- maxEdits: options.maxEdits,
2092
- maxExpansions: options.maxExpansions
2093
- },
2094
- score: { boost: { value: 3 } }
2087
+ path: path
2095
2088
  }
2096
2089
  }
2097
2090
  ],
@@ -2104,6 +2097,9 @@ module.exports = function(mongoose, config) {
2104
2097
  }
2105
2098
  ],
2106
2099
  minimumShouldMatch: 1
2100
+ },
2101
+ highlight: {
2102
+ path: path
2107
2103
  }
2108
2104
  }
2109
2105
  },
@@ -2114,7 +2110,8 @@ module.exports = function(mongoose, config) {
2114
2110
  $project: {
2115
2111
  name: 1,
2116
2112
  logoUrl: 1,
2117
- score: { $meta: "searchScore" }
2113
+ score: { $meta: "searchScore" },
2114
+ highlights: { $meta: "searchHighlights" }
2118
2115
  }
2119
2116
  }
2120
2117
  ]).exec(function(err, orgs) {
package/lib/Person.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- const _ = require("underscore");
4
3
  module.exports = function(mongoose, config) {
5
4
 
6
5
  let
@@ -1013,6 +1012,14 @@ module.exports = function(mongoose, config) {
1013
1012
  // combine provided and default options
1014
1013
  options = _.defaults(options || {}, defaultOptions);
1015
1014
 
1015
+ const path = [
1016
+ 'name.first',
1017
+ 'name.last',
1018
+ 'fullName',
1019
+ 'aliases',
1020
+ 'contact.email.email'
1021
+ ];
1022
+
1016
1023
  self.aggregate([
1017
1024
  {
1018
1025
  "$search": {
@@ -1022,17 +1029,7 @@ module.exports = function(mongoose, config) {
1022
1029
  {
1023
1030
  text: {
1024
1031
  query: query,
1025
- path: [
1026
- 'name.first',
1027
- 'name.last',
1028
- 'fullName',
1029
- 'aliases',
1030
- 'stakeholders'
1031
- ],
1032
- fuzzy: {
1033
- maxEdits: options.maxEdits,
1034
- maxExpansions: options.maxExpansions
1035
- }
1032
+ path: path
1036
1033
  }
1037
1034
  }
1038
1035
  ],
@@ -1043,8 +1040,10 @@ module.exports = function(mongoose, config) {
1043
1040
  value: false
1044
1041
  }
1045
1042
  }
1046
- ],
1047
- minimumShouldMatch: 1
1043
+ ]
1044
+ },
1045
+ highlight: {
1046
+ path: path
1048
1047
  }
1049
1048
  }
1050
1049
  }, {
@@ -1056,7 +1055,8 @@ module.exports = function(mongoose, config) {
1056
1055
  "name": 1,
1057
1056
  "avatarUrl": 1,
1058
1057
  "sources": 1,
1059
- "score": { "$meta": "searchScore" }
1058
+ "score": { "$meta": "searchScore" },
1059
+ highlights: { $meta: "searchHighlights" }
1060
1060
  }
1061
1061
  }
1062
1062
  ]).exec(function(err, people) {
package/lib/Round.js CHANGED
@@ -618,7 +618,7 @@ module.exports = function(mongoose, config) {
618
618
  let query = self.find({ 'vehicles.fund': { $in: fundIds } });
619
619
 
620
620
  query.select('organization');
621
- query.populate('organization', 'name');
621
+ query.populate('organization', 'name people');
622
622
 
623
623
  query.exec(function(err, rounds) {
624
624
 
@@ -639,7 +639,8 @@ module.exports = function(mongoose, config) {
639
639
 
640
640
  portfolio.push({
641
641
  _id: rounds[0].organization._id,
642
- name: rounds[0].organization.name
642
+ name: rounds[0].organization.name,
643
+ people: rounds[0].organization.people
643
644
  });
644
645
 
645
646
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "10.21.0",
3
+ "version": "10.21.2",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -16,7 +16,7 @@ var
16
16
  Organization = mongoose.model('Organization'),
17
17
  organization = new Organization();
18
18
 
19
- describe('Limited Partner', function() {
19
+ describe.only('Limited Partner', function() {
20
20
 
21
21
  before(function(done) {
22
22
  databaseHelpers.connect(mongoose, done);
@@ -123,7 +123,7 @@ describe('Limited Partner', function() {
123
123
  lp.transactions.push({
124
124
  fund: fund,
125
125
  type: 'commitment',
126
- amount: 100000,
126
+ amount: 1000000,
127
127
  date: new Date()
128
128
  });
129
129
 
@@ -279,6 +279,26 @@ describe('Limited Partner', function() {
279
279
  });
280
280
  });
281
281
 
282
+ it('calculates an lps total commitment', function(done) {
283
+ LimitedPartner.getById(lp.id, { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, result) {
284
+ should.not.exist(err);
285
+ should.exist(result);
286
+ result.id.should.equal(lp.id);
287
+ result.totalCommitment.should.equal(1000000);
288
+ done();
289
+ });
290
+ });
291
+
292
+ it('calculates an lps total contribution', function(done) {
293
+ LimitedPartner.getById(lp.id, { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, result) {
294
+ should.not.exist(err);
295
+ should.exist(result);
296
+ result.id.should.equal(lp.id);
297
+ result.totalContribution.should.equal(400000);
298
+ done();
299
+ });
300
+ });
301
+
282
302
  it('adds a note', function(done) {
283
303
 
284
304
  LimitedPartner.addNote(lp.id, person._id, 'Sweet note bro!', false, organization._id, function(err, result) {
@@ -19,7 +19,7 @@ var someOtherLp;
19
19
  var account;
20
20
  var customer1, customer2;
21
21
 
22
- describe.only('Organization', function() {
22
+ describe('Organization', function() {
23
23
 
24
24
  var org1, org2, org3, org4, org5;
25
25
  var mergeId = new mongoose.Types.ObjectId();