@dhyasama/totem-models 12.16.0 → 12.17.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
@@ -826,6 +826,12 @@ module.exports = function(mongoose, config) {
826
826
  const run = async () => {
827
827
  var now = new Date();
828
828
 
829
+ // Lean + projection re-applied here despite e513aab's broad lean removal.
830
+ // Eligibility is filtered at the mongo level on stored snapshot.status, and
831
+ // no caller reads pre('init') updateStatus output from this result:
832
+ // scheduleCompanyEmails re-fetches via findOne, summarizeFinancialsToSend
833
+ // reads only ObjectIds + snapshot.period/year. Hydrating the full doc
834
+ // (notably notifications.*.email bodies) was driving lambda OOMs.
829
835
  var query = this.find({
830
836
  'snapshots': {
831
837
  $elemMatch: {
@@ -835,7 +841,17 @@ module.exports = function(mongoose, config) {
835
841
  'status': { $nin: ['Pending', 'Completed', 'Archived'] }
836
842
  }
837
843
  }
838
- });
844
+ }).select({
845
+ customer: 1,
846
+ organization: 1,
847
+ 'snapshots._id': 1,
848
+ 'snapshots.uuid': 1,
849
+ 'snapshots.year': 1,
850
+ 'snapshots.period': 1,
851
+ 'snapshots.notifications.company.initial.sendTo': 1,
852
+ 'snapshots.notifications.company.initial.sendOn': 1,
853
+ 'snapshots.notifications.company.initial.sentOn': 1,
854
+ }).lean();
839
855
 
840
856
  const result = await query;
841
857
  var results = [];
@@ -881,6 +897,7 @@ module.exports = function(mongoose, config) {
881
897
  const run = async () => {
882
898
  var now = new Date();
883
899
 
900
+ // see lean+projection note on getCompanyInitialToSend
884
901
  var query = this.find({
885
902
  'snapshots': {
886
903
  $elemMatch: {
@@ -890,7 +907,17 @@ module.exports = function(mongoose, config) {
890
907
  'status': { $nin: ['Pending', 'Completed', 'Archived'] }
891
908
  }
892
909
  }
893
- });
910
+ }).select({
911
+ customer: 1,
912
+ organization: 1,
913
+ 'snapshots._id': 1,
914
+ 'snapshots.uuid': 1,
915
+ 'snapshots.year': 1,
916
+ 'snapshots.period': 1,
917
+ 'snapshots.notifications.company.reminders.sendTo': 1,
918
+ 'snapshots.notifications.company.reminders.sendOn': 1,
919
+ 'snapshots.notifications.company.reminders.sentOn': 1,
920
+ }).lean();
894
921
 
895
922
  const result = await query;
896
923
  var results = [];
@@ -940,6 +967,7 @@ module.exports = function(mongoose, config) {
940
967
  const run = async () => {
941
968
  var now = new Date();
942
969
 
970
+ // see lean+projection note on getCompanyInitialToSend
943
971
  var query = this.find({
944
972
  'snapshots': {
945
973
  $elemMatch: {
@@ -949,7 +977,17 @@ module.exports = function(mongoose, config) {
949
977
  'status': { $nin: ['Pending', 'Completed', 'Archived'] }
950
978
  }
951
979
  }
952
- });
980
+ }).select({
981
+ customer: 1,
982
+ organization: 1,
983
+ 'snapshots._id': 1,
984
+ 'snapshots.uuid': 1,
985
+ 'snapshots.year': 1,
986
+ 'snapshots.period': 1,
987
+ 'snapshots.notifications.company.rejections.sendTo': 1,
988
+ 'snapshots.notifications.company.rejections.sendOn': 1,
989
+ 'snapshots.notifications.company.rejections.sentOn': 1,
990
+ }).lean();
953
991
 
954
992
  const result = await query;
955
993
  var results = [];
@@ -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.16.0",
3
+ "version": "12.17.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",