-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_calls.js
114 lines (105 loc) · 2.83 KB
/
api_calls.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
angular
.module("ApiClient", ["OktaConfig"])
.factory("apiClient", function($q, $http, $timeout, OKTACONFIG) {
// Endpoint for resource server
// var BASE_URL = "http://localhost:8088";
// AWS Lambda Endpoint
var BASE_URL = OKTACONFIG.apiUrl;
var apiClient = {};
apiClient.getAppointments = function(token, filter) {
var deferred = $q.defer();
api_url = BASE_URL + "/appointments/"+filter;
$http({
method : "GET",
url : api_url,
headers : {
"Content-Type": "application/json",
Authorization : "Bearer " + token
}
})
.then(function(res){
if(res.data.Error){
deferred.reject(res.data.Error);
}
else {
deferred.resolve(angular.toJson(res.data.message));
}
}, function(err) {deferred.reject(err)});
return deferred.promise;
};
apiClient.confirmAppointment = function(appointment, token) {
appointment["status"] = "CONFIRMED"
var deferred = $q.defer();
api_url = BASE_URL + "/appointments/" + appointment["id"];
$http({
method: "PUT",
url : api_url,
data : appointment,
headers : {
"Content-Type" : "application/json",
Authorization : "Bearer " + token
}
})
.then(function(res) {
if(res.data.Error) {
deferred.reject(res.data.Error);
} else { deferred.resolve(angular.toJson(res));}
}, function(err) {deferred.reject(err)});
return deferred.promise;
}
apiClient.cancelAppointment = function(appointment, token) {
appointment["status"] = "DENIED"
var deferred = $q.defer();
api_url = BASE_URL + "/appointments/" + appointment["id"];
$http({
method: "PUT",
url : api_url,
data : appointment,
headers : {
"Content-Type" : "application/json",
Authorization : "Bearer " + token
}
})
.then(function(res) {
if(res.data.Error) {
deferred.reject(res.data.Error);
} else { deferred.resolve(angular.toJson(res));}
}, function(err) {deferred.reject(err)});
return deferred.promise;
}
apiClient.deleteAppointment = function(appointment, token) {
var deferred = $q.defer();
api_url = BASE_URL + "/appointments/" +appointment["id"];
$http({
method: "DELETE",
url : api_url,
data : appointment,
headers : {
"Content-Type" : "application/json",
Authorization : "Bearer " + token
}
})
.then(function(res) {
if (res.data.Error) {
deferred.reject(res.data.Error);
} else { deferred.resolve(res)}
}, function(err) {deferred.reject(err)});
return deferred.promise;
}
apiClient.populate = function(data) {
var deferred = $q.defer();
api_url = BASE_URL + "/populate";
$http({
method: "POST",
url : api_url,
headers : {"Content-Type" : "application/json"},
data: data
})
.then(function(res) {
if(res.data.Error) { deferred.reject(res.data.Error);}
else{ deferred.resolve(res); }
}, function(err) {deferred.reject(err)});
return deferred.promise;
}
return apiClient;
});