@dhyasama/totem-models 10.16.0 → 10.18.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/CapTable.js CHANGED
@@ -12,6 +12,7 @@
12
12
  //
13
13
  ///////////////////////////////////////////////////////////////////////////////////////
14
14
 
15
+ const _ = require("underscore");
15
16
  module.exports = function(mongoose, config) {
16
17
 
17
18
  var Schema = mongoose.Schema;
@@ -35,7 +36,7 @@ module.exports = function(mongoose, config) {
35
36
  document: { type: Schema.ObjectId, ref: 'Document', required: false },
36
37
 
37
38
  stakeholders: [{
38
-
39
+
39
40
  _id: false,
40
41
 
41
42
  // the raw stakeholder name on the cap table
@@ -107,7 +108,7 @@ module.exports = function(mongoose, config) {
107
108
  // Properties that are not persisted to the database
108
109
  ///////////////////////////////////////////////////////////////////////////////////////
109
110
 
110
- CapTable.virtual('shares').get(function() {
111
+ CapTable.virtual('shares').get(function() {
111
112
 
112
113
  var self = this;
113
114
 
@@ -142,7 +143,7 @@ module.exports = function(mongoose, config) {
142
143
  if (!customerid) { return cb(new Error('customerid is required'), null); }
143
144
  if (!mongoose.Types.ObjectId.isValid(customerid)) { return cb(new Error('customerid is not a valid ObjectId'), null); }
144
145
  if (!options) { return cb(new Error('options is required'), null); }
145
-
146
+
146
147
  let query;
147
148
 
148
149
  query = self.find({
@@ -153,7 +154,7 @@ module.exports = function(mongoose, config) {
153
154
  query.populate('stakeholders.lp', 'name')
154
155
  query.populate('stakeholders.org', 'name logoUrl')
155
156
  query.populate('stakeholders.person', 'name avatarUrl title')
156
-
157
+
157
158
  query.exec(cb);
158
159
 
159
160
  };
@@ -166,7 +167,7 @@ module.exports = function(mongoose, config) {
166
167
  if (!customerid) { return cb(new Error('customerid is required'), null); }
167
168
  if (!mongoose.Types.ObjectId.isValid(customerid)) { return cb(new Error('customerid is not a valid ObjectId'), null); }
168
169
  if (!options) { return cb(new Error('options is required'), null); }
169
-
170
+
170
171
  self.deleteMany({ customer: customerid, 'entered.by': { $ne: 'carta-parser' } }, cb);
171
172
 
172
173
  };
@@ -179,7 +180,7 @@ module.exports = function(mongoose, config) {
179
180
  if (!orgid) { return cb(new Error('orgid is required'), null); }
180
181
  if (!mongoose.Types.ObjectId.isValid(orgid)) { return cb(new Error('orgid is not a valid ObjectId'), null); }
181
182
  if (!options) { return cb(new Error('options is required'), null); }
182
-
183
+
183
184
  var query;
184
185
 
185
186
  if (options.isWorkerProcess) {
@@ -189,10 +190,10 @@ module.exports = function(mongoose, config) {
189
190
  }
190
191
 
191
192
  else {
192
-
193
+
193
194
  if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
194
195
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
195
-
196
+
196
197
  query = self.findOne({
197
198
  customer: options.CUSTOMER_ID,
198
199
  organization: orgid
@@ -217,7 +218,7 @@ module.exports = function(mongoose, config) {
217
218
  if (!lpid) { return cb(new Error('lpid is required'), null); }
218
219
  if (!mongoose.Types.ObjectId.isValid(lpid)) { return cb(new Error('lpid is not a valid ObjectId'), null); }
219
220
  if (!options) { return cb(new Error('options is required'), null); }
220
-
221
+
221
222
  var query;
222
223
 
223
224
  if (options.isWorkerProcess) {
@@ -230,7 +231,7 @@ module.exports = function(mongoose, config) {
230
231
 
231
232
  if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
232
233
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
233
-
234
+
234
235
  query = self.find({
235
236
  customer: options.CUSTOMER_ID,
236
237
  'stakeholders.lp': lpid
@@ -250,7 +251,7 @@ module.exports = function(mongoose, config) {
250
251
  if (!cb) { throw new Error('cb is required'); }
251
252
  if (!lpids) { return cb(new Error('lpids is required'), null); }
252
253
  if (!options) { return cb(new Error('options is required'), null); }
253
-
254
+
254
255
  var query;
255
256
 
256
257
  if (options.isWorkerProcess) {
@@ -263,7 +264,7 @@ module.exports = function(mongoose, config) {
263
264
 
264
265
  if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
265
266
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
266
-
267
+
267
268
  query = self.find({
268
269
  customer: options.CUSTOMER_ID,
269
270
  'stakeholders.lp': { $in : lpids }
@@ -284,7 +285,7 @@ module.exports = function(mongoose, config) {
284
285
  if (!orgid) { return cb(new Error('orgid is required'), null); }
285
286
  if (!mongoose.Types.ObjectId.isValid(orgid)) { return cb(new Error('orgid is not a valid ObjectId'), null); }
286
287
  if (!options) { return cb(new Error('options is required'), null); }
287
-
288
+
288
289
  var query;
289
290
 
290
291
  if (options.isWorkerProcess) {
@@ -297,7 +298,7 @@ module.exports = function(mongoose, config) {
297
298
 
298
299
  if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
299
300
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
300
-
301
+
301
302
  query = self.find({
302
303
  customer: options.CUSTOMER_ID,
303
304
  'stakeholders.org': orgid
@@ -318,7 +319,7 @@ module.exports = function(mongoose, config) {
318
319
  if (!personid) { return cb(new Error('personid is required'), null); }
319
320
  if (!mongoose.Types.ObjectId.isValid(personid)) { return cb(new Error('personid is not a valid ObjectId'), null); }
320
321
  if (!options) { return cb(new Error('options is required'), null); }
321
-
322
+
322
323
  var query;
323
324
 
324
325
  if (options.isWorkerProcess) {
@@ -331,7 +332,7 @@ module.exports = function(mongoose, config) {
331
332
 
332
333
  if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
333
334
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
334
-
335
+
335
336
  query = self.find({
336
337
  customer: options.CUSTOMER_ID,
337
338
  'stakeholders.person': personid
@@ -405,6 +406,70 @@ module.exports = function(mongoose, config) {
405
406
 
406
407
  };
407
408
 
409
+ CapTable.statics.search2 = function search2(value, options, cb) {
410
+
411
+ const self = this;
412
+
413
+ if (!cb) { throw new Error('cb is required'); }
414
+ if (!value) { return cb(new Error('value is required'), null); }
415
+ if (!options) { return cb(new Error('options is required'), null); }
416
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
417
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
418
+
419
+ const defaultOptions = {
420
+ limit: 10,
421
+ maxEdits: 1,
422
+ maxExpansions: 100
423
+ };
424
+
425
+ // combine provided and default options
426
+ options = _.defaults(options || {}, defaultOptions);
427
+
428
+ self.aggregate([
429
+ {
430
+ "$search": {
431
+ index: 'default',
432
+ compound: {
433
+ should: [
434
+ {
435
+ text: {
436
+ query: value,
437
+ path: [
438
+ 'stakeholders.name'
439
+ ],
440
+ fuzzy: {
441
+ maxEdits: options.maxEdits,
442
+ maxExpansions: options.maxExpansions
443
+ },
444
+ score: { boost: { value: 3 } }
445
+ }
446
+ }
447
+ ],
448
+ must: [
449
+ {
450
+ equals: {
451
+ path: 'customer',
452
+ value: mongoose.Types.ObjectId(options.CUSTOMER_ID)
453
+ }
454
+ }
455
+ ],
456
+ minimumShouldMatch: 1
457
+ }
458
+ }
459
+ },
460
+ {
461
+ $limit: options.limit,
462
+ },
463
+ {
464
+ $project: {
465
+ stakeholders: 1,
466
+ score: { $meta: "searchScore" }
467
+ }
468
+ }
469
+ ]).exec(cb);
470
+
471
+ };
472
+
408
473
  CapTable.statics.upsert = function upsert(capTable, cb) {
409
474
 
410
475
  if (!capTable) { return cb(new Error('cap table is required'), null); }
package/lib/Fund.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ const _ = require("underscore");
4
+ const helpers = require("../helpers");
3
5
  module.exports = function(mongoose, config) {
4
6
 
5
7
  var Schema = mongoose.Schema;
@@ -126,6 +128,81 @@ module.exports = function(mongoose, config) {
126
128
 
127
129
  };
128
130
 
131
+ Fund.statics.search2 = function search2(value, options, cb) {
132
+
133
+ const self = this;
134
+
135
+ if (!cb) { throw new Error('cb is required'); }
136
+ if (!value) { return cb(new Error('value is required'), null); }
137
+ if (!options) { return cb(new Error('options is required'), null); }
138
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
139
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
140
+
141
+ const defaultOptions = {
142
+ limit: 10,
143
+ maxEdits: 1,
144
+ maxExpansions: 100
145
+ };
146
+
147
+ // combine provided and default options
148
+ options = _.defaults(options || {}, defaultOptions);
149
+
150
+ self.aggregate([
151
+ {
152
+ "$search": {
153
+ index: 'default',
154
+ compound: {
155
+ should: [
156
+ {
157
+ text: {
158
+ query: value,
159
+ path: [
160
+ 'name',
161
+ 'stakeholders'
162
+ ],
163
+ fuzzy: {
164
+ maxEdits: options.maxEdits,
165
+ maxExpansions: options.maxExpansions
166
+ },
167
+ score: { boost: { value: 3 } }
168
+ }
169
+ }
170
+ ],
171
+ must: [
172
+ {
173
+ equals: {
174
+ path: 'customer',
175
+ value: mongoose.Types.ObjectId(options.CUSTOMER_ID)
176
+ }
177
+ }
178
+ ],
179
+ minimumShouldMatch: 1
180
+ }
181
+ }
182
+ },
183
+ {
184
+ $limit: options.limit,
185
+ },
186
+ {
187
+ $project: {
188
+ name: 1,
189
+ score: { $meta: "searchScore" }
190
+ }
191
+ }
192
+ ]).exec(function(err, orgs) {
193
+
194
+ if (err) { return cb(err, null); }
195
+
196
+ orgs = _.map(orgs, function(org) {
197
+ return helpers.cleanOrg(org, options.CUSTOMER_ID);
198
+ });
199
+
200
+ return cb(null, orgs);
201
+
202
+ });
203
+
204
+ };
205
+
129
206
  Fund.statics.upsert = function upsert(fund, username, cb) {
130
207
 
131
208
  if (!fund) { return cb(new Error('Fund is required'), null); }
@@ -154,9 +154,10 @@ module.exports = function(mongoose, config) {
154
154
  }],
155
155
 
156
156
  valuations: [{
157
- amount: { type: Number, default: 0 },
158
- description: { type: String, trim: true },
159
157
  date: { type: Date, default: null },
158
+ valuation: { type: Number, default: 0 },
159
+ pricePerShare: { type: Number, default: 0 },
160
+ method: { type: String, trim: true },
160
161
  customer: { type: Schema.ObjectId, ref: 'Organization' },
161
162
  }],
162
163
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "10.16.0",
3
+ "version": "10.18.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",