Created
May 19, 2014 16:03
-
-
Save JogoShugh/b36cbdbebf6f3e64479d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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