Skip to content

Instantly share code, notes, and snippets.

@mfalade
Created November 9, 2016 11:16
Show Gist options
  • Save mfalade/d887d40401d06a8bddcb1c8be0386e2f to your computer and use it in GitHub Desktop.
Save mfalade/d887d40401d06a8bddcb1c8be0386e2f to your computer and use it in GitHub Desktop.
angular.module('cerqma.services')
.factory('Equipments', ['$http', '$rootScope', '$state',
'API_PREFIX',
function ($http, $rootScope, $q, $state, API_PREFIX) {
// Response Handler
function returnResponse(res) {
return res.data;
}
function all(filter) {
var queryParams = '?';
if (filter && filter.inspector_id) {
queryParams = queryParams + '&inspector_id=' + filter.inspector_id;
}
return $http
.get(API_PREFIX + '/equipments' + queryParams)
.then(returnResponse);
}
function findOne(equipmentId) {
return $http
.get(API_PREFIX + '/equipments/' + equipmentId)
.then(returnResponse);
}
function create(payload) {
return $http
.post(API_PREFIX + '/equipments', payload)
.then(returnResponse);
}
function update(payload) {
return $http
.put(API_PREFIX + '/equipments', payload)
.then(returnResponse);
}
function destroy(equipmentId) {
return $http
.delete(API_PREFIX + '/equipments/' + equipmentId)
.then(returnResponse);
}
return {
all: all,
findOne: findOne,
create: create,
update: update,
destroy: destroy
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment