-
Notifications
You must be signed in to change notification settings - Fork 4
/
UserService.js
80 lines (76 loc) · 1.64 KB
/
UserService.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
*
*/
'use strict';
app.factory('UserService',['$http','$q','$rootScope',function($http,$q,$rootScope){
console.log("UserService..")
var BASE_URL='http://localhost:2222/ColBackEnd'
return{
fetchAllUsers:function(){
return $http.get(BASE_URL+'/users')
.then(
function(response){
return response.data;
},
function(errResponse){
console.error('Error while fetching UserDetails');
return $q.reject(errResponse);
}
);
},
createUser:function(user){
return $http.post(BASE_URL+'/user',user)
.then(
function(response){
return response.data;
},
function(errResponse){
console.error('Error while creating User');
return $q.reject(errResponse);
}
);
},
updateUser:function(user,id){
return $http.put(BASE_URL+'/user/'+id,user)
.then(
function(response){
return response.data;
},
function(errResponse){
console.error('Error while updating User');
return $q.reject(errResponse);
}
);
},
deleteUser:function(id){
return $http.delete(BASE_URL+'/user/'+id)
.then(
function(response){
return response.data;
},
function(errResponse){
console.error('Error while deleting User');
return $q.reject(errResponse);
}
);
},
authenticate:function(user){
return $http.post(BASE_URL+'/user/authenticate/',user)
.then(
function(response){
if(response.data.errorMessage!="")
{
$rootScope.currentUser={
name:response.data.name,
id:response.data.id,
role:response.data.role
};
}
return response.data;
}
);
},
}
}
]
);