taxtank-core 0.31.50 → 0.31.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1884,7 +1884,7 @@ class Collection {
1884
1884
  return this.items.reduce((prev, current) => (get(prev, path) > get(current, path) ? prev : current));
1885
1885
  }
1886
1886
  reduce(callback, init = 0) {
1887
- return round(this.items.reduce(callback, init), 2);
1887
+ return this.items.reduce(callback, init);
1888
1888
  }
1889
1889
  slice(from, to) {
1890
1890
  this.items.slice(from, to);
@@ -10659,6 +10659,10 @@ let RestService$1 = class RestService extends DataService {
10659
10659
  */
10660
10660
  fetch(path = this.apiUrl) {
10661
10661
  this.handleAccessError('get');
10662
+ if (!this.hasRoles()) {
10663
+ this.setCache([], true);
10664
+ return this.cacheSubject.asObservable();
10665
+ }
10662
10666
  // Set cache as empty collection to avoid multiple requests before cache filled
10663
10667
  this.setCache([]);
10664
10668
  return this.http.get(path)
@@ -10846,6 +10850,15 @@ let RestService$1 = class RestService extends DataService {
10846
10850
  });
10847
10851
  });
10848
10852
  }
10853
+ /**
10854
+ * check if user has subscription role to access api
10855
+ */
10856
+ hasRoles() {
10857
+ if (!this.roles.length) {
10858
+ return true;
10859
+ }
10860
+ return !!intersection(JSON.parse(localStorage.getItem('roles')), this.roles).length;
10861
+ }
10849
10862
  /**
10850
10863
  * // @TODO Alex remove
10851
10864
  * Method that call all listeners. Empty by default. Should be redefined by child services if required
@@ -15526,8 +15539,10 @@ class UserService extends RestService$1 {
15526
15539
  }
15527
15540
  fetch() {
15528
15541
  return super.fetch(`${this.apiUrl}/current`).pipe(map((users) => {
15542
+ // @TODO vik use separated service to handle global user storage
15529
15543
  localStorage.setItem('userId', this.getCacheFirst().id.toString());
15530
15544
  localStorage.setItem('financialYear', this.getCacheFirst().financialYear.toString());
15545
+ localStorage.setItem('roles', JSON.stringify(this.getCacheFirst().roles));
15531
15546
  this.mpService.identify(this.getCacheFirst().id);
15532
15547
  return users;
15533
15548
  }));