@dhyasama/totem-models 4.3.0 → 4.4.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/lib/Organization.js +53 -2
- package/lib/Person.js +10 -0
- package/package.json +2 -2
- package/test/Organization.js +24 -0
- package/test/Person.js +11 -0
package/lib/Organization.js
CHANGED
|
@@ -139,6 +139,10 @@ module.exports = function(mongoose, config) {
|
|
|
139
139
|
url: { type: String, unique: true, partialFilterExpression : { type :"string" }, trim: true }
|
|
140
140
|
},
|
|
141
141
|
|
|
142
|
+
carta: {
|
|
143
|
+
corporationid: { type: String, unique: true, partialFilterExpression : { type :"string" }, trim: true }
|
|
144
|
+
},
|
|
145
|
+
|
|
142
146
|
related: [{ type: Schema.ObjectId, ref: 'Organization' }],
|
|
143
147
|
|
|
144
148
|
// customer specific (customer id is stored on note)
|
|
@@ -174,7 +178,7 @@ module.exports = function(mongoose, config) {
|
|
|
174
178
|
}
|
|
175
179
|
},
|
|
176
180
|
|
|
177
|
-
|
|
181
|
+
carta: {
|
|
178
182
|
firmid: { type: String, unique: true, partialFilterExpression : { type :"string" }, trim: true }
|
|
179
183
|
},
|
|
180
184
|
|
|
@@ -775,6 +779,24 @@ module.exports = function(mongoose, config) {
|
|
|
775
779
|
|
|
776
780
|
};
|
|
777
781
|
|
|
782
|
+
Organization.statics.findByPersonRaw = function findByPersonRaw(personId, cb) {
|
|
783
|
+
|
|
784
|
+
// Given a person id, get all organizations with that person
|
|
785
|
+
// directly from mongo driver to avoid mongoose middlewares
|
|
786
|
+
|
|
787
|
+
var self = this;
|
|
788
|
+
|
|
789
|
+
self.collection.find({ $or:
|
|
790
|
+
[
|
|
791
|
+
{ 'people.person': personId },
|
|
792
|
+
{ 'chairs.first': personId },
|
|
793
|
+
{ 'chairs.second': personId }
|
|
794
|
+
],
|
|
795
|
+
'deleted': { $ne: true }
|
|
796
|
+
}).toArray(cb);
|
|
797
|
+
|
|
798
|
+
};
|
|
799
|
+
|
|
778
800
|
Organization.statics.findBySlug = function findBySlug(slug, cb) {
|
|
779
801
|
this.findOne({ slug: slug, 'deleted': {$ne: true} }).exec(cb);
|
|
780
802
|
};
|
|
@@ -894,6 +916,35 @@ module.exports = function(mongoose, config) {
|
|
|
894
916
|
|
|
895
917
|
};
|
|
896
918
|
|
|
919
|
+
Organization.statics.getByIdRaw = function getByIdRaw(id, options, cb) {
|
|
920
|
+
|
|
921
|
+
// directly from mongo driver to avoid mongoose middlewares
|
|
922
|
+
|
|
923
|
+
var self = this;
|
|
924
|
+
|
|
925
|
+
//self.collection.findOne({ "_id": id }, cb);
|
|
926
|
+
|
|
927
|
+
self.collection.findOne({ "_id": id }, function(err, result) {
|
|
928
|
+
|
|
929
|
+
if (err) return cb(err, null);
|
|
930
|
+
else if (!result) return cb(null, null);
|
|
931
|
+
else if (result.people.length == 0) return cb(null, result);
|
|
932
|
+
|
|
933
|
+
// hydrate so we can use the populate method to get people
|
|
934
|
+
// note the hydrated version is not returned
|
|
935
|
+
var hydrated = self.hydrate(result);
|
|
936
|
+
hydrated.populate({
|
|
937
|
+
path: 'people.person',
|
|
938
|
+
select: 'name avatarUrl title contact doNotDisplay'
|
|
939
|
+
}, function (err, populated) {
|
|
940
|
+
result.people = populated.people;
|
|
941
|
+
return cb(null, result);
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
};
|
|
947
|
+
|
|
897
948
|
Organization.statics.getChairsOfPerson = function getChairsOfPerson(personId, cb) {
|
|
898
949
|
|
|
899
950
|
var self = this;
|
|
@@ -1311,6 +1362,7 @@ module.exports = function(mongoose, config) {
|
|
|
1311
1362
|
// Post-init: fired on every document when it's returned from a query
|
|
1312
1363
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
1313
1364
|
|
|
1365
|
+
|
|
1314
1366
|
Organization.pre('save', function(next) {
|
|
1315
1367
|
|
|
1316
1368
|
var self = this;
|
|
@@ -1483,7 +1535,6 @@ module.exports = function(mongoose, config) {
|
|
|
1483
1535
|
});
|
|
1484
1536
|
|
|
1485
1537
|
|
|
1486
|
-
|
|
1487
1538
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
1488
1539
|
// CONFIG
|
|
1489
1540
|
///////////////////////////////////////////////////////////////////////////////////////
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhyasama/totem-models",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"author": "Jason Reynolds",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "Models for Totem platform",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"async": "^2.6.1",
|
|
20
20
|
"awesome-phonenumber": "^1.0.14",
|
|
21
21
|
"bcrypt": "^0.8.0",
|
|
22
|
-
"bluebird": "^3.5.
|
|
22
|
+
"bluebird": "^3.5.2",
|
|
23
23
|
"escape-string-regexp": "^1.0.5",
|
|
24
24
|
"moment": "^2.22.2",
|
|
25
25
|
"mongoose-deep-populate": "^3.0.0",
|
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) {
|