@dhyasama/totem-models 6.22.0 → 6.23.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/Person.js +43 -0
- package/package.json +1 -1
- package/test/Person.js +26 -0
package/lib/Person.js
CHANGED
|
@@ -757,6 +757,49 @@ module.exports = function(mongoose, config) {
|
|
|
757
757
|
|
|
758
758
|
};
|
|
759
759
|
|
|
760
|
+
Person.statics.getByIdAsGlobal = function getByIdAsGlobal(id, options, cb) {
|
|
761
|
+
|
|
762
|
+
var self = this;
|
|
763
|
+
|
|
764
|
+
// Save original id so we can put it back when we're done
|
|
765
|
+
var orginalCustomerId = config.CUSTOMER_ID;
|
|
766
|
+
|
|
767
|
+
// Switch to global
|
|
768
|
+
config.CUSTOMER_ID = "GLOBAL_PROCESS";
|
|
769
|
+
console.log('config.CUSTOMER_ID pre query', config.CUSTOMER_ID);
|
|
770
|
+
|
|
771
|
+
try {
|
|
772
|
+
|
|
773
|
+
self.findById(id, function(err, result) {
|
|
774
|
+
|
|
775
|
+
// Put original id back
|
|
776
|
+
config.CUSTOMER_ID = orginalCustomerId;
|
|
777
|
+
console.log('config.CUSTOMER_ID post query', config.CUSTOMER_ID);
|
|
778
|
+
|
|
779
|
+
if (err) { return cb(err, null); }
|
|
780
|
+
|
|
781
|
+
return cb(null, result);
|
|
782
|
+
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
}
|
|
787
|
+
catch(err) {
|
|
788
|
+
|
|
789
|
+
// Put original id back
|
|
790
|
+
config.CUSTOMER_ID = orginalCustomerId;
|
|
791
|
+
console.log('config.CUSTOMER_ID post query', config.CUSTOMER_ID);
|
|
792
|
+
|
|
793
|
+
console.log('ERROR WITH PERSON.GETBYIDGLOBAL');
|
|
794
|
+
console.log('config.CUSTOMER_ID', config.CUSTOMER_ID);
|
|
795
|
+
console.log(err);
|
|
796
|
+
|
|
797
|
+
return cb(err, null);
|
|
798
|
+
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
};
|
|
802
|
+
|
|
760
803
|
Person.statics.getByIdRaw = function (id, cb) {
|
|
761
804
|
|
|
762
805
|
// directly from mongo driver to avoid mongoose middlewares
|
package/package.json
CHANGED
package/test/Person.js
CHANGED
|
@@ -162,6 +162,21 @@ describe('Person', function() {
|
|
|
162
162
|
person5.name.first = 'Tim';
|
|
163
163
|
person5.name.last = 'Reynolds';
|
|
164
164
|
person5.slug = 'tim-reynolds';
|
|
165
|
+
person5.sources = [{
|
|
166
|
+
person: new mongoose.Types.ObjectId(),
|
|
167
|
+
customer: new mongoose.Types.ObjectId()
|
|
168
|
+
}];
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
// sources: [{
|
|
172
|
+
// _id: false,
|
|
173
|
+
// person: { type: Schema.ObjectId, ref: 'Person' },
|
|
174
|
+
// customer: { type: Schema.ObjectId, ref: 'Organization' },
|
|
175
|
+
// interactions: {
|
|
176
|
+
// calendar: { type: Number, required: false, default: 0 },
|
|
177
|
+
// email: { type: Number, required: false, default: 0 }
|
|
178
|
+
// }
|
|
179
|
+
// }],
|
|
165
180
|
|
|
166
181
|
Person.upsert(person2, 'test-user', function(err, person2) {
|
|
167
182
|
Person.upsert(person3, 'test-user', function(err, person3) {
|
|
@@ -845,6 +860,17 @@ describe('Person', function() {
|
|
|
845
860
|
|
|
846
861
|
});
|
|
847
862
|
|
|
863
|
+
it('finds a person as global', function (done) {
|
|
864
|
+
|
|
865
|
+
Person.getByIdAsGlobal(person5._id, {}, function (err, result) {
|
|
866
|
+
should.not.exist(err);
|
|
867
|
+
should.exist(result);
|
|
868
|
+
result.sources.length.should.equal(1);
|
|
869
|
+
done();
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
});
|
|
873
|
+
|
|
848
874
|
it('finds the primary email for a person', function(done) {
|
|
849
875
|
|
|
850
876
|
Person.getById(person.id, function(err, person) {
|