Commit fb87f0cd5ce7ef88ca0c93388a6035bf4f3b0b4c

Authored by Eric
1 parent 62d9449970
Exists in master

request punto de venta

1 angular.module('focaConfiguracion', ['ngStorage']) 1 angular.module('focaConfiguracion', ['ngStorage'])
2 .run([ 2 .run([
3 '$localStorage', 3 '$localStorage',
4 'focaConfiguracionService', 4 'focaConfiguracionService',
5 '$cookies', 5 function($localStorage, focaConfiguracionService) {
6 function($localStorage, focaConfiguracionService, $cookies) {
7 if (!$localStorage.terminalKey) { 6 if (!$localStorage.terminalKey) {
8 focaConfiguracionService.getHashTerminal().then(function(res) { 7 focaConfiguracionService.getHashTerminal().then(function(res) {
9 8
10 $localStorage.terminalKey = res.data; 9 $localStorage.terminalKey = res.data;
11 10
12 }); 11 });
13 } 12 }
14 13
15 if (!$cookies.get('puntoVenta') && $localStorage.terminalKey) {
16 focaConfiguracionService.getPuntoVenta().then(function(res) {
17
18 $cookies.put('puntoVenta', res.data);
19 });
20 }
21
22 }]); 14 }]);
23 15
src/js/requestHeadersInterceptor.js
1 angular.module('focaConfiguracion') 1 angular.module('focaConfiguracion')
2 .factory("RequestHeadersInterceptor", [ 2 .factory("RequestHeadersInterceptor", [
3 '$localStorage', '$cookies', function($localStorage, $cookies) { 3 '$localStorage', '$cookies', '$injector',
4 function($localStorage, $cookies, $injector) {
5
6 function getPuntoVenta(config) {
7
8 var url = $injector.get('API_ENDPOINT').URL;
9
10 if (url) {
11
12 var $http = $injector.get('$http');
13 var $timeout = $injector.get('$timeout');
14 config.url = url + '/config/punto-venta';
15
16 $timeout(function() {
17 $http(config).then(function(res) {
18 $cookies.put('puntoVenta', res.data[0]);
19 });
20 });
21 }
22 }
23
4 var request = { 24 var request = {
5 request: function(config) { 25 request: function(config) {
6 26
7 var nombreUsuario = $cookies.get('nombreUsuario'); 27 var nombreUsuario = $cookies.get('nombreUsuario');
8 var puntoVenta = $cookies.get('puntoVenta'); 28 var puntoVenta = $cookies.get('puntoVenta');
9 29
30 if (!puntoVenta) {
31 getPuntoVenta(angular.copy(config));
32 }
33
34 config.headers["X-Punto-Venta"] = puntoVenta;
10 config.headers["X-Terminal-Key"] = $localStorage.terminalKey; 35 config.headers["X-Terminal-Key"] = $localStorage.terminalKey;
11 config.headers["X-Nombre-Usuario"] = nombreUsuario; 36 config.headers["X-Nombre-Usuario"] = nombreUsuario;
12 config.headers["X-Punto-Venta"] = puntoVenta;
13 return config; 37 return config;
14 } 38 }
15 } 39 }
16 40
17 return request; 41 return request;
18 } 42 }
19 ]); 43 ]);