@dhyasama/totem-models 9.9.1 → 9.10.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/Fund.js +41 -0
- package/lib/LimitedPartner.js +24 -3
- package/lib/Organization.js +1 -0
- package/lib/Person.js +23 -1
- package/package.json +1 -1
package/lib/Fund.js
CHANGED
|
@@ -155,6 +155,47 @@ module.exports = function(mongoose, config) {
|
|
|
155
155
|
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
+
Fund.statics.modify = function(filter, update, cb) {
|
|
159
|
+
|
|
160
|
+
// VERY IMPORTANT NOTE
|
|
161
|
+
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
162
|
+
// at this time, the only known and approved use of this method is for adding and removing roles in totem web
|
|
163
|
+
|
|
164
|
+
if (!cb) throw new Error('cb is required');
|
|
165
|
+
if (!filter) { return cb(new Error('filter is required'), null); }
|
|
166
|
+
if (!update) { return cb(new Error('update is required'), null); }
|
|
167
|
+
|
|
168
|
+
var self = this;
|
|
169
|
+
|
|
170
|
+
// https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
171
|
+
// options runValidators defaults false which is ok since we have upsert false
|
|
172
|
+
// new returns the updated document
|
|
173
|
+
|
|
174
|
+
self.findOneAndUpdate(filter, update, { upsert: false, new: true }, cb);
|
|
175
|
+
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
Fund.statics.modifyById = function(id, update, cb) {
|
|
179
|
+
|
|
180
|
+
// VERY IMPORTANT NOTE
|
|
181
|
+
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
182
|
+
// at this time, the only known and approved use of this method is for the org edit form in totem web
|
|
183
|
+
|
|
184
|
+
if (!cb) throw new Error('cb is required');
|
|
185
|
+
if (!id) { return cb(new Error('id is required'), null); }
|
|
186
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
187
|
+
if (!update) { return cb(new Error('update is required'), null); }
|
|
188
|
+
|
|
189
|
+
var self = this;
|
|
190
|
+
|
|
191
|
+
// https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
192
|
+
// options runValidators defaults false which is ok since we have upsert false
|
|
193
|
+
// new returns the updated document
|
|
194
|
+
|
|
195
|
+
self.findByIdAndUpdate(id, update, { upsert: false, new: true }, cb);
|
|
196
|
+
|
|
197
|
+
};
|
|
198
|
+
|
|
158
199
|
Fund.set('usePushEach', true);
|
|
159
200
|
Fund.set('autoIndex', false);
|
|
160
201
|
Fund.set('usePushEach', true);
|
package/lib/LimitedPartner.js
CHANGED
|
@@ -637,17 +637,38 @@ module.exports = function(mongoose, config) {
|
|
|
637
637
|
|
|
638
638
|
};
|
|
639
639
|
|
|
640
|
+
LimitedPartner.statics.modify = function(filter, update, cb) {
|
|
641
|
+
|
|
642
|
+
// VERY IMPORTANT NOTE
|
|
643
|
+
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
644
|
+
// at this time, the only known and approved use of this method is for adding and removing roles in totem web
|
|
645
|
+
|
|
646
|
+
if (!cb) throw new Error('cb is required');
|
|
647
|
+
if (!filter) { return cb(new Error('filter is required'), null); }
|
|
648
|
+
if (!update) { return cb(new Error('update is required'), null); }
|
|
649
|
+
|
|
650
|
+
var self = this;
|
|
651
|
+
|
|
652
|
+
// https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
653
|
+
// options runValidators defaults false which is ok since we have upsert false
|
|
654
|
+
// new returns the updated document
|
|
655
|
+
|
|
656
|
+
self.findOneAndUpdate(filter, update, { upsert: false, new: true }, cb);
|
|
657
|
+
|
|
658
|
+
};
|
|
659
|
+
|
|
640
660
|
LimitedPartner.statics.modifyById = function(id, update, cb) {
|
|
641
661
|
|
|
642
662
|
// VERY IMPORTANT NOTE
|
|
643
663
|
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
664
|
+
// at this time, the only known and approved use of this method is for the org edit form in totem web
|
|
644
665
|
|
|
645
|
-
if (!cb)
|
|
666
|
+
if (!cb) throw new Error('cb is required');
|
|
646
667
|
if (!id) { return cb(new Error('id is required'), null); }
|
|
647
668
|
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
648
|
-
if (!update) { return cb(new Error('
|
|
669
|
+
if (!update) { return cb(new Error('update is required'), null); }
|
|
649
670
|
|
|
650
|
-
|
|
671
|
+
var self = this;
|
|
651
672
|
|
|
652
673
|
// https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
653
674
|
// options runValidators defaults false which is ok since we have upsert false
|
package/lib/Organization.js
CHANGED
|
@@ -1649,6 +1649,7 @@ module.exports = function(mongoose, config) {
|
|
|
1649
1649
|
|
|
1650
1650
|
if (!cb) throw new Error('cb is required');
|
|
1651
1651
|
if (!id) { return cb(new Error('id is required'), null); }
|
|
1652
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
1652
1653
|
if (!update) { return cb(new Error('update is required'), null); }
|
|
1653
1654
|
|
|
1654
1655
|
var self = this;
|
package/lib/Person.js
CHANGED
|
@@ -594,16 +594,38 @@ module.exports = function(mongoose, config) {
|
|
|
594
594
|
});
|
|
595
595
|
};
|
|
596
596
|
|
|
597
|
+
Person.statics.modify = function(filter, update, cb) {
|
|
598
|
+
|
|
599
|
+
// VERY IMPORTANT NOTE
|
|
600
|
+
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
601
|
+
// at this time, the only known and approved use of this method is for adding and removing roles in totem web
|
|
602
|
+
|
|
603
|
+
if (!cb) throw new Error('cb is required');
|
|
604
|
+
if (!filter) { return cb(new Error('filter is required'), null); }
|
|
605
|
+
if (!update) { return cb(new Error('update is required'), null); }
|
|
606
|
+
|
|
607
|
+
var self = this;
|
|
608
|
+
|
|
609
|
+
// https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
610
|
+
// options runValidators defaults false which is ok since we have upsert false
|
|
611
|
+
// new returns the updated document
|
|
612
|
+
|
|
613
|
+
self.findOneAndUpdate(filter, update, { upsert: false, new: true }, cb);
|
|
614
|
+
|
|
615
|
+
};
|
|
616
|
+
|
|
597
617
|
Person.statics.modifyById = function(id, update, cb) {
|
|
598
618
|
|
|
599
619
|
// VERY IMPORTANT NOTE
|
|
600
620
|
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
621
|
+
// at this time, the only known and approved use of this method is for the org edit form in totem web
|
|
601
622
|
|
|
602
623
|
if (!cb) throw new Error('cb is required');
|
|
603
624
|
if (!id) { return cb(new Error('id is required'), null); }
|
|
625
|
+
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
604
626
|
if (!update) { return cb(new Error('update is required'), null); }
|
|
605
627
|
|
|
606
|
-
|
|
628
|
+
var self = this;
|
|
607
629
|
|
|
608
630
|
// https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
609
631
|
// options runValidators defaults false which is ok since we have upsert false
|