UNPKG

identity

Version:

Identity client

69 lines (49 loc) 1.52 kB
module.exports = { beforeFind: function(){ var self = this; return function(){ if(!this.context) return true; var callbacks = self.getTypeCallbacks(this.context, 'find'); if(callbacks.length === 0){ return false; } if(callbacks.indexOf(true) === -1){ for(var i = 0; i < callbacks.length; i++){ if(typeof callbacks[i] == 'function'){ callbacks[i].call(this); } } } return true; } }, afterFind: function(){ var self = this; return function(data){ if(!this.context) return true; if(this.getInternal('as_raw')) return true; if(this.getInternal('as_json')){ //as json var records = data.result; for(var i in records){ var dummy_record = this.new(); dummy_record.set(records[i]); records[i] = dummy_record.toJson(self.getAllowedAttributes(dummy_record, 'find'), records[i]); } }else{ //normal records //loop all records and set it's allowed attributes this.each(function(record){ record.allowed_attributes = self.getAllowedAttributes(record, 'find'); }); } return true; } }, afterSave: function(){ return function(){ if(this._allowed_attributes) this.allowed_attributes = this._allowed_attributes; return true; } } };