You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2019/11/08 20:57:09 UTC

[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #3598: Removed restangular from UserService

mitchell852 commented on a change in pull request #3598: Removed restangular from UserService
URL: https://github.com/apache/trafficcontrol/pull/3598#discussion_r344363500
 
 

 ##########
 File path: traffic_portal/app/src/common/api/UserService.js
 ##########
 @@ -17,143 +17,152 @@
  * under the License.
  */
 
-var UserService = function(Restangular, $http, $location, $q, authService, httpService, locationUtils, userModel, messageModel, ENV) {
-
-    var service = this;
+var UserService = function($http, locationUtils, userModel, messageModel, ENV) {
 
     this.getCurrentUser = function() {
-        var deferred = $q.defer();
-
-        $http.get(ENV.api['root'] + "user/current")
-            .then(
-                function(result) {
-                    userModel.setUser(result.data.response);
-                    deferred.resolve(result.data.response);
-                },
-                function(fault) {
-                    deferred.reject(fault);
-                }
-            );
-
-        return deferred.promise;
+        return $http.get(ENV.api['root'] + "user/current").then(
+            function(result) {
+                userModel.setUser(result.data.response);
+                return result.data.response;
+            },
+            function(err) {
+                throw err;
+            }
+        );
     };
 
     this.resetPassword = function(email) {
-        return $http.post(ENV.api['root'] + "user/reset_password", { email: email })
-            .then(
-                function(result) {
-                    messageModel.setMessages(result.data.alerts, false);
-                },
-                function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
-                }
-            );
+        return $http.post(ENV.api['root'] + "user/reset_password", { email: email }).then(
+            function(result) {
+                messageModel.setMessages(result.data.alerts, false);
+                return result;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
+        );
     };
 
     this.getUsers = function(queryParams) {
-        return Restangular.all('users').getList(queryParams);
+        return $http.get(ENV.api['root'] + 'users', {params: queryParams}).then(
+            function (result) {
+                return result.data.response;
+            },
+            function (err) {
+                console.error(err);
+                throw err;
+            }
+        )
     };
 
     this.getUser = function(id) {
-        return Restangular.one("users", id).get();
+        return $http.get(ENV.api['root'] + 'users', {params: {id: id}}).then(
+            function (result) {
+                return result.data.response[0];
+            },
+            function (err) {
+                console.error(err);
+                throw err;
+            }
+        )
     };
 
     this.createUser = function(user) {
-        return Restangular.service('users').post(user)
-            .then(
-                function(result) {
-                    messageModel.setMessages([ { level: 'success', text: 'User created' } ], true);
-                    locationUtils.navigateToPath('/users');
-                },
-                function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
-                }
-            );
+        return $http.post(ENV.api['root'] + 'users', user).then(
+            function(result) {
+                messageModel.setMessages([ { level: 'success', text: 'User created' } ], true);
+                locationUtils.navigateToPath('/users');
+                return result;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
+        );
     };
 
     this.updateUser = function(user) {
-        return $http.put(ENV.api['root'] + "users/" + user.id, user)
-            .then(
-                function(result) {
-                    if (userModel.user.id == user.id) {
-                        // if you are updating the currently logged in user...
-                        userModel.setUser(user);
-                    }
-                    messageModel.setMessages(result.data.alerts, false);
-                },
-                function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
+        return $http.put(ENV.api['root'] + "users/" + user.id, user).then(
+            function(result) {
+                if (userModel.user.id === user.id) {
+                    // if you are updating the currently logged in user...
+                    userModel.setUser(user);
                 }
-            );
+                messageModel.setMessages(result.data.alerts, false);
+                return result;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
+        );
     };
 
     this.updateCurrentUser = function(user) {
-        return $http.post(ENV.api['root'] + "user/current/update", { user: user })
-            .then(
-                function() {
-                    userModel.setUser(user);
-                    messageModel.setMessages([ { level: 'success', text: 'Current user updated' } ], false);
-                },
-                function() {
-                    messageModel.setMessages([ { level: 'error', text: 'Current user updated failed' } ], false);
-                }
-            );
+        return $http.post(ENV.api['root'] + "user/current/update", { user: user }).then(
+            function(result) {
+                userModel.setUser(user);
+                messageModel.setMessages([ { level: 'success', text: 'Current user updated' } ], false);
+                return result;
+            },
+            function(err) {
+                messageModel.setMessages([ { level: 'error', text: 'Current user updated failed' } ], false);
+                throw err;
+            }
+        );
     };
 
     this.getUnassignedUserDeliveryServices = function(userId) {
 
 Review comment:
   can you delete these methods as they are not used anywhere:
   
   getUnassignedUserDeliveryServices
   deleteUserDeliveryService
   assignUserDeliveryServices

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services