@dhyasama/totem-models 4.2.0 → 4.4.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/Organization.js +48 -1
- package/lib/Person.js +10 -0
- package/package.json +1 -1
- package/test/Organization.js +24 -0
- package/test/Person.js +11 -0
package/lib/Organization.js
CHANGED
|
@@ -775,6 +775,24 @@ module.exports = function(mongoose, config) {
|
|
|
775
775
|
|
|
776
776
|
};
|
|
777
777
|
|
|
778
|
+
Organization.statics.findByPersonRaw = function findByPersonRaw(personId, cb) {
|
|
779
|
+
|
|
780
|
+
// Given a person id, get all organizations with that person
|
|
781
|
+
// directly from mongo driver to avoid mongoose middlewares
|
|
782
|
+
|
|
783
|
+
var self = this;
|
|
784
|
+
|
|
785
|
+
self.collection.find({ $or:
|
|
786
|
+
[
|
|
787
|
+
{ 'people.person': personId },
|
|
788
|
+
{ 'chairs.first': personId },
|
|
789
|
+
{ 'chairs.second': personId }
|
|
790
|
+
],
|
|
791
|
+
'deleted': { $ne: true }
|
|
792
|
+
}).toArray(cb);
|
|
793
|
+
|
|
794
|
+
};
|
|
795
|
+
|
|
778
796
|
Organization.statics.findBySlug = function findBySlug(slug, cb) {
|
|
779
797
|
this.findOne({ slug: slug, 'deleted': {$ne: true} }).exec(cb);
|
|
780
798
|
};
|
|
@@ -894,6 +912,35 @@ module.exports = function(mongoose, config) {
|
|
|
894
912
|
|
|
895
913
|
};
|
|
896
914
|
|
|
915
|
+
Organization.statics.getByIdRaw = function getByIdRaw(id, options, cb) {
|
|
916
|
+
|
|
917
|
+
// directly from mongo driver to avoid mongoose middlewares
|
|
918
|
+
|
|
919
|
+
var self = this;
|
|
920
|
+
|
|
921
|
+
//self.collection.findOne({ "_id": id }, cb);
|
|
922
|
+
|
|
923
|
+
self.collection.findOne({ "_id": id }, function(err, result) {
|
|
924
|
+
|
|
925
|
+
if (err) return cb(err, null);
|
|
926
|
+
else if (!result) return cb(null, null);
|
|
927
|
+
else if (result.people.length == 0) return cb(null, result);
|
|
928
|
+
|
|
929
|
+
// hydrate so we can use the populate method to get people
|
|
930
|
+
// note the hydrated version is not returned
|
|
931
|
+
var hydrated = self.hydrate(result);
|
|
932
|
+
hydrated.populate({
|
|
933
|
+
path: 'people.person',
|
|
934
|
+
select: 'name avatarUrl title contact doNotDisplay'
|
|
935
|
+
}, function (err, populated) {
|
|
936
|
+
result.people = populated.people;
|
|
937
|
+
return cb(null, result);
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
};
|
|
943
|
+
|
|
897
944
|
Organization.statics.getChairsOfPerson = function getChairsOfPerson(personId, cb) {
|
|
898
945
|
|
|
899
946
|
var self = this;
|
|
@@ -1311,6 +1358,7 @@ module.exports = function(mongoose, config) {
|
|
|
1311
1358
|
// Post-init: fired on every document when it's returned from a query
|
|
1312
1359
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
1313
1360
|
|
|
1361
|
+
|
|
1314
1362
|
Organization.pre('save', function(next) {
|
|
1315
1363
|
|
|
1316
1364
|
var self = this;
|
|
@@ -1483,7 +1531,6 @@ module.exports = function(mongoose, config) {
|
|
|
1483
1531
|
});
|
|
1484
1532
|
|
|
1485
1533
|
|
|
1486
|
-
|
|
1487
1534
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
1488
1535
|
// CONFIG
|
|
1489
1536
|
///////////////////////////////////////////////////////////////////////////////////////
|
package/lib/Person.js
CHANGED
|
@@ -719,6 +719,16 @@ module.exports = function(mongoose, config) {
|
|
|
719
719
|
|
|
720
720
|
};
|
|
721
721
|
|
|
722
|
+
Person.statics.getByIdRaw = function (id, cb) {
|
|
723
|
+
|
|
724
|
+
// directly from mongo driver to avoid mongoose middlewares
|
|
725
|
+
|
|
726
|
+
var self = this;
|
|
727
|
+
|
|
728
|
+
self.collection.findOne({ "_id": id }, cb);
|
|
729
|
+
|
|
730
|
+
};
|
|
731
|
+
|
|
722
732
|
Person.statics.getByIdNoPopulate = function (id, cb) {
|
|
723
733
|
|
|
724
734
|
this
|
package/package.json
CHANGED
package/test/Organization.js
CHANGED
|
@@ -486,6 +486,17 @@ describe('Organization', function() {
|
|
|
486
486
|
|
|
487
487
|
});
|
|
488
488
|
|
|
489
|
+
it('finds an org without mongoose sugar', function(done) {
|
|
490
|
+
|
|
491
|
+
Organization.getByIdRaw(org1._id, {}, function(err, result) {
|
|
492
|
+
should.not.exist(err);
|
|
493
|
+
should.exist(result);
|
|
494
|
+
(result instanceof Organization).should.equal(false);
|
|
495
|
+
done();
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
});
|
|
499
|
+
|
|
489
500
|
it('gets an org by id', function(done) {
|
|
490
501
|
|
|
491
502
|
Organization.getById(org1.id, { role: 'lp-full' }, function(err, org) {
|
|
@@ -558,6 +569,19 @@ describe('Organization', function() {
|
|
|
558
569
|
|
|
559
570
|
});
|
|
560
571
|
|
|
572
|
+
it('finds orgs by person without mongoose sugar', function(done) {
|
|
573
|
+
|
|
574
|
+
Organization.findByPersonRaw(person._id, function(err, result) {
|
|
575
|
+
should.not.exist(err);
|
|
576
|
+
should.exist(result);
|
|
577
|
+
result.length.should.equal(1);
|
|
578
|
+
result[0]._id.toString().should.equal(org1.id.toString());
|
|
579
|
+
(result[0] instanceof Organization).should.equal(false);
|
|
580
|
+
done();
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
});
|
|
584
|
+
|
|
561
585
|
it('finds boards of a person', function(done) {
|
|
562
586
|
|
|
563
587
|
Organization.getBoardsOfPerson(person2.id, function(err, result) {
|
package/test/Person.js
CHANGED
|
@@ -666,6 +666,17 @@ describe('Person', function() {
|
|
|
666
666
|
|
|
667
667
|
});
|
|
668
668
|
|
|
669
|
+
it('finds a person without mongoose sugar', function(done) {
|
|
670
|
+
|
|
671
|
+
Person.getByIdRaw(person5._id, function(err, person) {
|
|
672
|
+
should.not.exist(err);
|
|
673
|
+
should.exist(person);
|
|
674
|
+
(person instanceof Person).should.equal(false);
|
|
675
|
+
done();
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
});
|
|
679
|
+
|
|
669
680
|
it('finds the primary email for a person', function(done) {
|
|
670
681
|
|
|
671
682
|
Person.getById(person.id, function(err, person) {
|