1const plugin = function updatePreventor(schema, options) {
2
3 function preUpdate (next){
4 // const update = this.getUpdate()
5 const { _id } = this.getQuery();
6 this.findOne({_id: _id}, function(err, doc){
7 if(err) {
8 return next(new Error('This bannerset is set to be readonly'));
9 }
10 if(doc && doc.frozen) {
11 return next(new Error('This bannerset is set to be readonly'));
12 }
13 return next();
14 });
15 }
16
17 schema.pre('update', preUpdate);
18 schema.pre('findOneAndUpdate', preUpdate);
19}
20
21export default plugin;Created on 8/27/2018