@dhyasama/totem-models 12.15.1 → 12.16.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/helpers.js CHANGED
@@ -37,7 +37,7 @@ const cleanPerson = module.exports.cleanPerson = function cleanPerson(doc, custo
37
37
 
38
38
  if (doc.sources) {
39
39
  doc.sources = _.reject(doc.sources, function(source) {
40
- let sourceCustomerId = mongoose.Types.ObjectId.isValid(source.customer) ? source.customer : source.customer._id;
40
+ let sourceCustomerId = (source.customer && source.customer._id) ? source.customer._id : source.customer;
41
41
  return sourceCustomerId.toString() !== customerId.toString();
42
42
  });
43
43
  }
@@ -59,7 +59,7 @@ const cleanRound = module.exports.cleanRound = function cleanRound(doc, fundIds,
59
59
 
60
60
  if (doc.vehicles) {
61
61
  doc.vehicles = _.reject(doc.vehicles, function(item) {
62
- var fundId = mongoose.Types.ObjectId.isValid(item.fund) ? item.fund : item.fund._id;
62
+ var fundId = (item.fund && item.fund._id) ? item.fund._id : item.fund;
63
63
  return !_.contains(fundIds, fundId.toString());
64
64
  });
65
65
  }
@@ -121,7 +121,7 @@ const getPeopleSources = module.exports.getPeopleSources = function getPeopleSou
121
121
  result = _.compact(result);
122
122
 
123
123
  if (result.length === 0) { return []; }
124
- if (mongoose.Types.ObjectId.isValid(result[0].person)) { return []; } // not populated
124
+ if (!result[0].person || !result[0].person._id) { return []; } // not populated
125
125
 
126
126
  result = _.uniq(result, function(item) {
127
127
  if (!item || !item.person) { return ''; }
package/lib/Financials.js CHANGED
@@ -36,8 +36,8 @@ module.exports = function(mongoose, config) {
36
36
  period: { type: String, enum: [null, 'month', 'quarter', 'half', 'year']},
37
37
  time: {
38
38
  hour: { type: Number },
39
- minute: { type: Number, default: 0 },
40
- second: { type: Number, default: 0 }
39
+ minute: { type: Number },
40
+ second: { type: Number }
41
41
  }
42
42
  },
43
43
  remind: {
@@ -45,16 +45,16 @@ module.exports = function(mongoose, config) {
45
45
  occurrences: { type: Number },
46
46
  time: {
47
47
  hour: { type: Number },
48
- minute: { type: Number, default: 0 },
49
- second: { type: Number, default: 0 }
48
+ minute: { type: Number },
49
+ second: { type: Number }
50
50
  }
51
51
  },
52
52
  due: {
53
53
  daysAfter: { type: Number },
54
54
  time: {
55
55
  hour: { type: Number },
56
- minute: { type: Number, default: 0 },
57
- second: { type: Number, default: 0 }
56
+ minute: { type: Number },
57
+ second: { type: Number }
58
58
  }
59
59
  },
60
60
  fiscal: {
@@ -311,7 +311,7 @@ module.exports = function(mongoose, config) {
311
311
  const self = this;
312
312
 
313
313
  let match = _.find(self.people, function(person) {
314
- let personId = mongoose.Types.ObjectId.isValid(person) ? person : person.id;
314
+ let personId = (person && person._id) ? person._id : person;
315
315
  return personId.toString() === idOfPersonToAdd.toString();
316
316
  });
317
317
 
package/lib/List.js CHANGED
@@ -263,7 +263,7 @@ module.exports = function(mongoose, config) {
263
263
 
264
264
  let dedupeArray = function dedupeArray(arr) {
265
265
  return _.uniq(arr, function(item) {
266
- return (mongoose.Types.ObjectId.isValid(item) ? item : item._id).toString();
266
+ return ((item && item._id) ? item._id : item).toString();
267
267
  });
268
268
  };
269
269
 
@@ -1003,7 +1003,7 @@ module.exports = function(mongoose, config) {
1003
1003
  // Check if person is already added
1004
1004
  var match = _.find(self.people, function(existingPerson) {
1005
1005
  if (existingPerson.person == null) return null;
1006
- var id = mongoose.Types.ObjectId.isValid(existingPerson.person) ? existingPerson.person : existingPerson.person.id;
1006
+ var id = (existingPerson.person && existingPerson.person._id) ? existingPerson.person._id : existingPerson.person;
1007
1007
  return id.toString() == personToAdd.person.toString();
1008
1008
  });
1009
1009
 
@@ -1032,7 +1032,7 @@ module.exports = function(mongoose, config) {
1032
1032
  var self = this;
1033
1033
 
1034
1034
  var match = _.find(self.related, function(org) {
1035
- var orgId = mongoose.Types.ObjectId.isValid(org) ? org : org.id;
1035
+ var orgId = (org && org._id) ? org._id : org;
1036
1036
  return orgId.toString() === id.toString();
1037
1037
  });
1038
1038
 
@@ -1043,7 +1043,7 @@ module.exports = function(mongoose, config) {
1043
1043
  Organization.methods.removePerson = function(personIdToRemove) {
1044
1044
 
1045
1045
  this.people = _.reject(this.people, function(existingPerson) {
1046
- var id = mongoose.Types.ObjectId.isValid(existingPerson.person) ? existingPerson.person : existingPerson.person._id;
1046
+ var id = (existingPerson.person && existingPerson.person._id) ? existingPerson.person._id : existingPerson.person;
1047
1047
  return id.toString() === personIdToRemove.toString();
1048
1048
  });
1049
1049
 
package/lib/Person.js CHANGED
@@ -231,7 +231,7 @@ module.exports = function(mongoose, config) {
231
231
  switch(chairObj.num) {
232
232
  case 'chair1':
233
233
  this.chairs.first = _.filter(this.chairs.first, function(chair) {
234
- var id = mongoose.Types.ObjectId.isValid(chair.company.toString()) ? chair.company.toString() : chair.company.id.toString();
234
+ var id = (chair.company && chair.company._id) ? chair.company._id.toString() : chair.company.toString();
235
235
  return id !== orgId;
236
236
  });
237
237
  break;
@@ -239,7 +239,7 @@ module.exports = function(mongoose, config) {
239
239
  case 'chair2':
240
240
  field = 'chairs.second';
241
241
  this.chairs.second = _.filter(this.chairs.second, function(chair) {
242
- var id = mongoose.Types.ObjectId.isValid(chair.company.toString()) ? chair.company.toString() : chair.company.id.toString();
242
+ var id = (chair.company && chair.company._id) ? chair.company._id.toString() : chair.company.toString();
243
243
  return id !== orgId;
244
244
  });
245
245
  break;
package/lib/Round.js CHANGED
@@ -180,25 +180,21 @@ module.exports = function(mongoose, config) {
180
180
  if (!fund) throw new Error('Must supply fund to add');
181
181
 
182
182
  // Do our best to accept an object or an objectid
183
- if (!mongoose.Types.ObjectId.isValid(investment)) {
184
- investment = investment._id;
185
- if (!mongoose.Types.ObjectId.isValid(investment)) throw new Error('Need a valid investment objectid!');
186
- }
183
+ if (investment && investment._id) { investment = investment._id; }
184
+ if (!mongoose.Types.ObjectId.isValid(investment)) throw new Error('Need a valid investment objectid!');
187
185
 
188
186
  // Do our best to accept an object or an objectid
189
- if (!mongoose.Types.ObjectId.isValid(fund)) {
190
- fund = fund._id;
191
- if (!mongoose.Types.ObjectId.isValid(fund)) throw new Error('Need a valid fund objectid!');
192
- }
187
+ if (fund && fund._id) { fund = fund._id; }
188
+ if (!mongoose.Types.ObjectId.isValid(fund)) throw new Error('Need a valid fund objectid!');
193
189
 
194
190
  // Create or update
195
191
  var vehicle = self.addVehicle(fund);
196
- var fid = mongoose.Types.ObjectId.isValid(vehicle.fund) ? vehicle.fund : vehicle.fund._id;
192
+ var fid = (vehicle.fund && vehicle.fund._id) ? vehicle.fund._id : vehicle.fund;
197
193
 
198
194
  // The vehicle returned by addVehicle, appears to be a copy not a reference which is odd to me.
199
195
  // We need a reference to add the investment, so go get it.
200
196
  vehicle = _.find(self.vehicles, function(v) {
201
- var fundid = mongoose.Types.ObjectId.isValid(v.fund) ? v.fund : v.fund._id;
197
+ var fundid = (v.fund && v.fund._id) ? v.fund._id : v.fund;
202
198
  return fundid.toString() === fid.toString();
203
199
  });
204
200
 
@@ -207,7 +203,7 @@ module.exports = function(mongoose, config) {
207
203
 
208
204
  // Check if investment is already added
209
205
  var match = _.find(vehicle.investments, function(i) {
210
- var id = mongoose.Types.ObjectId.isValid(i) ? i : i._id;
206
+ var id = (i && i._id) ? i._id : i;
211
207
  return id.toString() === investment.toString();
212
208
  });
213
209
 
@@ -229,14 +225,12 @@ module.exports = function(mongoose, config) {
229
225
  if (!fund) { throw new Error('Must supply fund to add'); }
230
226
 
231
227
  // Do our best to accept an object or an objectid
232
- if (!mongoose.Types.ObjectId.isValid(fund)) {
233
- fund = fund._id;
234
- if (!mongoose.Types.ObjectId.isValid(fund)) throw new Error('Need a valid fund objectid!');
235
- }
228
+ if (fund && fund._id) { fund = fund._id; }
229
+ if (!mongoose.Types.ObjectId.isValid(fund)) throw new Error('Need a valid fund objectid!');
236
230
 
237
231
  // Check if vehicle is already added
238
232
  let vehicle = _.find(self.vehicles, function(v) {
239
- let fundid = mongoose.Types.ObjectId.isValid(v.fund) ? v.fund : v.fund._id;
233
+ let fundid = (v.fund && v.fund._id) ? v.fund._id : v.fund;
240
234
  return fundid.toString() === fund.toString();
241
235
  });
242
236
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "12.15.1",
3
+ "version": "12.16.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",