Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
Created May 19, 2014 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JogoShugh/b36cbdbebf6f3e64479d to your computer and use it in GitHub Desktop.
Save JogoShugh/b36cbdbebf6f3e64479d to your computer and use it in GitHub Desktop.
function mongoLabResourceFactory(resourceService, resourcePath, resourceName, apiKey) {
var resource = resourceService(resourcePath + '/' + resourceName + '/:id', {
apiKey: apiKey
}, {
update: {
method: 'PUT'
}
});
resource.prototype.update = function (cb) {
return resource.update({
id: this._id.$oid
},
angular.extend({}, this, {
_id: undefined
}), cb);
};
resource.prototype.updateSafe = function (patch, cb) {
resource.get({id:this._id.$oid}, function(obj) {
for(var prop in patch) {
obj[prop] = patch[prop];
}
obj.update(cb);
});
};
resource.prototype.destroy = function (cb) {
return resource.remove({
id: this._id.$oid
}, cb);
};
return resource;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment