@dhyasama/totem-models 12.10.0 → 12.11.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/LimitedPartner.js +9 -6
- package/lib/Person.js +8 -4
- package/package.json +1 -1
- package/test/LimitedPartner.js +19 -0
- package/test/Person.js +17 -0
package/lib/LimitedPartner.js
CHANGED
|
@@ -213,23 +213,26 @@ module.exports = function(mongoose, config) {
|
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
LimitedPartner.virtual('email.primary').get(function () {
|
|
216
|
-
let
|
|
217
|
-
|
|
216
|
+
let emails = this && this.contact && this.contact.email ? this.contact.email : [];
|
|
217
|
+
let primary = _.find(emails, function(email) {
|
|
218
|
+
return email && email.primary;
|
|
218
219
|
});
|
|
219
220
|
return primary ? primary.email : '';
|
|
220
221
|
});
|
|
221
222
|
|
|
222
223
|
LimitedPartner.virtual('phone.primary').get(function () {
|
|
223
|
-
let
|
|
224
|
-
|
|
224
|
+
let phones = this && this.contact && this.contact.phone ? this.contact.phone : [];
|
|
225
|
+
let primary = _.find(phones, function(phone) {
|
|
226
|
+
return phone && phone.primary;
|
|
225
227
|
});
|
|
226
228
|
return primary ? primary.number : '';
|
|
227
229
|
});
|
|
228
230
|
|
|
229
231
|
LimitedPartner.virtual('address.primary').get(function () {
|
|
230
232
|
|
|
231
|
-
let
|
|
232
|
-
|
|
233
|
+
let addresses = this && this.contact && this.contact.address ? this.contact.address : [];
|
|
234
|
+
let primary = _.find(addresses, function(address) {
|
|
235
|
+
return address && address.primary;
|
|
233
236
|
});
|
|
234
237
|
|
|
235
238
|
if (!primary) {
|
package/lib/Person.js
CHANGED
|
@@ -166,17 +166,21 @@ module.exports = function(mongoose, config) {
|
|
|
166
166
|
// Absent that, use first email
|
|
167
167
|
// Absent that, return empty string
|
|
168
168
|
var self = this;
|
|
169
|
+
var emails = self && self.contact && self.contact.email ? self.contact.email : [];
|
|
169
170
|
var result;
|
|
170
|
-
var primary = _.find(
|
|
171
|
+
var primary = _.find(emails, function(email) {
|
|
172
|
+
return email && email.primary;
|
|
173
|
+
});
|
|
171
174
|
if (primary) result = primary.email;
|
|
172
|
-
else if (
|
|
175
|
+
else if (emails.length >= 1 && emails[0]) result = emails[0].email;
|
|
173
176
|
else result = '';
|
|
174
177
|
return result;
|
|
175
178
|
});
|
|
176
179
|
|
|
177
180
|
Person.virtual('phone.primary').get(function () {
|
|
178
|
-
var
|
|
179
|
-
|
|
181
|
+
var phones = this && this.contact && this.contact.phone ? this.contact.phone : [];
|
|
182
|
+
var primary = _.find(phones, function(phone) {
|
|
183
|
+
return phone && phone.primary;
|
|
180
184
|
});
|
|
181
185
|
return primary ? primary.number : '';
|
|
182
186
|
});
|
package/package.json
CHANGED
package/test/LimitedPartner.js
CHANGED
|
@@ -398,6 +398,25 @@ describe('Limited Partner', function() {
|
|
|
398
398
|
|
|
399
399
|
});
|
|
400
400
|
|
|
401
|
+
it('does not throw when contact is omitted from a lean lp projection', function(done) {
|
|
402
|
+
|
|
403
|
+
LimitedPartner.findById(lp.id)
|
|
404
|
+
.select('name')
|
|
405
|
+
.lean({ virtuals: true })
|
|
406
|
+
.then(function(result) {
|
|
407
|
+
should.exist(result);
|
|
408
|
+
should.exist(result.email);
|
|
409
|
+
should.exist(result.phone);
|
|
410
|
+
should.exist(result.address);
|
|
411
|
+
result.email.primary.should.equal('');
|
|
412
|
+
result.phone.primary.should.equal('');
|
|
413
|
+
result.address.primary.postalCode.should.equal('');
|
|
414
|
+
done();
|
|
415
|
+
})
|
|
416
|
+
.catch(done);
|
|
417
|
+
|
|
418
|
+
});
|
|
419
|
+
|
|
401
420
|
it('adds a flag', function(done) {
|
|
402
421
|
|
|
403
422
|
LimitedPartner.addFlag(lp.id, person._id, 'incorrect phone', organization._id, function(err, result) {
|
package/test/Person.js
CHANGED
|
@@ -718,6 +718,23 @@ describe('Person', function() {
|
|
|
718
718
|
|
|
719
719
|
});
|
|
720
720
|
|
|
721
|
+
it('does not throw when contact is omitted from a lean person projection', function(done) {
|
|
722
|
+
|
|
723
|
+
Person.findById(person.id)
|
|
724
|
+
.select('name')
|
|
725
|
+
.lean({ virtuals: true })
|
|
726
|
+
.then(function(result) {
|
|
727
|
+
should.exist(result);
|
|
728
|
+
should.exist(result.email);
|
|
729
|
+
should.exist(result.phone);
|
|
730
|
+
result.email.primary.should.equal('');
|
|
731
|
+
result.phone.primary.should.equal('');
|
|
732
|
+
done();
|
|
733
|
+
})
|
|
734
|
+
.catch(done);
|
|
735
|
+
|
|
736
|
+
});
|
|
737
|
+
|
|
721
738
|
it('gets sources', function(done) {
|
|
722
739
|
|
|
723
740
|
Person.getSources(person.id, { CUSTOMER_ID: org._id }, function(err, result) {
|