-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subsidy client #181
Subsidy client #181
Changes from 4 commits
737f4b0
853920f
608e092
a5089d3
540ca5b
3f77b15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
angular.module('bhima.services') | ||
.service('SubsidiesService', SubsidiesService); | ||
|
||
SubsidiesService.$inject = ['$http', 'util']; | ||
|
||
function SubsidiesService($http, util) { | ||
var service = this; | ||
var baseUrl = '/subsidies/'; | ||
|
||
service.read = read; | ||
service.create = create; | ||
service.update = update; | ||
service.delete = del; | ||
|
||
/** | ||
* @desc Get an id (optionnal) and return back a list of subsidies or an subsidy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This are really great comments! One small thing: JavaScript doesn't have a type or object called Otherwise, this is excellent code documentation! |
||
* @param {Integer} id, the id of the subsidy (optionnal) | ||
* @return {object} a promise object, with the response.body inside. | ||
* @example | ||
* service.read() | ||
* .then(function (subsidies){ | ||
* your code here | ||
* }); | ||
**/ | ||
function read(id) { | ||
var url = baseUrl.concat(id || ''); | ||
return $http.get(url) | ||
.then(util.unwrapHttpResponse); | ||
} | ||
|
||
/** | ||
* @desc It create an subsidy | ||
* @param {object} subsidy, subsidy to create | ||
* @example | ||
* service.create(subsidy) | ||
* .then(function (res){ | ||
* your code here | ||
* }); | ||
**/ | ||
function create(subsidy) { | ||
return $http.post(baseUrl, subsidy) | ||
.then(util.unwrapHttpResponse); | ||
} | ||
|
||
/** | ||
* @desc It updates an subsidy | ||
* @param {Integer} id, subsidy id to update | ||
* @param {object} subsidy, subsidy to update | ||
* @example | ||
* service.update(id, subsidy) | ||
* .then(function (res){ | ||
* your code here | ||
* }); | ||
**/ | ||
function update(id, subsidy) { | ||
delete subsidy.id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are going to submit |
||
delete subsidy.account_number; | ||
delete subsidy.account_number; | ||
|
||
var subsidyClean = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice construction. |
||
label : subsidy.label, | ||
value : subsidy.value, | ||
account_id : subsidy.account_id, | ||
description : subsidy.description | ||
}; | ||
|
||
return $http.put(baseUrl.concat(id), subsidyClean) | ||
.then(util.unwrapHttpResponse); | ||
} | ||
|
||
/** | ||
* @desc It Delete a subsidy | ||
* @param {Integer} id, subsidy id to delete | ||
* @example | ||
* service.del(id) | ||
* .then(function (res){ | ||
* your code here | ||
* }); | ||
**/ | ||
|
||
function del(id) { | ||
return $http.delete(baseUrl + id) | ||
.then(util.unwrapHttpResponse); | ||
} | ||
|
||
return service; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better name would be
SubsidyService
.Subsidie
isn't a valid English spelling :).