{"size": 1316, "ext": "js", "max_stars_repo_path": "modules/foods/client/services/foods.client.service.js", "max_stars_repo_name": "tinhnqjp/reporting", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modules/foods/client/services/foods.client.service.js", "max_issues_repo_name": "tinhnqjp/reporting", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modules/foods/client/services/foods.client.service.js", "max_forks_repo_name": "tinhnqjp/reporting", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.6896551724, "max_line_length": 75, "alphanum_fraction": 0.5782674772}
(function () {
  'use strict';

  angular
    .module('foods.admin.services')
    .factory('FoodsService', FoodsService)
    .factory('FoodsApi', FoodsApi);

  FoodsService.$inject = ['$resource'];

  function FoodsService($resource) {
    var Food = $resource('/api/foods/:foodId', { foodId: '@_id' }, {
      update: { method: 'PUT' }
    });

    angular.extend(Food.prototype, {
      createOrUpdate: function () {
        var food = this;
        return createOrUpdate(food);
      }
    });

    return Food;

    function createOrUpdate(food) {
      if (food._id) {
        return food.$update(onSuccess, onError);
      } else {
        return food.$save(onSuccess, onError);
      }

      // Handle successful response
      function onSuccess(food) {}

      // Handle error response
      function onError(errorResponse) {
        var error = errorResponse.data;
        handleError(error);
      }
    }
    function handleError(error) {
      return false;
    }
  }

  FoodsApi.$inject = ['$http'];
  function FoodsApi($http) {
    this.list = function (condition) {
      return $http.post('/api/foods/list', { condition: condition }, {});
    };
    this.export = function (condition) {
      return $http.post('/api/foods/export', { condition: condition }, {});
    };
    return this;
  }

}());
