@dhyasama/totem-models 6.13.0 → 6.14.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.
@@ -1830,7 +1830,7 @@ module.exports = function(mongoose, config) {
1830
1830
  Organization.statics.modify = function(filter, update, cb) {
1831
1831
 
1832
1832
  // VERY IMPORTANT NOTE
1833
- // findOneAndUpdate does not trigger pre-save hook so that code will not run here
1833
+ // findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
1834
1834
  // at this time, the only known and approved use of this method is for adding and removing roles in totem web
1835
1835
 
1836
1836
  if (!cb) throw new Error('cb is required');
@@ -1847,6 +1847,26 @@ module.exports = function(mongoose, config) {
1847
1847
 
1848
1848
  };
1849
1849
 
1850
+ Organization.statics.modifyById = function(id, update, cb) {
1851
+
1852
+ // VERY IMPORTANT NOTE
1853
+ // findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
1854
+ // at this time, the only known and approved use of this method is for the org edit form in totem web
1855
+
1856
+ if (!cb) throw new Error('cb is required');
1857
+ if (!id) { return cb(new Error('id is required'), null); }
1858
+ if (!update) { return cb(new Error('update is required'), null); }
1859
+
1860
+ var self = this;
1861
+
1862
+ // https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
1863
+ // options runValidators defaults false which is ok since we have upsert false
1864
+ // new returns the updated document
1865
+
1866
+ self.findByIdAndUpdate(id, update, { upsert: false, new: true }, cb);
1867
+
1868
+ };
1869
+
1850
1870
 
1851
1871
 
1852
1872
  ///////////////////////////////////////////////////////////////////////////////////////
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "6.13.0",
3
+ "version": "6.14.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",