@dhyasama/totem-models 12.16.0 → 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 +3 -3
- package/lib/LimitedPartner.js +1 -1
- package/lib/List.js +1 -1
- package/lib/Organization.js +3 -3
- package/lib/Person.js +2 -2
- package/lib/Round.js +10 -16
- package/package.json +1 -1
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 =
|
|
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 =
|
|
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 (
|
|
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/LimitedPartner.js
CHANGED
|
@@ -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 =
|
|
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 (
|
|
266
|
+
return ((item && item._id) ? item._id : item).toString();
|
|
267
267
|
});
|
|
268
268
|
};
|
|
269
269
|
|
package/lib/Organization.js
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 (
|
|
184
|
-
|
|
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 (
|
|
190
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 (
|
|
233
|
-
|
|
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 =
|
|
233
|
+
let fundid = (v.fund && v.fund._id) ? v.fund._id : v.fund;
|
|
240
234
|
return fundid.toString() === fund.toString();
|
|
241
235
|
});
|
|
242
236
|
|