Commit 1bf6403d2ad1740dea056469cee3bcd8058c4197

Authored by Eric Fernandez
1 parent bef6f00e59
Exists in master

nombre headers

1 angular.module('focaConfiguracion', ['ngStorage']) 1 angular.module('focaConfiguracion', ['ngStorage'])
2 .run(['$localStorage', 'focaConfiguracionService', function($localStorage, focaConfiguracionService) { 2 .run([
3 '$localStorage',
4 'focaConfiguracionService',
5 '$cookies',
6 function($localStorage, focaConfiguracionService, $cookies) {
3 if (!$localStorage.terminalKey) { 7 if (!$localStorage.terminalKey) {
4 focaConfiguracionService.getHashTerminal().then(function(res) { 8 focaConfiguracionService.getHashTerminal().then(function(res) {
9
5 $localStorage.terminalKey = res.data; 10 $localStorage.terminalKey = res.data;
11
6 }); 12 });
7 } 13 }
14
15 if(!$cookies.get('puntoVenta') && $localStorage.terminalKey) {
16 focaConfiguracionService.getPuntoVenta().then(function(res) {
17
18 $cookies.put('puntoVenta', res.data);
19 });
20 }
21
8 }]); 22 }]);
9 23
1 angular.module('focaConfiguracion') 1 angular.module('focaConfiguracion')
2 .config(['$httpProvider', function($httpProvider) { 2 .config(['$httpProvider', function($httpProvider) {
3 $httpProvider.interceptors.push('RequestHeadersInterceptor'); 3 $httpProvider.interceptors.push('RequestHeadersInterceptor');
4 }]);
4 }]);
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', function($localStorage, $cookies) {
4 var request = { 4 var request = {
5 request: function(config) { 5 request: function(config) {
6 6
7 var nombreUsuario = $cookies.get('nombreUsuario'); 7 var nombreUsuario = $cookies.get('nombreUsuario');
8 var puntoVenta = $cookies.get('puntoVenta');
8 9
9 config.headers["X-Terminal-Key"] = $localStorage.terminalKey; 10 config.headers["X-Terminal-Key"] = $localStorage.terminalKey;
10 config.headers["Nombre-Usuario"] = nombreUsuario; 11 config.headers["X-Nombre-Usuario"] = nombreUsuario;
12 config.headers["X-Punto-Venta"] = puntoVenta;
11 return config; 13 return config;
12 } 14 }
13 } 15 }
14 16
15 return request; 17 return request;
16 } 18 }
17 ]);
19 ]);
1 angular.module('focaConfiguracion') 1 angular.module('focaConfiguracion')
2 .factory("focaConfiguracionService", [ 2 .factory("focaConfiguracionService", [
3 '$http', 'API_ENDPOINT', 3 '$http', 'API_ENDPOINT',
4 function($http, API_ENDPOINT) { 4 function($http, API_ENDPOINT) {
5 return { 5 return {
6 getHashTerminal: function() { 6 getHashTerminal: function() {
7 return $http.get(API_ENDPOINT.ENDPOINT_BASE + '/terminal/obtener'); 7 return $http.get(API_ENDPOINT.ENDPOINT_BASE + '/terminal/obtener');
8 },
9 getPuntoVenta: function() {
10 return $http.get(API_ENDPOINT.URL + '/config/punto-venta');
8 } 11 }
9 } 12 }
10 } 13 }
11 ]); 14 ]);
12 15