/**
* @ngdoc factory
* @name Requests
* @description Handles all HTTP Requests
* @requires $http
* @requires $rootScope
* @memberof ClientApp
* @return Requests
*/
app.factory('Requests', ['$http', '$rootScope', function(http, rootScope) {
var Requests = {};
Requests.data = [];
Requests.post_data = []
var base_url = "";
var url = null;
/**
* @function post
* @memberof Requests
* @description Handles POST Request
* @param resource
* @param object
* @param callBack
*/
Requests.post = function post(resource, object, callBack) {
var req = {
method: 'POST',
url: base_url + resource,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + rootScope.token
},
data: object
};
if (object) {
http(req)
.success(function(data) {
//this is the key
callBack(data);
})
.error(function(data, response) {
console.log(response + " " + data);
});;
}
}
/**
* @function get
* @description Handles GET Request
* @param resource
* @param callBack
* @memberof Requests
*/
Requests.get = function get(resource, callBack) {
var data;
var req = {
method: 'GET',
url: base_url + resource + "/user/" + rootScope.user._id,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + rootScope.token
}
};
http(req)
.success(function(data) {
//this is the key
callBack(data);
})
.error(function(data, response) {
console.log(response + " " + data);
});;
}
return Requests;
}])