all files / app/crud/ crudResource.service.js

100% Statements 9/9
100% Branches 0/0
100% Functions 4/4
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                            132×                             132×   38×     19×        
/**
 * @ngdoc service
 * @name app.crud.crudResource
 * @description
 * Make CRUD REST API requests
 *
 */
(function () {
  'use strict';
 
  angular
    .module('app.crud')
    .factory('crudResource', factory);
 
  /** @ngInject */
  function factory($resource, apiPath) {
 
    var service = {
      getPath: getPath,
      /**
       * @ngdoc function
       * @name getResource
       * @methodOf app.crud.crudResource
       * @description
       * Get a $resource for making a REST API request to a particular resource
       * @param {String} resourcePath
       * (e.g.; 'players')
       * @returns {Object} $resource
       */
      getResource: getResource
    };
 
    return service;
 
    function getPath(resourcePath) {
      return apiPath + resourcePath;
    }
 
    function getResource(resourcePath) {
      return $resource(getPath(resourcePath) + '/:id', null, {'update': {method: 'PUT'}});
    }
  }
})();