Commit fb87f0cd5ce7ef88ca0c93388a6035bf4f3b0b4c

Authored by Eric
1 parent 62d9449970
Exists in master

request punto de venta

... ... @@ -2,8 +2,7 @@ angular.module('focaConfiguracion', ['ngStorage'])
2 2 .run([
3 3 '$localStorage',
4 4 'focaConfiguracionService',
5   - '$cookies',
6   - function($localStorage, focaConfiguracionService, $cookies) {
  5 + function($localStorage, focaConfiguracionService) {
7 6 if (!$localStorage.terminalKey) {
8 7 focaConfiguracionService.getHashTerminal().then(function(res) {
9 8  
... ... @@ -12,11 +11,4 @@ angular.module('focaConfiguracion', ['ngStorage'])
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 }]);
src/js/requestHeadersInterceptor.js
1 1 angular.module('focaConfiguracion')
2 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 24 var request = {
5 25 request: function(config) {
6 26  
7 27 var nombreUsuario = $cookies.get('nombreUsuario');
8 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 35 config.headers["X-Terminal-Key"] = $localStorage.terminalKey;
11 36 config.headers["X-Nombre-Usuario"] = nombreUsuario;
12   - config.headers["X-Punto-Venta"] = puntoVenta;
13 37 return config;
14 38 }
15 39 }