@dhyasama/totem-models 8.0.3 → 8.0.5

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/Deal.js CHANGED
@@ -6,8 +6,7 @@ module.exports = function(mongoose, config) {
6
6
 
7
7
  Schema = mongoose.Schema,
8
8
  async = require('async'),
9
- _ = require('underscore'),
10
- utilities = require('@dhyasama/ffvc-utilities');
9
+ _ = require('underscore');
11
10
 
12
11
  let Deal = new Schema({
13
12
 
package/lib/Document.js CHANGED
@@ -5,7 +5,7 @@ module.exports = function(mongoose, config) {
5
5
  var
6
6
 
7
7
  Schema = mongoose.Schema,
8
- utilities = require('@dhyasama/ffvc-utilities'),
8
+ utilities = require('@dhyasama/totem-utilities'),
9
9
  _ = require('underscore');
10
10
 
11
11
  var Document = new Schema({
@@ -5,7 +5,7 @@ module.exports = function(mongoose, config) {
5
5
  let Schema = mongoose.Schema;
6
6
  let async = require('async');
7
7
  let Note = mongoose.model('Note');
8
- let utilities = require('@dhyasama/ffvc-utilities');
8
+ let utilities = require('@dhyasama/totem-utilities');
9
9
  let moment = require('moment');
10
10
  let helpers = require('../helpers');
11
11
 
package/lib/List.js CHANGED
@@ -6,7 +6,6 @@ module.exports = function(mongoose, config) {
6
6
 
7
7
  Schema = mongoose.Schema,
8
8
  env = process.env.NODE_ENV || 'development',
9
- utils = require('@dhyasama/ffvc-utilities'),
10
9
  _ = require('underscore');
11
10
 
12
11
  let List = new Schema({
@@ -235,7 +234,7 @@ module.exports = function(mongoose, config) {
235
234
 
236
235
  let dedupeArray = function dedupeArray(arr) {
237
236
  return _.uniq(arr, function(item) {
238
- return (utils.isValidObjectId(item) ? item : item._id).toString();
237
+ return (mongoose.Types.ObjectId.isValid(item) ? item : item._id).toString();
239
238
  });
240
239
  };
241
240
 
@@ -6,7 +6,7 @@ module.exports = function(mongoose, config) {
6
6
 
7
7
  _ = require('underscore'),
8
8
  async = require('async'),
9
- utils = require('@dhyasama/ffvc-utilities'),
9
+ utilities = require('@dhyasama/totem-utilities'),
10
10
  helpers = require('../helpers'),
11
11
  Schema = mongoose.Schema,
12
12
  Flag = mongoose.model('Flag'),
@@ -932,12 +932,12 @@ module.exports = function(mongoose, config) {
932
932
  // Some simple validation
933
933
  if (!personToAdd) throw new Error('Must supply person to add');
934
934
  if (!personToAdd.person) throw new Error('Person to add must have person reference');
935
- if (!utils.isValidObjectId(personToAdd.person)) throw new Error('Person reference must be a valid objectid');
935
+ if (!mongoose.Types.ObjectId.isValid(personToAdd.person)) throw new Error('Person reference must be a valid objectid');
936
936
 
937
937
  // Check if person is already added
938
938
  var match = _.find(self.people, function(existingPerson) {
939
939
  if (existingPerson.person == null) return null;
940
- var id = utils.isValidObjectId(existingPerson.person) ? existingPerson.person : existingPerson.person.id;
940
+ var id = mongoose.Types.ObjectId.isValid(existingPerson.person) ? existingPerson.person : existingPerson.person.id;
941
941
  return id.toString() == personToAdd.person.toString();
942
942
  });
943
943
 
@@ -966,7 +966,7 @@ module.exports = function(mongoose, config) {
966
966
  var self = this;
967
967
 
968
968
  var match = _.find(self.related, function(org) {
969
- var orgId = utils.isValidObjectId(org) ? org : org.id;
969
+ var orgId = mongoose.Types.ObjectId.isValid(org) ? org : org.id;
970
970
  return orgId.toString() === id.toString();
971
971
  });
972
972
 
@@ -977,8 +977,8 @@ module.exports = function(mongoose, config) {
977
977
  Organization.methods.removePerson = function(personIdToRemove) {
978
978
 
979
979
  this.people = _.reject(this.people, function(existingPerson) {
980
- var id = utils.isValidObjectId(existingPerson.person) ? existingPerson.person : existingPerson.person._id;
981
- return id.toString() == personIdToRemove.toString();
980
+ var id = mongoose.Types.ObjectId.isValid(existingPerson.person) ? existingPerson.person : existingPerson.person._id;
981
+ return id.toString() === personIdToRemove.toString();
982
982
  });
983
983
 
984
984
  };
@@ -1240,7 +1240,7 @@ module.exports = function(mongoose, config) {
1240
1240
  if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
1241
1241
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
1242
1242
 
1243
- let username = utils.getUsernameFromUrl(value);
1243
+ let username = utilities.getUsernameFromUrl(value);
1244
1244
 
1245
1245
  if (!username) { return cb(null, []); }
1246
1246
 
@@ -1692,7 +1692,7 @@ module.exports = function(mongoose, config) {
1692
1692
  };
1693
1693
 
1694
1694
  // combine provided and default options
1695
- options = utils.setDefaults(options, defaultOptions);
1695
+ options = _.defaults(options || {}, defaultOptions);
1696
1696
 
1697
1697
  // need to be admin or provide investor id
1698
1698
  if (!options.admin && !options.investor) return cb(null, []);
@@ -1782,7 +1782,7 @@ module.exports = function(mongoose, config) {
1782
1782
 
1783
1783
  data.domain = data.domain.toLowerCase();
1784
1784
 
1785
- var parsed = utils.getDomain(data.domain);
1785
+ var parsed = utilities.getDomain(data.domain);
1786
1786
  if (parsed) data.domain = parsed;
1787
1787
 
1788
1788
  var domainRegExp = options.fuzzy ? new RegExp(data.domain, 'i') : new RegExp('^' + data.domain + '$', 'i');
@@ -1941,7 +1941,7 @@ module.exports = function(mongoose, config) {
1941
1941
  if (obj.website) {
1942
1942
  obj.website = String(obj.website);
1943
1943
  obj.website = obj.website.replace('http://', '').replace('https://', '').replace(/\/+$/, '');
1944
- obj.website = utils.getDomain(obj.website);
1944
+ obj.website = utilities.getDomain(obj.website);
1945
1945
  }
1946
1946
 
1947
1947
  // Format website aliases
@@ -1949,7 +1949,7 @@ module.exports = function(mongoose, config) {
1949
1949
  obj.websiteAliases = _.map(obj.websiteAliases, function(alias) {
1950
1950
  alias = String(alias);
1951
1951
  alias = alias.replace('http://', '').replace('https://', '').replace(/\/+$/, '');
1952
- return utils.getDomain(alias);
1952
+ return utilities.getDomain(alias);
1953
1953
  });
1954
1954
  }
1955
1955
 
package/lib/Person.js CHANGED
@@ -9,7 +9,7 @@ module.exports = function(mongoose, config) {
9
9
  Note = mongoose.model('Note'),
10
10
  Flag = mongoose.model('Flag'),
11
11
  helpers = require('../helpers'),
12
- utils = require('@dhyasama/ffvc-utilities'),
12
+ utilities = require('@dhyasama/totem-utilities'),
13
13
  async = require('async'),
14
14
  _ = require('underscore'),
15
15
  PhoneNumber = require( 'awesome-phonenumber'),
@@ -240,21 +240,21 @@ module.exports = function(mongoose, config) {
240
240
  switch(chairObj.num) {
241
241
  case 'chair1':
242
242
  this.chairs.first = _.filter(this.chairs.first, function(chair) {
243
- var id = utils.isValidObjectId(chair.company.toString()) ? chair.company.toString() : chair.company.id.toString();
244
- return id != orgId;
243
+ var id = mongoose.Types.ObjectId.isValid(chair.company.toString()) ? chair.company.toString() : chair.company.id.toString();
244
+ return id !== orgId;
245
245
  });
246
246
  break;
247
247
 
248
248
  case 'chair2':
249
249
  field = 'chairs.second';
250
250
  this.chairs.second = _.filter(this.chairs.second, function(chair) {
251
- var id = utils.isValidObjectId(chair.company.toString()) ? chair.company.toString() : chair.company.id.toString();
252
- return chair.company.id != orgId;
251
+ var id = mongoose.Types.ObjectId.isValid(chair.company.toString()) ? chair.company.toString() : chair.company.id.toString();
252
+ return id !== orgId;
253
253
  });
254
254
  break;
255
255
  }
256
256
 
257
- if(chairObj.val && chairObj.val == "") {
257
+ if(chairObj.val && chairObj.val === '') {
258
258
  this.previous.push({
259
259
  field: field,
260
260
  value: {
@@ -352,7 +352,7 @@ module.exports = function(mongoose, config) {
352
352
 
353
353
  if (!value) { return cb(new Error('value must be provided'), null); }
354
354
 
355
- let username = utils.getUsernameFromUrl(value);
355
+ let username = utilities.getUsernameFromUrl(value);
356
356
 
357
357
  if (!username) { return cb(null, []); }
358
358
 
@@ -377,11 +377,14 @@ module.exports = function(mongoose, config) {
377
377
  if (!id) { return cb(new Error('id is required'), null); }
378
378
  if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
379
379
  if (!options) { return cb(new Error('options is required'), null); }
380
- if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
381
- if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
382
380
 
383
381
  options = helpers.getDefaultOptions(options);
384
382
 
383
+ if (!options.isWorkerProcess) {
384
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
385
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
386
+ }
387
+
385
388
  self
386
389
  .findById(id)
387
390
  .select('-previous')
@@ -906,7 +909,7 @@ module.exports = function(mongoose, config) {
906
909
  };
907
910
 
908
911
  // combine provided and default options
909
- options = utils.setDefaults(options, defaultOptions);
912
+ options = _.defaults(options || {}, defaultOptions);
910
913
 
911
914
  // need to be admin or provide investor id
912
915
  if (!options.admin && !options.investor) return cb(null, []);
package/lib/Round.js CHANGED
@@ -19,7 +19,6 @@
19
19
  module.exports = function(mongoose, config) {
20
20
 
21
21
  let Schema = mongoose.Schema;
22
- let utils = require('@dhyasama/ffvc-utilities');
23
22
  let async = require('async');
24
23
  let _ = require('underscore');
25
24
  let helpers = require('../helpers');
@@ -209,7 +208,7 @@ module.exports = function(mongoose, config) {
209
208
 
210
209
  _.each(rounds, function(r) {
211
210
  r.vehicles = _.filter(r.vehicles, function(v) {
212
- var fundid = utils.isValidObjectId(v.fund) ? v.fund : v.fund._id;
211
+ var fundid = mongoose.Types.ObjectId.isValid(v.fund) ? v.fund : v.fund._id;
213
212
  return fundIds.indexOf(fundid.toString()) >= 0;
214
213
  });
215
214
  });
@@ -242,7 +241,7 @@ module.exports = function(mongoose, config) {
242
241
  // sums the value (fair or realized) of all vehicles in the round
243
242
  var self = this;
244
243
  return _.reduce(self.vehicles, function(memo, vehicle) {
245
- if (self.roundName == 'Proceeds') return memo + vehicle.realized; // proceeds are realized and do not have a fair value
244
+ if (self.roundName === 'Proceeds') return memo + vehicle.realized; // proceeds are realized and do not have a fair value
246
245
  else return memo + vehicle.fairValue;
247
246
  }, 0);
248
247
  });
@@ -280,26 +279,26 @@ module.exports = function(mongoose, config) {
280
279
  if (!fund) throw new Error('Must supply fund to add');
281
280
 
282
281
  // Do our best to accept an object or an objectid
283
- if (!utils.isValidObjectId(investment)) {
282
+ if (!mongoose.Types.ObjectId.isValid(investment)) {
284
283
  investment = investment._id;
285
- if (!utils.isValidObjectId(investment)) throw new Error('Need a valid investment objectid!');
284
+ if (!mongoose.Types.ObjectId.isValid(investment)) throw new Error('Need a valid investment objectid!');
286
285
  }
287
286
 
288
287
  // Do our best to accept an object or an objectid
289
- if (!utils.isValidObjectId(fund)) {
288
+ if (!mongoose.Types.ObjectId.isValid(fund)) {
290
289
  fund = fund._id;
291
- if (!utils.isValidObjectId(fund)) throw new Error('Need a valid fund objectid!');
290
+ if (!mongoose.Types.ObjectId.isValid(fund)) throw new Error('Need a valid fund objectid!');
292
291
  }
293
292
 
294
293
  // Create or update
295
294
  var vehicle = self.addVehicle(fund, data);
296
- var fid = utils.isValidObjectId(vehicle.fund) ? vehicle.fund : vehicle.fund._id;
295
+ var fid = mongoose.Types.ObjectId.isValid(vehicle.fund) ? vehicle.fund : vehicle.fund._id;
297
296
 
298
297
  // The vehicle returned by addVehicle, appears to be a copy not a reference which is odd to me.
299
298
  // We need a reference to add the investment, so go get it.
300
299
  vehicle = _.find(self.vehicles, function(v) {
301
- var fundid = utils.isValidObjectId(v.fund) ? v.fund : v.fund._id;
302
- return fundid.toString() == fid.toString();
300
+ var fundid = mongoose.Types.ObjectId.isValid(v.fund) ? v.fund : v.fund._id;
301
+ return fundid.toString() === fid.toString();
303
302
  });
304
303
 
305
304
  // bail if not found
@@ -307,8 +306,8 @@ module.exports = function(mongoose, config) {
307
306
 
308
307
  // Check if investment is already added
309
308
  var match = _.find(vehicle.investments, function(i) {
310
- var id = utils.isValidObjectId(i) ? i : i._id;
311
- return id.toString() == investment.toString();
309
+ var id = mongoose.Types.ObjectId.isValid(i) ? i : i._id;
310
+ return id.toString() === investment.toString();
312
311
  });
313
312
 
314
313
  // If not, add it
@@ -326,16 +325,16 @@ module.exports = function(mongoose, config) {
326
325
  if (!person) throw new Error('Must supply person to add');
327
326
 
328
327
  // Do our best to accept an object or an objectid
329
- if (!utils.isValidObjectId(person)) {
328
+ if (!mongoose.Types.ObjectId.isValid(person)) {
330
329
  person = person._id;
331
- if (!utils.isValidObjectId(person)) throw new Error('Need a valid objectid!');
330
+ if (!mongoose.Types.ObjectId.isValid(person)) throw new Error('Need a valid objectid!');
332
331
  }
333
332
 
334
333
  // Check if person is already added
335
334
  var match = _.find(self.people, function(existingPerson) {
336
335
  var p = existingPerson.person || existingPerson;
337
- var id = utils.isValidObjectId(p) ? p : p._id;
338
- return id.toString() == person.toString();
336
+ var id = mongoose.Types.ObjectId.isValid(p) ? p : p._id;
337
+ return id.toString() === person.toString();
339
338
  });
340
339
 
341
340
  // If not, add it
@@ -353,14 +352,14 @@ module.exports = function(mongoose, config) {
353
352
  // Note investment data is not added here
354
353
  // Note data will overwrite values for an existing vehicle.
355
354
 
356
- var self = this;
355
+ const self = this;
357
356
 
358
- if (!fund) throw new Error('Must supply fund to add');
357
+ if (!fund) { throw new Error('Must supply fund to add'); }
359
358
 
360
359
  // Do our best to accept an object or an objectid
361
- if (!utils.isValidObjectId(fund)) {
360
+ if (!mongoose.Types.ObjectId.isValid(fund)) {
362
361
  fund = fund._id;
363
- if (!utils.isValidObjectId(fund)) throw new Error('Need a valid fund objectid!');
362
+ if (!mongoose.Types.ObjectId.isValid(fund)) throw new Error('Need a valid fund objectid!');
364
363
  }
365
364
 
366
365
  data = data || {};
@@ -369,9 +368,9 @@ module.exports = function(mongoose, config) {
369
368
  data.valuationDate = data.valuationDate || null;
370
369
 
371
370
  // Check if vehicle is already added
372
- var vehicle = _.find(self.vehicles, function(v) {
373
- var fundid = utils.isValidObjectId(v.fund) ? v.fund : v.fund._id;
374
- return fundid.toString() == fund;
371
+ let vehicle = _.find(self.vehicles, function(v) {
372
+ let fundid = mongoose.Types.ObjectId.isValid(v.fund) ? v.fund : v.fund._id;
373
+ return fundid.toString() === fund.toString();
375
374
  });
376
375
 
377
376
  // update data on existing vehicle
@@ -882,7 +881,7 @@ module.exports = function(mongoose, config) {
882
881
  }
883
882
 
884
883
  // escrow is also special, except the gains are unrealized
885
- else if (doc.roundName == 'Escrow') {
884
+ else if (doc.roundName === 'Escrow') {
886
885
  vehicle.unrealized = vehicle.fairValue - vehicle.cost;
887
886
  vehicle.realized = 0;
888
887
  }
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "8.0.3",
3
+ "version": "8.0.5",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
7
7
  "main": "index.js",
8
+ "engines": {
9
+ "node": ">=12.0.0"
10
+ },
8
11
  "scripts": {
9
- "test": "NODE_ENV=test node ./changeBSON && mocha -R spec -t 15000 --exit"
12
+ "test": "NODE_ENV=test mocha -R spec -t 15000 --exit"
10
13
  },
11
14
  "publishConfig": {
12
15
  "registry": "https://registry.npmjs.org/"
package/test/Round.js CHANGED
@@ -16,7 +16,6 @@ var
16
16
  var orgid = new mongoose.Types.ObjectId();
17
17
  var personid = new mongoose.Types.ObjectId();
18
18
  var fundid = new mongoose.Types.ObjectId();
19
- var investmentid = new mongoose.Types.ObjectId();
20
19
  var organization, organization2, fund, person, investment, investment2;
21
20
 
22
21
  describe('Rounds', function() {