Created
May 12, 2017 18:47
-
-
Save giancarlosisasi/6d09fd4b2a89ac164090e5b88cbfdce3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // GET USER DATA | |
| (function() { | |
| "use strict"; | |
| angular.module('app') | |
| .factory('GetUserService', GetUserService); | |
| GetUserService.$inject = ['$http', '$log', '$q', 'localStorageService']; | |
| function GetUserService($http, $log, $q, localStorageService) { | |
| return { | |
| getUser : getUser | |
| }; | |
| function getUser(id) { | |
| return $http.get('/api/users/show?user_id=' + id) | |
| .then(getUserCompleted) | |
| .catch(getUserFailed); | |
| function getUserCompleted(response) { | |
| return response.data | |
| } | |
| function getUserFailed(error) { | |
| $log.error('XHR Failed to get the user.' + error.data); | |
| return $q.reject(error); | |
| } | |
| } | |
| }; | |
| })(); | |
| // UPDATE USER DATA | |
| (function() { | |
| "user strict"; | |
| angular.module('app') | |
| .factory('UpdateUserService', UpdateUserService); | |
| UpdateUserService.$inject = ['$http', '$log', '$q', 'localStorageService']; | |
| function UpdateUserService($http, $log, $q, localStorageService) { | |
| return { | |
| updateUser : updateUser | |
| }; | |
| function updateUser(id, newName, newLastname) { | |
| return $http.put('/api/users/update?user_id=' + id, { user: { name: newName, lastname: newLastname } }) | |
| .then(updateUserCompleted) | |
| .catch(updateUserFailed); | |
| function updateUserCompleted(response) { | |
| return response.data | |
| } | |
| function updateUserFailed(error) { | |
| $log.error('XHR Failed for update the user.' + error.data); | |
| return $q.reject(error); | |
| } | |
| }; | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment