/** * Provides interface for unit apis. */ (function() { var restResource = function($resource) { return function() { arguments[2]["create"] = { method: "PUT" }; arguments[2]["update"] = { method: "POST" }; var res = $resource.apply(null, arguments); res.prototype.$save = function() { return this[this.id? "$update":"$create"].apply(this, arguments); }; return res; }; }; angular.module('Units', ['ngResource']) /* * Collection of unit apis. * * Methods: * get: Gets information for a unit by id * query: Get a list of all units * queryType: Get a list of all units of a type * delete: Deletes a unit with an id * create: Creates a unit * update: Updates a unit * normalize: Converts from the given unit amount to the primary unit * save: Creates a new unit or updates an existing unit */ .factory('Unit', ['$resource', function($resource) { var res = restResource($resource)("unit/:id", {id: "@id"}, { "queryType": { method: 'GET', isArray: true, url: "unit/type/:type" }, "primary": { method: 'GET', isArray: true, url: "unit/primary/:type" } }); res.prototype.normalize = function(amount) { return amount * this.conversion; }; return res; }]); })();