requestHeadersInterceptor.js
1.39 KB
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
angular.module('focaConfiguracion')
.factory("RequestHeadersInterceptor", [
'$localStorage', '$cookies', '$injector',
function($localStorage, $cookies, $injector) {
function getPuntoVenta(config) {
var url = $injector.get('API_ENDPOINT').URL;
if (url) {
var $http = $injector.get('$http');
var $timeout = $injector.get('$timeout');
config.url = url + '/config/punto-venta';
$timeout(function() {
$http(config).then(function(res) {
$cookies.put('puntoVenta', res.data[0]);
});
});
}
}
var request = {
request: function(config) {
var nombreUsuario = $cookies.get('nombreUsuario');
var puntoVenta = $cookies.get('puntoVenta');
if (!puntoVenta) {
getPuntoVenta(angular.copy(config));
}
config.headers["X-Terminal-Key"] = $localStorage.terminalKey;
config.headers["X-Nombre-Usuario"] = nombreUsuario;
config.headers["X-Punto-Venta"] = puntoVenta;
return config;
}
}
return request;
}
]);