@esolve/ng-esolve-connect 0.15.2 → 0.16.2

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.
Files changed (179) hide show
  1. package/esm2020/lib/account/registration/esolve-registration-data.interface.mjs +1 -1
  2. package/esm2020/lib/manufacturers/esolve-manufacturer-image-size.type.mjs +2 -0
  3. package/esm2020/lib/manufacturers/esolve-manufacturer.model.mjs +30 -13
  4. package/esm2020/lib/manufacturers/esolve-manufacturers.service.mjs +2 -2
  5. package/esm2020/lib/manufacturers/index.mjs +7 -2
  6. package/esm2020/lib/media/esolve-media.service.mjs +3 -3
  7. package/esm2020/lib/news/esolve-news-article-options.interface.mjs +1 -1
  8. package/esm2020/lib/news/esolve-news-article-record.interface.mjs +1 -1
  9. package/esm2020/lib/news/esolve-news-article.model.mjs +66 -13
  10. package/esm2020/lib/news/esolve-news.service.mjs +56 -46
  11. package/esm2020/lib/news/index.mjs +1 -3
  12. package/esm2020/lib/ranges/esolve-range.model.mjs +35 -14
  13. package/esm2020/lib/ranges/esolve-ranges.service.mjs +2 -2
  14. package/esm2020/lib/shared/assets/esolve-asset-list.type.mjs +2 -0
  15. package/esm2020/lib/shared/assets/esolve-asset-options.interface.mjs +2 -0
  16. package/esm2020/lib/shared/assets/esolve-asset-record.interface.mjs +2 -0
  17. package/esm2020/lib/shared/assets/esolve-asset.model.mjs +77 -0
  18. package/esm2020/lib/shared/assets/esolve-assets.service.mjs +102 -0
  19. package/esm2020/lib/shared/assets/index.mjs +11 -2
  20. package/esm2020/lib/shared/sort/esolve-sort-order.type.mjs +2 -0
  21. package/esm2020/lib/shared/sort/esolve-sort.interface.mjs +2 -0
  22. package/esm2020/lib/shared/sort/index.mjs +5 -0
  23. package/esm2020/lib/stock/classes/esolve-additional-stock-image.model.mjs +21 -0
  24. package/esm2020/lib/stock/classes/esolve-colour.model.mjs +8 -0
  25. package/esm2020/lib/stock/classes/esolve-linked-stock-item.model.mjs +9 -0
  26. package/esm2020/lib/stock/classes/esolve-media-stock-item.model.mjs +7 -0
  27. package/esm2020/lib/stock/classes/esolve-recipe-stock-item.model.mjs +9 -0
  28. package/esm2020/lib/stock/classes/esolve-stock-badge.model.mjs +11 -0
  29. package/esm2020/lib/stock/classes/esolve-stock-group-item.model.mjs +7 -0
  30. package/esm2020/lib/stock/classes/esolve-stock-group.model.mjs +13 -0
  31. package/esm2020/lib/stock/classes/esolve-stock-image-collection.model.mjs +26 -0
  32. package/esm2020/lib/stock/classes/esolve-stock-image.model.mjs +45 -0
  33. package/esm2020/lib/stock/classes/esolve-stock-item-base.model.mjs +224 -0
  34. package/esm2020/lib/stock/classes/esolve-stock-item-list.model.mjs +11 -0
  35. package/esm2020/lib/stock/classes/esolve-stock-item.model.mjs +17 -0
  36. package/esm2020/lib/stock/classes/esolve-stock-lead-times.model.mjs +9 -0
  37. package/esm2020/lib/stock/classes/esolve-stock-price.model.mjs +43 -0
  38. package/esm2020/lib/stock/classes/index.mjs +17 -0
  39. package/esm2020/lib/stock/esolve-stock.service.mjs +40 -9
  40. package/esm2020/lib/stock/index.mjs +4 -35
  41. package/esm2020/lib/stock/interfaces/esolve-additional-stock-image-record.interface.mjs +2 -0
  42. package/esm2020/lib/stock/interfaces/esolve-colour-record.interface.mjs +2 -0
  43. package/esm2020/lib/stock/interfaces/esolve-linked-stock-record.interface.mjs +2 -0
  44. package/esm2020/lib/stock/interfaces/esolve-media-stock-item-options.interface.mjs +2 -0
  45. package/esm2020/lib/stock/interfaces/esolve-media-stock-item-record.interface.mjs +2 -0
  46. package/esm2020/lib/stock/interfaces/esolve-recipe-item-record.interface.mjs +2 -0
  47. package/esm2020/lib/stock/interfaces/esolve-recipe-stock-options.interface.mjs +2 -0
  48. package/esm2020/lib/stock/interfaces/esolve-stock-badge-record.interface.mjs +2 -0
  49. package/esm2020/lib/stock/interfaces/esolve-stock-base-record.interface.mjs +2 -0
  50. package/esm2020/lib/stock/interfaces/esolve-stock-group-item-record.interface.mjs +2 -0
  51. package/esm2020/lib/stock/interfaces/esolve-stock-image-collection-record.interface.mjs +3 -0
  52. package/esm2020/lib/stock/interfaces/esolve-stock-item-options.interface.mjs +2 -0
  53. package/esm2020/lib/stock/interfaces/esolve-stock-lead-times-record.interface.mjs +2 -0
  54. package/esm2020/lib/stock/interfaces/esolve-stock-linked-category-record.interface.mjs +2 -0
  55. package/esm2020/lib/stock/interfaces/esolve-stock-record.interface.mjs +2 -0
  56. package/esm2020/lib/stock/interfaces/index.mjs +17 -0
  57. package/esm2020/lib/stock/types/esolve-media-stock-item-list.type.mjs +2 -0
  58. package/esm2020/lib/stock/types/esolve-media-stock-sort-field.type.mjs +2 -0
  59. package/esm2020/lib/stock/types/esolve-stock-image-size.type.mjs +2 -0
  60. package/esm2020/lib/stock/types/esolve-stock-sort-field.type.mjs +2 -0
  61. package/esm2020/lib/stock/types/esolve-stock-unit-of-measure.type.mjs +2 -0
  62. package/esm2020/lib/stock/types/index.mjs +7 -0
  63. package/esm2020/lib/tags/esolve-tag-options.interface.mjs +2 -0
  64. package/esm2020/lib/tags/esolve-tag-phrase-match-mode.type.mjs +2 -0
  65. package/esm2020/lib/tags/esolve-tag-record.interface.mjs +1 -1
  66. package/esm2020/lib/tags/esolve-tag.model.mjs +32 -6
  67. package/esm2020/lib/tags/esolve-tags.service.mjs +76 -0
  68. package/esm2020/lib/tags/index.mjs +9 -2
  69. package/esm2020/lib/topics/esolve-topic.model.mjs +12 -6
  70. package/esm2020/lib/topics/esolve-topic.service.mjs +2 -2
  71. package/esm2020/public-api.mjs +2 -1
  72. package/fesm2015/esolve-ng-esolve-connect.mjs +1902 -1452
  73. package/fesm2015/esolve-ng-esolve-connect.mjs.map +1 -1
  74. package/fesm2020/esolve-ng-esolve-connect.mjs +1875 -1437
  75. package/fesm2020/esolve-ng-esolve-connect.mjs.map +1 -1
  76. package/lib/account/registration/esolve-registration-data.interface.d.ts +3 -0
  77. package/lib/manufacturers/esolve-manufacturer-image-size.type.d.ts +1 -0
  78. package/lib/manufacturers/esolve-manufacturer.model.d.ts +4 -3
  79. package/lib/manufacturers/index.d.ts +2 -1
  80. package/lib/news/esolve-news-article-options.interface.d.ts +1 -0
  81. package/lib/news/esolve-news-article-record.interface.d.ts +8 -4
  82. package/lib/news/esolve-news-article.model.d.ts +13 -2
  83. package/lib/news/esolve-news.service.d.ts +2 -1
  84. package/lib/news/index.d.ts +0 -2
  85. package/lib/ranges/esolve-range.model.d.ts +2 -2
  86. package/lib/shared/assets/esolve-asset-list.type.d.ts +3 -0
  87. package/lib/shared/assets/esolve-asset-options.interface.d.ts +15 -0
  88. package/lib/shared/assets/esolve-asset-record.interface.d.ts +27 -0
  89. package/lib/shared/assets/esolve-asset.model.d.ts +39 -0
  90. package/lib/shared/assets/esolve-assets.service.d.ts +19 -0
  91. package/lib/shared/assets/index.d.ts +6 -1
  92. package/lib/shared/sort/esolve-sort-order.type.d.ts +1 -0
  93. package/lib/shared/sort/esolve-sort.interface.d.ts +5 -0
  94. package/lib/shared/sort/index.d.ts +2 -0
  95. package/lib/stock/{esolve-additional-stock-image.model.d.ts → classes/esolve-additional-stock-image.model.d.ts} +1 -1
  96. package/lib/stock/{esolve-colour.model.d.ts → classes/esolve-colour.model.d.ts} +1 -1
  97. package/lib/stock/{esolve-linked-stock-item.model.d.ts → classes/esolve-linked-stock-item.model.d.ts} +2 -2
  98. package/lib/stock/{esolve-media-stock-item.model.d.ts → classes/esolve-media-stock-item.model.d.ts} +2 -2
  99. package/lib/stock/{esolve-recipe-stock-item.model.d.ts → classes/esolve-recipe-stock-item.model.d.ts} +2 -2
  100. package/lib/stock/{esolve-stock-badge.model.d.ts → classes/esolve-stock-badge.model.d.ts} +0 -0
  101. package/lib/stock/{esolve-stock-group-item.model.d.ts → classes/esolve-stock-group-item.model.d.ts} +2 -2
  102. package/lib/stock/{esolve-stock-group.model.d.ts → classes/esolve-stock-group.model.d.ts} +2 -2
  103. package/lib/stock/{esolve-stock-image-collection.model.d.ts → classes/esolve-stock-image-collection.model.d.ts} +1 -1
  104. package/lib/stock/{esolve-stock-image.model.d.ts → classes/esolve-stock-image.model.d.ts} +1 -1
  105. package/lib/stock/{esolve-stock-item-base.model.d.ts → classes/esolve-stock-item-base.model.d.ts} +29 -9
  106. package/lib/stock/{esolve-stock-item-list.model.d.ts → classes/esolve-stock-item-list.model.d.ts} +1 -1
  107. package/lib/stock/{esolve-stock-item.model.d.ts → classes/esolve-stock-item.model.d.ts} +2 -2
  108. package/lib/stock/{esolve-stock-lead-times.model.d.ts → classes/esolve-stock-lead-times.model.d.ts} +1 -1
  109. package/lib/stock/{esolve-stock-price.model.d.ts → classes/esolve-stock-price.model.d.ts} +0 -0
  110. package/lib/stock/classes/index.d.ts +15 -0
  111. package/lib/stock/esolve-stock.service.d.ts +4 -9
  112. package/lib/stock/index.d.ts +3 -31
  113. package/lib/stock/{esolve-additional-stock-image-record.interface.d.ts → interfaces/esolve-additional-stock-image-record.interface.d.ts} +0 -0
  114. package/lib/stock/{esolve-colour-record.interface.d.ts → interfaces/esolve-colour-record.interface.d.ts} +0 -0
  115. package/lib/stock/{esolve-linked-stock-record.interface.d.ts → interfaces/esolve-linked-stock-record.interface.d.ts} +1 -1
  116. package/lib/stock/{esolve-media-stock-item-options.interface.d.ts → interfaces/esolve-media-stock-item-options.interface.d.ts} +3 -0
  117. package/lib/stock/{esolve-media-stock-item-record.interface.d.ts → interfaces/esolve-media-stock-item-record.interface.d.ts} +1 -1
  118. package/lib/stock/{esolve-recipe-item-record.interface.d.ts → interfaces/esolve-recipe-item-record.interface.d.ts} +1 -1
  119. package/lib/stock/interfaces/esolve-recipe-stock-options.interface.d.ts +7 -0
  120. package/lib/stock/{esolve-stock-badge-record.interface.d.ts → interfaces/esolve-stock-badge-record.interface.d.ts} +0 -0
  121. package/lib/stock/{esolve-stock-base-record.interface.d.ts → interfaces/esolve-stock-base-record.interface.d.ts} +12 -6
  122. package/lib/stock/{esolve-stock-group-item-record.interface.d.ts → interfaces/esolve-stock-group-item-record.interface.d.ts} +1 -1
  123. package/lib/stock/{esolve-stock-image-collection-record.interface.d.ts → interfaces/esolve-stock-image-collection-record.interface.d.ts} +0 -0
  124. package/lib/stock/{esolve-stock-item-options.interface.d.ts → interfaces/esolve-stock-item-options.interface.d.ts} +3 -0
  125. package/lib/stock/{esolve-stock-lead-times-record.interface.d.ts → interfaces/esolve-stock-lead-times-record.interface.d.ts} +0 -0
  126. package/lib/stock/{esolve-stock-linked-category-record.interface.d.ts → interfaces/esolve-stock-linked-category-record.interface.d.ts} +0 -0
  127. package/lib/stock/{esolve-stock-record.interface.d.ts → interfaces/esolve-stock-record.interface.d.ts} +1 -1
  128. package/lib/stock/interfaces/index.d.ts +15 -0
  129. package/lib/stock/types/esolve-media-stock-item-list.type.d.ts +7 -0
  130. package/lib/stock/types/esolve-media-stock-sort-field.type.d.ts +2 -0
  131. package/lib/stock/{esolve-stock-image-size.type.d.ts → types/esolve-stock-image-size.type.d.ts} +0 -0
  132. package/lib/stock/types/esolve-stock-sort-field.type.d.ts +1 -0
  133. package/lib/stock/types/esolve-stock-unit-of-measure.type.d.ts +1 -0
  134. package/lib/stock/types/index.d.ts +5 -0
  135. package/lib/tags/esolve-tag-options.interface.d.ts +6 -0
  136. package/lib/tags/esolve-tag-phrase-match-mode.type.d.ts +1 -0
  137. package/lib/tags/esolve-tag-record.interface.d.ts +1 -0
  138. package/lib/tags/esolve-tag.model.d.ts +14 -3
  139. package/lib/tags/esolve-tags.service.d.ts +22 -0
  140. package/lib/tags/index.d.ts +4 -1
  141. package/lib/topics/esolve-topic.model.d.ts +1 -1
  142. package/package.json +1 -1
  143. package/public-api.d.ts +1 -0
  144. package/esm2020/lib/news/esolve-news-manufacturer-record.interface.mjs +0 -2
  145. package/esm2020/lib/news/esolve-news-range-record.interface.mjs +0 -2
  146. package/esm2020/lib/stock/esolve-additional-stock-image-record.interface.mjs +0 -2
  147. package/esm2020/lib/stock/esolve-additional-stock-image.model.mjs +0 -21
  148. package/esm2020/lib/stock/esolve-colour-record.interface.mjs +0 -2
  149. package/esm2020/lib/stock/esolve-colour.model.mjs +0 -8
  150. package/esm2020/lib/stock/esolve-linked-stock-item.model.mjs +0 -9
  151. package/esm2020/lib/stock/esolve-linked-stock-record.interface.mjs +0 -2
  152. package/esm2020/lib/stock/esolve-media-stock-item-list.type.mjs +0 -2
  153. package/esm2020/lib/stock/esolve-media-stock-item-options.interface.mjs +0 -2
  154. package/esm2020/lib/stock/esolve-media-stock-item-record.interface.mjs +0 -2
  155. package/esm2020/lib/stock/esolve-media-stock-item.model.mjs +0 -7
  156. package/esm2020/lib/stock/esolve-recipe-item-record.interface.mjs +0 -2
  157. package/esm2020/lib/stock/esolve-recipe-stock-item.model.mjs +0 -9
  158. package/esm2020/lib/stock/esolve-stock-badge-record.interface.mjs +0 -2
  159. package/esm2020/lib/stock/esolve-stock-badge.model.mjs +0 -11
  160. package/esm2020/lib/stock/esolve-stock-base-record.interface.mjs +0 -2
  161. package/esm2020/lib/stock/esolve-stock-group-item-record.interface.mjs +0 -2
  162. package/esm2020/lib/stock/esolve-stock-group-item.model.mjs +0 -7
  163. package/esm2020/lib/stock/esolve-stock-group.model.mjs +0 -13
  164. package/esm2020/lib/stock/esolve-stock-image-collection-record.interface.mjs +0 -3
  165. package/esm2020/lib/stock/esolve-stock-image-collection.model.mjs +0 -26
  166. package/esm2020/lib/stock/esolve-stock-image-size.type.mjs +0 -2
  167. package/esm2020/lib/stock/esolve-stock-image.model.mjs +0 -45
  168. package/esm2020/lib/stock/esolve-stock-item-base.model.mjs +0 -197
  169. package/esm2020/lib/stock/esolve-stock-item-list.model.mjs +0 -11
  170. package/esm2020/lib/stock/esolve-stock-item-options.interface.mjs +0 -2
  171. package/esm2020/lib/stock/esolve-stock-item.model.mjs +0 -17
  172. package/esm2020/lib/stock/esolve-stock-lead-times-record.interface.mjs +0 -2
  173. package/esm2020/lib/stock/esolve-stock-lead-times.model.mjs +0 -9
  174. package/esm2020/lib/stock/esolve-stock-linked-category-record.interface.mjs +0 -2
  175. package/esm2020/lib/stock/esolve-stock-price.model.mjs +0 -43
  176. package/esm2020/lib/stock/esolve-stock-record.interface.mjs +0 -2
  177. package/lib/news/esolve-news-manufacturer-record.interface.d.ts +0 -8
  178. package/lib/news/esolve-news-range-record.interface.d.ts +0 -9
  179. package/lib/stock/esolve-media-stock-item-list.type.d.ts +0 -7
@@ -7,7 +7,7 @@ import * as i1 from 'ngx-cookie-service';
7
7
  import { CookieService } from 'ngx-cookie-service';
8
8
  import { BehaviorSubject, throwError, of, iif } from 'rxjs';
9
9
  import * as i1$1 from '@angular/platform-browser';
10
- import { map, tap, catchError, switchMap } from 'rxjs/operators';
10
+ import { map, catchError, tap, switchMap } from 'rxjs/operators';
11
11
 
12
12
  const ESOLVE_CONNECT_CONFIG = new InjectionToken('esolve.connect.config');
13
13
 
@@ -468,6 +468,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
468
468
  }]
469
469
  }], ctorParameters: function () { return []; } });
470
470
 
471
+ // Types
472
+
471
473
  /**
472
474
  * Search Engine Optimization information.
473
475
  */
@@ -693,436 +695,525 @@ class EsolveLinkedAsset {
693
695
  }
694
696
  }
695
697
 
696
- class EsolveAuthService {
697
- constructor(config, http, session, errorHandler, cookieService) {
698
- this.config = config;
699
- this.http = http;
700
- this.session = session;
701
- this.errorHandler = errorHandler;
702
- this.cookieService = cookieService;
703
- }
704
- getAccessToken(email, password, anonymous = false) {
705
- let params = new HttpParams();
706
- if (anonymous) {
707
- params = params.set('anonymous', true);
698
+ class EsolveCategoryTreeItem {
699
+ constructor(type, esolve_id, parent_id, description, sef_description, short_description, sort_priority, active, display_only, image_name, seo_title, seo_keywords, seo_description, children) {
700
+ this.type = type;
701
+ this.esolve_id = esolve_id;
702
+ this.parent_id = parent_id;
703
+ this.description = description;
704
+ this.sef_description = sef_description;
705
+ this.short_description = short_description;
706
+ this.sort_priority = sort_priority;
707
+ this.active = active;
708
+ this.display_only = display_only;
709
+ this.image_name = image_name;
710
+ this.id = '';
711
+ this.image_path = '';
712
+ if (this.type === 'category') {
713
+ this.id = `<<CAT>>${this.esolve_id}`;
714
+ if (children != null) {
715
+ this.children = children;
716
+ }
717
+ this.image_path = '/images/categories/';
708
718
  }
709
- if (email !== '') {
710
- params = params.set('email', email);
719
+ else {
720
+ this.id = `<<SUB>>${this.esolve_id}`;
721
+ this.image_path = '/images/subcategories/';
711
722
  }
712
- if (password !== '') {
713
- params = params.set('password', password);
723
+ if (seo_title.trim() === '') {
724
+ seo_title = this.description;
714
725
  }
715
- return this.http
716
- .get(`${this.config.api_url}/get-access-token.php`, {
717
- params,
718
- headers: new HttpHeaders({
719
- 'Accept-Language': '*',
720
- }),
721
- })
722
- .pipe(tap((responseData) => {
723
- if ((responseData.type === 'error') ||
724
- (responseData.type === 'exception')) {
725
- throw responseData;
726
- }
727
- }), catchError(this.handleError), tap((responseData) => {
728
- this.handleAuthentication(responseData.additional_data);
729
- }));
726
+ this.seo_details = new EsolveSeoInfo(seo_title, seo_description, seo_keywords);
730
727
  }
731
- autoLogin() {
732
- this.session.restore(this.handleExpiration(), () => {
733
- this.getAccessToken('', '', true).toPromise().then(() => { }, (error) => {
734
- console.error(error);
735
- });
736
- });
728
+ get small_image_src() {
729
+ return this.getImagePath('small');
737
730
  }
738
- login(email, password) {
739
- const body = {
740
- login: {
741
- email,
742
- password
743
- }
744
- };
731
+ get thumbnail_image_src() {
732
+ return this.getImagePath('thumb');
733
+ }
734
+ get tiny_image_src() {
735
+ return this.getImagePath('tiny');
736
+ }
737
+ getImagePath(image_size) {
738
+ if (this.image_name !== '') {
739
+ return `${this.image_path}${image_size}/${this.image_name}`;
740
+ }
741
+ return '';
742
+ }
743
+ }
744
+
745
+ class EsolveCategoryTreeService {
746
+ constructor(config, http) {
747
+ this.config = config;
748
+ this.http = http;
749
+ }
750
+ /**
751
+ * Retrieves the category tree from eSolve instance and coverts it to the correct format.
752
+ */
753
+ getCategoryTree() {
745
754
  return this.http
746
- .post(`${this.config.api_url}/set-login.php`, body, {
747
- headers: {
748
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
749
- },
750
- responseType: 'json',
751
- observe: 'body'
752
- })
755
+ .get(`${this.config.api_url}/get-tree.php`)
753
756
  .pipe(map((response) => {
754
- if ((response.responses === undefined) ||
755
- (response.responses.length <= 0)) {
757
+ if (response.records === undefined) {
756
758
  throw response;
757
759
  }
758
- const login_response = response.responses[0];
759
- if ((login_response.status.state !== 'success') &&
760
- (login_response.status.state !== 'warning')) {
761
- throw login_response;
762
- }
763
- for (const response_log of login_response.log) {
764
- if ((response_log.type === 'success') &&
765
- (response_log.message_code === 'login_success')) {
766
- const session_data = login_response.session_data;
767
- const user_id = +login_response.esolve_id;
768
- const location_id = +session_data.location_id;
769
- this.session.handleUpdateSession({
770
- user_id: user_id,
771
- location_id: location_id
772
- });
773
- return user_id;
774
- }
775
- }
776
- throw login_response;
777
- }), catchError((errorRes) => {
778
- return this.errorHandler.handleHttpPostError('set-login', errorRes);
760
+ return this.processTree(response.records);
779
761
  }));
780
762
  }
781
- logout() {
782
- this.session.clearTimer();
783
- this.cookieService.delete('_ws_id');
784
- return this.getAccessToken('', '', true).toPromise();
785
- }
786
- checkAccessToken(session) {
787
- var _a;
788
- session = session || this.session.currentSession;
789
- const token = (_a = session === null || session === void 0 ? void 0 : session.key) !== null && _a !== void 0 ? _a : '';
790
- return this.http
791
- .get(`${this.config.api_url}/get-access-token.php`, {
792
- params: { key: token },
793
- headers: new HttpHeaders({
794
- 'Accept-Language': '*'
795
- }),
796
- })
797
- .pipe(map((responseData) => {
798
- if ((responseData.type === 'error') ||
799
- (responseData.type === 'exception') ||
800
- (!responseData.additional_data.key_okay)) {
801
- throw responseData;
763
+ /**
764
+ * Retrieve the details of a category tree item from the eSolve instance and
765
+ * converts it to the correct format.
766
+ *
767
+ * @param options Filter options
768
+ */
769
+ getCategoryTreeItem(options) {
770
+ let type;
771
+ let esolve_id;
772
+ let sef_description;
773
+ if (options.id) {
774
+ const categoryIdentifier = this.processID(options.id);
775
+ if (categoryIdentifier) {
776
+ type = categoryIdentifier.type;
777
+ esolve_id = categoryIdentifier.esolve_id;
802
778
  }
803
- const additional_data = responseData.additional_data;
804
- const result = {
805
- key: token,
806
- expires: additional_data.expires,
807
- expiry_time: additional_data.expiry_time,
808
- location_id: additional_data.location_id,
809
- user_id: additional_data.user_id,
810
- };
811
- return result;
812
- }))
813
- .toPromise();
814
- }
815
- // Handlers
816
- handleExpiration() {
817
- return (session) => {
818
- this.checkAccessToken(session).then((response) => {
819
- this.handleAuthentication(response);
820
- }, () => {
821
- this.logout();
822
- });
823
- };
824
- }
825
- handleAuthentication(result) {
826
- if (!result.key) {
827
- return;
828
- }
829
- this.session.handleSession(+result.user_id, +result.location_id, result.key, +result.expiry_time, +result.expires, this.handleExpiration());
830
- }
831
- handleError(errorRes) {
832
- const error = {
833
- message: 'An unknown error occurred',
834
- data: {},
835
- };
836
- if ((!errorRes.type) ||
837
- (!errorRes.service_type) ||
838
- (!errorRes.message)) {
839
- return throwError(error);
840
779
  }
841
- if (errorRes.message.trim() !== '') {
842
- error.message = errorRes.message;
780
+ else if (options.type) {
781
+ type = options.type;
782
+ if (options.esolve_id) {
783
+ esolve_id = options.esolve_id;
784
+ }
785
+ else if (options.sef_description) {
786
+ sef_description = options.sef_description;
787
+ }
843
788
  }
844
- if (errorRes.additional_data) {
845
- error.data = errorRes.additional_data;
789
+ if (type && (esolve_id || sef_description)) {
790
+ let params = new HttpParams();
791
+ params = params.set('type', type);
792
+ if (esolve_id) {
793
+ params = params.set('id', esolve_id);
794
+ }
795
+ if (sef_description) {
796
+ params = params.set('sef_description', sef_description);
797
+ }
798
+ return this.http
799
+ .get(`${this.config.api_url}/get-tree-item.php`, { params })
800
+ .pipe(map((response) => {
801
+ if ((response.records === undefined) ||
802
+ (response.records.length <= 0)) {
803
+ throw response;
804
+ }
805
+ return this.processTreeItem(response.records[0]);
806
+ }));
846
807
  }
847
- return throwError(error);
808
+ return throwError('Invalid options');
848
809
  }
849
- }
850
- EsolveAuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAuthService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }, { token: EsolveSessionService }, { token: EsolveErrorHandlerService }, { token: EsolveCookieService }], target: i0.ɵɵFactoryTarget.Injectable });
851
- EsolveAuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAuthService, providedIn: 'root' });
852
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAuthService, decorators: [{
853
- type: Injectable,
854
- args: [{
855
- providedIn: 'root',
856
- }]
857
- }], ctorParameters: function () {
858
- return [{ type: undefined, decorators: [{
859
- type: Inject,
860
- args: [ESOLVE_CONNECT_CONFIG]
861
- }] }, { type: i1$2.HttpClient }, { type: EsolveSessionService }, { type: EsolveErrorHandlerService }, { type: EsolveCookieService }];
862
- } });
863
-
864
- class EsolveAddress {
865
- constructor(id, recipient, address_type, pobox, place_name, street_number, street, suburb, city, province, country, postal_code, latitude, longitude) {
866
- this.id = id;
867
- this.recipient = recipient;
868
- this.address_type = address_type;
869
- this.pobox = pobox;
870
- this.place_name = place_name;
871
- this.street_number = street_number;
872
- this.street = street;
873
- this.suburb = suburb;
874
- this.city = city;
875
- this.province = province;
876
- this.country = country;
877
- this.postal_code = postal_code;
878
- this.latitude = latitude;
879
- this.longitude = longitude;
810
+ /**
811
+ * Processes the eSolve tree records and converts them into the correct format.
812
+ *
813
+ * @param tree_records Records to process
814
+ */
815
+ processTree(tree_records) {
816
+ const tree_items = [];
817
+ if (tree_records) {
818
+ for (const tree_record of tree_records) {
819
+ let esolve_id = '';
820
+ let parent_id = '';
821
+ let children = [];
822
+ if (tree_record.type === 'category') {
823
+ children = this.processTree(tree_record.children);
824
+ esolve_id = tree_record.menu_id;
825
+ parent_id = tree_record.owner_menu_id;
826
+ }
827
+ else {
828
+ esolve_id = tree_record.id;
829
+ parent_id = tree_record.menu_id;
830
+ }
831
+ tree_items.push(new EsolveCategoryTreeItem(tree_record.type, esolve_id, parent_id, tree_record.description, tree_record.sef_description, tree_record.seo_description, tree_record.sort_priority, tree_record.active, tree_record.display_only, tree_record.image, tree_record.seo_page_title, tree_record.seo_keywords, tree_record.short_description, children));
832
+ }
833
+ }
834
+ return tree_items;
880
835
  }
881
- }
882
-
883
- class EsolveAddressResult extends EsolveResponseResult {
884
- constructor(response) {
885
- super(response);
886
- this.id = response.esolve_id;
887
- this.address_validated = response.address_validated;
888
- this.geocode_status = response.geocode_status;
889
- this.geocode_result = response.geocode_result;
836
+ processTreeItem(record) {
837
+ return new EsolveCategoryTreeItem(record.type, record.id, record.parent_id, record.description, record.sef_description, record.short_description, record.sort_priority, record.active, record.display_only, record.image, record.seo_page_title, record.seo_keywords, record.seo_description);
890
838
  }
891
- }
892
-
893
- class EsolveUserAccount {
894
- constructor(esolve_id, email, registration_type, title, first_name, last_name, initials, gender, identification_number) {
895
- this.esolve_id = esolve_id;
896
- this.email = email;
897
- this.registration_type = registration_type;
898
- this.title = title;
899
- this.first_name = first_name;
900
- this.last_name = last_name;
901
- this.initials = initials;
902
- this.gender = gender;
903
- this.identification_number = identification_number;
839
+ processID(id) {
840
+ let type;
841
+ let esolve_id;
842
+ const type_code_regex = /^\<\<(CAT|SUB)\>\>/g;
843
+ const match_results = id.match(type_code_regex);
844
+ if (match_results) {
845
+ const type_code = match_results[0];
846
+ type = (type_code === '<<CAT>>' ? 'category' : 'subcategory');
847
+ esolve_id = id.replace(type_code_regex, '');
848
+ return {
849
+ type,
850
+ esolve_id
851
+ };
852
+ }
853
+ return null;
904
854
  }
905
- }
855
+ }
856
+ EsolveCategoryTreeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveCategoryTreeService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
857
+ EsolveCategoryTreeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveCategoryTreeService, providedIn: 'root' });
858
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveCategoryTreeService, decorators: [{
859
+ type: Injectable,
860
+ args: [{
861
+ providedIn: 'root',
862
+ }]
863
+ }], ctorParameters: function () {
864
+ return [{ type: undefined, decorators: [{
865
+ type: Inject,
866
+ args: [ESOLVE_CONNECT_CONFIG]
867
+ }] }, { type: i1$2.HttpClient }];
868
+ } });
906
869
 
907
- class EsolveUserAccountResult extends EsolveResponseResult {
908
- constructor(response) {
909
- super(response);
870
+ class EsolveManufacturer {
871
+ constructor(record) {
872
+ var _a, _b, _c, _d, _e, _f, _g;
910
873
  this.id = 0;
911
- this.id = +response.esolve_id;
874
+ this.manufacturer = '';
875
+ this.sef_manufacturer = '';
876
+ this.title = '';
877
+ this.article = '';
878
+ this.sort_priority = 0;
879
+ this.is_active = false;
880
+ this.featured = false;
881
+ this.image_name = '';
882
+ let seo_title = '';
883
+ let seo_keywords = '';
884
+ let seo_description = '';
885
+ if (record) {
886
+ this.id = +((_a = record.id) !== null && _a !== void 0 ? _a : 0);
887
+ this.manufacturer = (_b = record.manufacturer) !== null && _b !== void 0 ? _b : '';
888
+ this.sef_manufacturer = (_c = record.sef_manufacturer) !== null && _c !== void 0 ? _c : '';
889
+ this.title = (_d = record.title) !== null && _d !== void 0 ? _d : '';
890
+ this.article = (_e = record.article) !== null && _e !== void 0 ? _e : '';
891
+ this.sort_priority = +((_f = record.sort_priority) !== null && _f !== void 0 ? _f : 0);
892
+ this.image_name = (_g = record.image_name) !== null && _g !== void 0 ? _g : '';
893
+ if (record.is_active) {
894
+ this.is_active = !!+record.is_active;
895
+ }
896
+ if (record.featured) {
897
+ this.featured = !!+record.featured;
898
+ }
899
+ }
900
+ if (this.title.trim() === '') {
901
+ this.title = this.manufacturer;
902
+ }
903
+ if (seo_title.trim() === '') {
904
+ seo_title = this.title;
905
+ }
906
+ this.seo_details = new EsolveSeoInfo(seo_title, seo_description, seo_keywords);
912
907
  }
913
- }
914
-
915
- class EsolveUserAccountBusiness {
916
- constructor(name, vat_number, description, type) {
917
- this.name = name;
918
- this.vat_number = vat_number;
919
- this.description = description;
920
- this.type = type;
908
+ get original_image_src() {
909
+ return this.getImagePath('original');
921
910
  }
922
- }
923
-
924
- class EsolveUserAccountContact {
925
- constructor(tel_number, cell_number, fax_number) {
926
- this.tel_number = tel_number;
927
- this.cell_number = cell_number;
928
- this.fax_number = fax_number;
911
+ get small_image_src() {
912
+ return this.getImagePath('small');
929
913
  }
930
- }
931
-
932
- class EsolveTransactionAddress {
933
- constructor(recipient, address_type, address_description, street_number, street, suburb, city, province, country, postal_code, pobox) {
934
- this.recipient = recipient;
935
- this.address_type = address_type;
936
- this.address_description = address_description;
937
- this.street_number = street_number;
938
- this.street = street;
939
- this.suburb = suburb;
940
- this.city = city;
941
- this.province = province;
942
- this.country = country;
943
- this.postal_code = postal_code;
944
- this.pobox = pobox;
914
+ get thumbnail_image_src() {
915
+ return this.getImagePath('thumb');
945
916
  }
946
- }
947
-
948
- class EsolveTransactionClient {
949
- constructor(id, account, company_name, branch_code, email, first_name, last_name, contact_number) {
950
- this.id = id;
951
- this.account = account;
952
- this.company_name = company_name;
953
- this.branch_code = branch_code;
954
- this.email = email;
955
- this.first_name = first_name;
956
- this.last_name = last_name;
957
- this.contact_number = contact_number;
917
+ get tiny_image_src() {
918
+ return this.getImagePath('tiny');
958
919
  }
959
- }
960
-
961
- class EsolveTransactionItem {
962
- constructor(code, name, qty, discount, vat_rate, price, line_total) {
963
- this.code = code;
964
- this.name = name;
965
- this.qty = qty;
966
- this.discount = discount;
967
- this.vat_rate = vat_rate;
968
- this.price = price;
969
- this.line_total = line_total;
920
+ getImagePath(image_size) {
921
+ if (this.image_name !== '') {
922
+ return `/images/manufacturers/${image_size}/${this.image_name}`;
923
+ }
924
+ return '';
970
925
  }
971
926
  }
972
927
 
973
- class EsolveTransactionItemPrice {
974
- constructor(
975
- /**
976
- * Price without tax
977
- */
978
- price,
979
- /**
980
- * Price with tax
981
- */
982
- price_with_tax,
983
- /**
984
- * Price without tax and with discounts applied if applicable
985
- */
986
- price_discounted,
987
- /**
988
- * Price with tax and with discounts applied if applicable
989
- */
990
- price_with_tax_discounted) {
991
- this.price = price;
992
- this.price_with_tax = price_with_tax;
993
- this.price_discounted = price_discounted;
994
- this.price_with_tax_discounted = price_with_tax_discounted;
928
+ class EsolveManufacturersService {
929
+ constructor(config, http) {
930
+ this.config = config;
931
+ this.http = http;
995
932
  }
996
- }
997
-
998
- class EsolveLocationAddress {
999
- constructor(street, suburb, city, province, country, postal_code, latitude, longitude) {
1000
- this.street = street;
1001
- this.suburb = suburb;
1002
- this.city = city;
1003
- this.province = province;
1004
- this.country = country;
1005
- this.postal_code = postal_code;
1006
- this.latitude = latitude;
1007
- this.longitude = longitude;
933
+ getManufacturer(id) {
934
+ const params = new HttpParams({
935
+ fromObject: { manufacturers_id: id }
936
+ });
937
+ return this.getManufacturerSingle(params);
1008
938
  }
1009
- }
1010
-
1011
- class EsolveLocationContactInfo {
1012
- constructor(telnumber, cellnumber, email, fax) {
1013
- this.telnumber = telnumber;
1014
- this.cellnumber = cellnumber;
1015
- this.email = email;
1016
- this.fax = fax;
939
+ getManufacturerFromSEF(sef_manufacturer) {
940
+ const params = new HttpParams({
941
+ fromObject: { sef_manufacturer }
942
+ });
943
+ return this.getManufacturerSingle(params);
1017
944
  }
1018
- }
1019
-
1020
- class EsolveLocationPOBoxAddress {
1021
- constructor(pobox, city, postal_code) {
1022
- this.pobox = pobox;
1023
- this.city = city;
1024
- this.postal_code = postal_code;
945
+ getManufacturers(options) {
946
+ let params = new HttpParams();
947
+ if (options === null || options === void 0 ? void 0 : options.featured_only) {
948
+ params = params.set('featured_only', options.featured_only);
949
+ }
950
+ return this.getManufacturerRecords(params).pipe(map((records) => {
951
+ const manufacturers = [];
952
+ for (const record of records) {
953
+ manufacturers.push(this.processManufacturer(record));
954
+ }
955
+ return manufacturers;
956
+ }), catchError(() => {
957
+ return of([]);
958
+ }));
1025
959
  }
1026
- }
1027
-
1028
- class EsolveLocationTradingTimes {
1029
- constructor(monday, tuesday, wednesday, thursday, friday, saturday, sunday, public_holiday, trading_hours_additional_info = '') {
1030
- this.monday = monday;
1031
- this.tuesday = tuesday;
1032
- this.wednesday = wednesday;
1033
- this.thursday = thursday;
1034
- this.friday = friday;
1035
- this.saturday = saturday;
1036
- this.sunday = sunday;
1037
- this.public_holiday = public_holiday;
1038
- this.trading_hours_additional_info = trading_hours_additional_info;
960
+ getManufacturerSingle(params) {
961
+ return this.getManufacturerRecords(params).pipe(map((records) => {
962
+ const record = records[0];
963
+ return this.processManufacturer(record);
964
+ }));
1039
965
  }
1040
- }
1041
-
1042
- class EsolveLocationTradingDay {
1043
- constructor(open, close) {
1044
- this.open = open;
1045
- this.close = close;
966
+ getManufacturerRecords(params) {
967
+ return this.http
968
+ .get(`${this.config.api_url}/get-manufacturers.php`, { params })
969
+ .pipe(map((response) => {
970
+ if ((response.records === undefined) ||
971
+ (response.records.length <= 0)) {
972
+ throw response;
973
+ }
974
+ return response.records;
975
+ }));
1046
976
  }
1047
- }
977
+ processManufacturer(record) {
978
+ return new EsolveManufacturer(record);
979
+ }
980
+ }
981
+ EsolveManufacturersService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveManufacturersService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
982
+ EsolveManufacturersService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveManufacturersService, providedIn: 'root' });
983
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveManufacturersService, decorators: [{
984
+ type: Injectable,
985
+ args: [{
986
+ providedIn: 'root',
987
+ }]
988
+ }], ctorParameters: function () {
989
+ return [{ type: undefined, decorators: [{
990
+ type: Inject,
991
+ args: [ESOLVE_CONNECT_CONFIG]
992
+ }] }, { type: i1$2.HttpClient }];
993
+ } });
1048
994
 
1049
- class EsolveLocation {
995
+ // Types
996
+
997
+ class EsolveRange {
1050
998
  constructor(record) {
1051
- this.id = +record.id;
1052
- this.identifier = record.identifier;
1053
- this.description = record.description;
1054
- this.head_office = record.head_office;
1055
- this.erp_identifier = record.erp_identifier;
1056
- this.external_system_code = record.external_system_code;
1057
- this.default_location_for_payment_methods = record.default_location_for_payment_methods;
1058
- this.userid = +record.userid;
1059
- this.importance = +record.importance;
1060
- this.active = record.is_active;
1061
- this.website_url = record.website_url;
1062
- this.address = new EsolveLocationAddress(record.street, record.suburb, record.city, record.province, record.country, record.postal_code, +record.latitude, +record.longitude);
1063
- this.pobox_address = new EsolveLocationPOBoxAddress(record.pobox, record.pobox_city, record.pobox_postal_code);
1064
- const telnumbers = [];
1065
- if (record.branch_telnumber.length > 0) {
1066
- telnumbers.push(record.branch_telnumber);
999
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1000
+ this.id = 0;
1001
+ this.range = '';
1002
+ this.sef_range = '';
1003
+ this.manufacturers_id = 0;
1004
+ this.title = '';
1005
+ this.article = '';
1006
+ this.is_active = false;
1007
+ this.featured = false;
1008
+ this.sort_priority = 0;
1009
+ this.image_name = '';
1010
+ let seo_title = '';
1011
+ let seo_keywords = '';
1012
+ let seo_description = '';
1013
+ if (record) {
1014
+ this.id = +((_a = record.id) !== null && _a !== void 0 ? _a : 0);
1015
+ this.range = (_b = record.range) !== null && _b !== void 0 ? _b : '';
1016
+ this.sef_range = (_c = record.sef_range) !== null && _c !== void 0 ? _c : '';
1017
+ this.manufacturers_id = +((_d = record.manufacturers_id) !== null && _d !== void 0 ? _d : 0);
1018
+ this.title = (_e = record.title) !== null && _e !== void 0 ? _e : '';
1019
+ this.article = (_f = record.article) !== null && _f !== void 0 ? _f : '';
1020
+ this.sort_priority = +((_g = record.sort_priority) !== null && _g !== void 0 ? _g : 0);
1021
+ this.image_name = (_h = record.image_name) !== null && _h !== void 0 ? _h : '';
1022
+ if (record.is_active) {
1023
+ this.is_active = !!+record.is_active;
1024
+ }
1025
+ if (record.featured) {
1026
+ this.featured = !!+record.featured;
1027
+ }
1028
+ seo_title = (_j = record.seo_page_title) !== null && _j !== void 0 ? _j : '';
1029
+ seo_keywords = (_k = record.seo_keywords) !== null && _k !== void 0 ? _k : '';
1030
+ seo_description = (_l = record.seo_description) !== null && _l !== void 0 ? _l : '';
1067
1031
  }
1068
- if (record.branch_telnumber_2.length > 0) {
1069
- telnumbers.push(record.branch_telnumber_2);
1032
+ if (this.title.trim() === '') {
1033
+ this.title = this.range;
1070
1034
  }
1071
- if (record.branch_telnumber_3.length > 0) {
1072
- telnumbers.push(record.branch_telnumber_3);
1035
+ if (seo_title.trim() === '') {
1036
+ seo_title = this.title;
1073
1037
  }
1074
- this.contact_info = new EsolveLocationContactInfo(telnumbers, record.branch_cellnumber, record.branch_email, record.branch_fax);
1075
- const monday = new EsolveLocationTradingDay(record.monday_open_time, record.monday_close_time);
1076
- const tuesday = new EsolveLocationTradingDay(record.tuesday_open_time, record.tuesday_close_time);
1077
- const wednesday = new EsolveLocationTradingDay(record.wednesday_open_time, record.wednesday_close_time);
1078
- const thursday = new EsolveLocationTradingDay(record.thursday_open_time, record.thursday_close_time);
1079
- const friday = new EsolveLocationTradingDay(record.friday_open_time, record.friday_close_time);
1080
- const saturday = new EsolveLocationTradingDay(record.saturday_open_time, record.saturday_close_time);
1081
- const sunday = new EsolveLocationTradingDay(record.sunday_open_time, record.sunday_close_time);
1082
- const public_holiday = new EsolveLocationTradingDay(record.public_holiday_open_time, record.public_holiday_close_time);
1083
- this.trading_times = new EsolveLocationTradingTimes(monday, tuesday, wednesday, thursday, friday, saturday, sunday, public_holiday, record.trading_hours_additional_info);
1038
+ this.seo_details = new EsolveSeoInfo(seo_title, seo_description, seo_keywords);
1039
+ }
1040
+ get image_src() {
1041
+ return this.getImagePath();
1042
+ }
1043
+ getImagePath() {
1044
+ if (this.image_name !== '') {
1045
+ return `/images/ranges/${this.image_name}`;
1046
+ }
1047
+ return '';
1084
1048
  }
1085
1049
  }
1086
1050
 
1087
- class EsolveLocationsService {
1051
+ class EsolveRangesService {
1088
1052
  constructor(config, http) {
1089
1053
  this.config = config;
1090
1054
  this.http = http;
1091
1055
  }
1092
- /**
1093
- * Retrieves a list of stock locations
1094
- *
1095
- * @returns An `Observable` with an array of stock locations
1096
- */
1097
- getStockLocations() {
1056
+ getRange(id) {
1057
+ const params = new HttpParams({
1058
+ fromObject: { ranges_id: id }
1059
+ });
1060
+ return this.getRangeSingle(params);
1061
+ }
1062
+ getRangeFromSEF(sef_range) {
1063
+ const params = new HttpParams({
1064
+ fromObject: { sef_range }
1065
+ });
1066
+ return this.getRangeSingle(params);
1067
+ }
1068
+ getRanges(options) {
1069
+ let params = new HttpParams();
1070
+ if (options === null || options === void 0 ? void 0 : options.featured_only) {
1071
+ params = params.set('featured_only', options.featured_only);
1072
+ }
1073
+ if (options === null || options === void 0 ? void 0 : options.manufacturers_id) {
1074
+ params = params.set('manufacturers_id', options.manufacturers_id);
1075
+ }
1076
+ return this.getRangeRecords(params).pipe(map((records) => {
1077
+ const ranges = [];
1078
+ for (const record of records) {
1079
+ ranges.push(this.processRange(record));
1080
+ }
1081
+ return ranges;
1082
+ }), catchError(() => {
1083
+ return of([]);
1084
+ }));
1085
+ }
1086
+ getRangeSingle(params) {
1087
+ return this.getRangeRecords(params).pipe(map((records) => {
1088
+ const record = records[0];
1089
+ return this.processRange(record);
1090
+ }));
1091
+ }
1092
+ getRangeRecords(params) {
1098
1093
  return this.http
1099
- .get(`${this.config.api_url}/get-locations.php`)
1094
+ .get(`${this.config.api_url}/get-ranges.php`, { params })
1100
1095
  .pipe(map((response) => {
1101
- if (response.records === undefined) {
1096
+ if ((response.records === undefined) ||
1097
+ (response.records.length <= 0)) {
1102
1098
  throw response;
1103
1099
  }
1104
- return this.processStockLocations(response.records);
1100
+ return response.records;
1105
1101
  }));
1106
1102
  }
1103
+ processRange(record) {
1104
+ return new EsolveRange(record);
1105
+ }
1106
+ }
1107
+ EsolveRangesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveRangesService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1108
+ EsolveRangesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveRangesService, providedIn: 'root' });
1109
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveRangesService, decorators: [{
1110
+ type: Injectable,
1111
+ args: [{
1112
+ providedIn: 'root',
1113
+ }]
1114
+ }], ctorParameters: function () {
1115
+ return [{ type: undefined, decorators: [{
1116
+ type: Inject,
1117
+ args: [ESOLVE_CONNECT_CONFIG]
1118
+ }] }, { type: i1$2.HttpClient }];
1119
+ } });
1120
+
1121
+ class EsolveTag {
1122
+ constructor(record) {
1123
+ var _a, _b, _c, _d, _e;
1124
+ this.id = 0;
1125
+ this.phrase = '';
1126
+ this.weight = 0;
1127
+ this.description = '';
1128
+ this.image_name = '';
1129
+ if (record) {
1130
+ this.id = +((_a = record.id) !== null && _a !== void 0 ? _a : 0);
1131
+ this.phrase = (_b = record.tag_phrase) !== null && _b !== void 0 ? _b : '';
1132
+ this.weight = +((_c = record.tag_weight) !== null && _c !== void 0 ? _c : 0);
1133
+ this.description = (_d = record.description) !== null && _d !== void 0 ? _d : '';
1134
+ this.image_name = (_e = record.image_name) !== null && _e !== void 0 ? _e : '';
1135
+ }
1136
+ }
1107
1137
  /**
1108
- * Processes the eSolve stock location records.
1138
+ * @deprecated To be removed in the future. Use `EsolveTag.phrase` instead
1139
+ */
1140
+ get tag_phrase() {
1141
+ return this.phrase;
1142
+ }
1143
+ /**
1144
+ * @deprecated To be removed in the future. Use `EsolveTag.weight` instead
1145
+ */
1146
+ get tag_weight() {
1147
+ return this.weight;
1148
+ }
1149
+ getImagePath() {
1150
+ if (this.image_name !== '') {
1151
+ return `/images/tags/${this.image_name}`;
1152
+ }
1153
+ return '';
1154
+ }
1155
+ }
1156
+
1157
+ class EsolveTagsService {
1158
+ constructor(config, http) {
1159
+ this.config = config;
1160
+ this.http = http;
1161
+ }
1162
+ /**
1163
+ * Retrieves active topics from the list of topic ID's. Note that inactive or expired
1164
+ * topics will not be retrieved.
1109
1165
  *
1110
- * @param records Records to process
1111
- * @returns An array of processed stock location records
1166
+ * @param options Tag filters
1112
1167
  */
1113
- processStockLocations(records) {
1114
- const stock_locations = [];
1168
+ getTags(options) {
1169
+ const params = this.parseOptions(options);
1170
+ return this.http.get(`${this.config.api_url}/get-tags.php`, { params }).pipe(map(response => {
1171
+ if (response.records === undefined) {
1172
+ throw response;
1173
+ }
1174
+ return this.processTags(response.records);
1175
+ }));
1176
+ }
1177
+ parseOptions(options) {
1178
+ let params = new HttpParams();
1179
+ if (options) {
1180
+ if (options.tags_id) {
1181
+ if (Array.isArray(options.tags_id)) {
1182
+ const tag_list = options.tags_id;
1183
+ if (tag_list.length > 0) {
1184
+ params = params.append('tags_id', tag_list.join(','));
1185
+ }
1186
+ }
1187
+ else {
1188
+ params = params.append('tags_id', options.tags_id);
1189
+ }
1190
+ }
1191
+ else {
1192
+ if (options.phrase && options.phrase !== '') {
1193
+ params = params.append('phrase', options.phrase);
1194
+ const phrase_match_mode = options.phrase_match_mode;
1195
+ if (phrase_match_mode) {
1196
+ params = params.append('phrase_match_mode', phrase_match_mode);
1197
+ }
1198
+ }
1199
+ }
1200
+ }
1201
+ return params;
1202
+ }
1203
+ processTags(records) {
1204
+ const tags = [];
1115
1205
  if (records) {
1116
1206
  for (const record of records) {
1117
- stock_locations.push(new EsolveLocation(record));
1207
+ const tag = new EsolveTag(record);
1208
+ tags.push(tag);
1118
1209
  }
1119
1210
  }
1120
- return stock_locations;
1211
+ return tags;
1121
1212
  }
1122
1213
  }
1123
- EsolveLocationsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveLocationsService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1124
- EsolveLocationsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveLocationsService, providedIn: 'root' });
1125
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveLocationsService, decorators: [{
1214
+ EsolveTagsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveTagsService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1215
+ EsolveTagsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveTagsService, providedIn: 'root' });
1216
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveTagsService, decorators: [{
1126
1217
  type: Injectable,
1127
1218
  args: [{
1128
1219
  providedIn: 'root',
@@ -1134,420 +1225,674 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
1134
1225
  }] }, { type: i1$2.HttpClient }];
1135
1226
  } });
1136
1227
 
1137
- class EsolveTransactionLocation extends EsolveLocation {
1138
- }
1228
+ // Types
1139
1229
 
1140
- class EsolveTransactionPaymentMethod {
1141
- constructor(id, name, description, integration_type, service_provider) {
1142
- this.id = id;
1143
- this.name = name;
1144
- this.description = description;
1145
- this.integration_type = integration_type;
1146
- this.service_provider = service_provider;
1230
+ class EsolveTopic {
1231
+ constructor(record) {
1232
+ var _a, _b, _c, _d;
1233
+ this.id = 0;
1234
+ this.name = '';
1235
+ this.short_description = '';
1236
+ this.sort_priority = 0;
1237
+ if (record) {
1238
+ this.id = +((_a = record.id) !== null && _a !== void 0 ? _a : 0);
1239
+ this.name = (_b = record.name) !== null && _b !== void 0 ? _b : '';
1240
+ this.short_description = (_c = record.short_description) !== null && _c !== void 0 ? _c : '';
1241
+ this.sort_priority = +((_d = record.sort_priority) !== null && _d !== void 0 ? _d : 0);
1242
+ }
1147
1243
  }
1148
1244
  }
1149
1245
 
1150
- class EsolveTransactionShippingMethod {
1151
- constructor(id, name, delivery_category, location, description, pricing, client_to_collect) {
1152
- this.id = id;
1153
- this.name = name;
1154
- this.delivery_category = delivery_category;
1155
- this.location = location;
1156
- this.description = description;
1157
- this.pricing = pricing;
1158
- this.client_to_collect = client_to_collect;
1246
+ class EsolveTopicService {
1247
+ constructor(config, http) {
1248
+ this.config = config;
1249
+ this.http = http;
1159
1250
  }
1160
- }
1161
-
1162
- class EsolveTransactionUser {
1163
- constructor(id, email, first_name, last_name, tel_number, cell_number) {
1164
- this.id = id;
1165
- this.email = email;
1166
- this.first_name = first_name;
1167
- this.last_name = last_name;
1168
- this.tel_number = tel_number;
1169
- this.cell_number = cell_number;
1251
+ /**
1252
+ * Retrieves active topics from the list of topic ID's. Note that inactive or expired
1253
+ * topics will not be retrieved.
1254
+ *
1255
+ * @param topic_id_list List of topic ID's that need to be retrieved
1256
+ */
1257
+ getTopics(topic_id_list = []) {
1258
+ let params = new HttpParams();
1259
+ if (topic_id_list.length > 0) {
1260
+ params = params.append('topic_id', topic_id_list.join(','));
1261
+ }
1262
+ return this.http.get(`${this.config.api_url}/get-topics.php`, { params }).pipe(map(response => {
1263
+ if (response.records === undefined) {
1264
+ throw response;
1265
+ }
1266
+ return this.processTopics(response.records);
1267
+ }));
1170
1268
  }
1171
- }
1269
+ processTopics(records) {
1270
+ const topics = [];
1271
+ if (records) {
1272
+ for (const record of records) {
1273
+ const topic = new EsolveTopic(record);
1274
+ topics.push(topic);
1275
+ }
1276
+ }
1277
+ return topics;
1278
+ }
1279
+ }
1280
+ EsolveTopicService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveTopicService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1281
+ EsolveTopicService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveTopicService, providedIn: 'root' });
1282
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveTopicService, decorators: [{
1283
+ type: Injectable,
1284
+ args: [{
1285
+ providedIn: 'root',
1286
+ }]
1287
+ }], ctorParameters: function () {
1288
+ return [{ type: undefined, decorators: [{
1289
+ type: Inject,
1290
+ args: [ESOLVE_CONNECT_CONFIG]
1291
+ }] }, { type: i1$2.HttpClient }];
1292
+ } });
1172
1293
 
1173
- class EsolveTransaction {
1294
+ class EsolveAsset {
1174
1295
  constructor(record) {
1175
- // Transaction Items
1176
- this.items = [];
1296
+ var _a, _b, _c, _d, _e, _f, _g;
1297
+ this.id = 0;
1298
+ this.src = '';
1299
+ this.name = '';
1300
+ this.description = '';
1301
+ this.document_number = '';
1302
+ this.document_type = '';
1303
+ this.area_of_application = '';
1304
+ this.asset_category = '';
1305
+ this.asset_sub_category = '';
1306
+ this.sort_priority = 0;
1307
+ this.topics = [];
1308
+ this.tags = [];
1309
+ this.image_name = '';
1177
1310
  this.id = +record.id;
1178
- this.type = record.transaction_type;
1179
- this.status = record.status;
1180
- this.loyalty_number = record.loyaltynumber;
1181
- this.external_order_number = record.external_order_number;
1182
- this.external_invoice_number = record.external_invoice_number;
1183
- this.date = new Date(+record.txdate_timestamp * 1000);
1184
- this.expected_date = new Date(+record.expected_date_timestamp * 1000);
1185
- this.invoice_amount = +record.invoice_amount;
1186
- this.vat = +record.vat;
1187
- this.discount = +record.discount;
1188
- this.total = +record.total;
1189
- this.shipping_total = +record.shipping_total;
1190
- this.insurance_total = +record.insurance_total;
1191
- this.payment = +record.payment;
1192
- this.payment_reference = record.payment_reference;
1193
- this.payment_description = record.payment_description;
1194
- this.gateway_transaction_id = record.gateway_transaction_id;
1195
- this.address = new EsolveTransactionAddress(record.recipient, record.address_type, record.address_description, record.street_number, record.street, record.suburb, record.city, record.province, record.country, record.postal_code, record.pobox);
1196
- if (record.user) {
1197
- this.user = new EsolveTransactionUser(+record.user.id, record.user.email, record.user.firstname, record.user.surname, record.user.telnumber, record.user.cellnumber);
1311
+ this.src = record.src;
1312
+ this.name = record.name;
1313
+ this.type = record.type;
1314
+ this.description = record.description;
1315
+ this.document_number = (_a = record.document_number) !== null && _a !== void 0 ? _a : '';
1316
+ this.document_type = (_b = record.document_type) !== null && _b !== void 0 ? _b : '';
1317
+ this.area_of_application = (_c = record.area_of_application) !== null && _c !== void 0 ? _c : '';
1318
+ this.asset_category = (_d = record.asset_category) !== null && _d !== void 0 ? _d : '';
1319
+ this.asset_sub_category = (_e = record.asset_sub_category) !== null && _e !== void 0 ? _e : '';
1320
+ this.sort_priority = +((_f = record.sort_priority) !== null && _f !== void 0 ? _f : '');
1321
+ this.image_name = (_g = record.image_name) !== null && _g !== void 0 ? _g : '';
1322
+ if (record.created) {
1323
+ this.created = record.created;
1198
1324
  }
1199
- if (record.client) {
1200
- this.client = new EsolveTransactionClient(+record.client.id, record.client.account, record.client.company_name, record.client.branch_code, record.client.email, record.client.firstname, record.client.surname, record.client.contact_number);
1325
+ if (record.category) {
1326
+ this.category = new EsolveCategoryTreeItem(record.category.type, record.category.id, record.category.parent_id, record.category.description, record.category.sef_description, record.category.short_description, record.category.sort_priority, record.category.active, record.category.display_only, record.category.image, record.category.seo_page_title, record.category.seo_keywords, record.category.seo_description);
1201
1327
  }
1202
- if (record.location_details) {
1203
- this.location = new EsolveTransactionLocation(record.location_details);
1328
+ if (record.subcategory) {
1329
+ this.subcategory = new EsolveCategoryTreeItem(record.subcategory.type, record.subcategory.id, record.subcategory.parent_id, record.subcategory.description, record.subcategory.sef_description, record.subcategory.short_description, record.subcategory.sort_priority, record.subcategory.active, record.subcategory.display_only, record.subcategory.image, record.subcategory.seo_page_title, record.subcategory.seo_keywords, record.subcategory.seo_description);
1204
1330
  }
1205
- if (record.payment_method_details) {
1206
- this.payment_method = new EsolveTransactionPaymentMethod(record.payment_method_details.id, record.payment_method_details.paymethod_name, record.payment_method_details.description, record.payment_method_details.integration_type, record.payment_method_details.service_provider);
1331
+ if (record.manufacturer) {
1332
+ this.manufacturer = new EsolveManufacturer(record.manufacturer);
1207
1333
  }
1208
- if (record.shipping_method_details) {
1209
- this.shipping_method = new EsolveTransactionShippingMethod(+record.shipping_method_details.id, record.shipping_method_details.carrier_name, record.shipping_method_details.delivery_category, record.shipping_method_details.location, record.shipping_method_details.description, record.shipping_method_details.pricing, !!record.shipping_method_details.client_to_collect);
1334
+ if (record.range) {
1335
+ this.range = new EsolveRange(record.range);
1210
1336
  }
1211
- this.parseTransactionItems(record.transaction_items);
1212
- }
1213
- parseTransactionItems(record_items) {
1214
- for (const record_item of record_items) {
1215
- const price = new EsolveTransactionItemPrice(+record_item.price_exclusive, +record_item.price_inclusive, +record_item.price_exclusive_after_discount, +record_item.price_inclusive_after_discount);
1216
- const line_total = new EsolveTransactionItemPrice(+record_item.line_total_exclusive, +record_item.line_total_inclusive, +record_item.line_total_exclusive_after_discount, +record_item.line_total_inclusive_after_discount);
1217
- const item = new EsolveTransactionItem(record_item.code, record_item.name, +record_item.qty, +record_item.discount, +record_item.vat_rate, price, line_total);
1218
- this.items.push(item);
1337
+ if (record.topics && record.topics.length > 0) {
1338
+ for (const topic of record.topics) {
1339
+ this.topics.push(new EsolveTopic(topic));
1340
+ }
1341
+ }
1342
+ if (record.tags && record.tags.length > 0) {
1343
+ for (const tag of record.tags) {
1344
+ this.tags.push(new EsolveTag(tag));
1345
+ }
1219
1346
  }
1220
1347
  }
1221
- }
1222
-
1223
- class EsolveTransactionList extends EsolveList {
1224
- }
1225
-
1226
- // Classes
1227
-
1228
- class EsolveChangePasswordResult extends EsolveResponseResult {
1229
- constructor(response) {
1230
- super(response);
1231
- this.password_updated = (response.status.state === 'success');
1232
- }
1233
- }
1234
-
1235
- class EsolveResetPasswordResult extends EsolveResponseResult {
1236
- constructor(response) {
1237
- super(response);
1238
- this.id = response.esolve_id;
1239
- this.reset_success = response.reset_success;
1240
- this.password_matches_old = response.password_matches_old;
1241
- this.login_required = response.login_required;
1242
- }
1243
- }
1244
-
1245
- class EsolveRegistrationResult extends EsolveResponseResult {
1246
- constructor(response) {
1247
- super(response);
1248
- this.user_id = response.esolve_id;
1249
- this.guest = response.guest;
1250
- this.auto_login = response.auto_login;
1251
- this.authentication_required = response.authentication_required;
1252
- this.location_id = response.session_data.location_id;
1348
+ /**
1349
+ * Shortcut to `getImagePath()`
1350
+ */
1351
+ get image_src() {
1352
+ return this.getImagePath();
1253
1353
  }
1254
- }
1255
-
1256
- class EsolveLocationUpdateResult extends EsolveResponseResult {
1257
- constructor(response) {
1258
- super(response);
1259
- this.location_updated = (response.esolve_id > 0);
1354
+ /**
1355
+ * Retrieve image path
1356
+ *
1357
+ * @returns Image path on CDN, else empty string if no image exists
1358
+ */
1359
+ getImagePath() {
1360
+ if (this.image_name !== '') {
1361
+ return `/images/documents/${this.image_name}`;
1362
+ }
1363
+ return '';
1260
1364
  }
1261
1365
  }
1262
1366
 
1263
- class EsolveAccountService {
1264
- constructor(config, http, sessionService, errorHandler, responseHandler) {
1367
+ class EsolveAssetsService {
1368
+ constructor(config, http) {
1265
1369
  this.config = config;
1266
1370
  this.http = http;
1267
- this.sessionService = sessionService;
1268
- this.errorHandler = errorHandler;
1269
- this.responseHandler = responseHandler;
1270
- this._user_id = 0;
1271
- this.sessionService.session.subscribe((session) => {
1272
- if (session.key !== '') {
1273
- this.user_id = session.id;
1274
- }
1275
- });
1276
- }
1277
- get user_id() {
1278
- return this._user_id;
1279
- }
1280
- set user_id(value) {
1281
- value = ((value > 0) ? value : 0);
1282
- if (this._user_id !== value) {
1283
- this._user_id = value;
1284
- }
1285
- }
1286
- updateUserAccount(user_account_data) {
1287
- const body = {
1288
- account: user_account_data
1289
- };
1290
- return this.http
1291
- .post(`${this.config.api_url}/set-user-account.php`, body, {
1292
- headers: {
1293
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
1294
- },
1295
- responseType: 'json',
1296
- observe: 'body'
1297
- })
1298
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => new EsolveUserAccountResult(response))), catchError((errorRes) => {
1299
- return this.errorHandler.handleHttpPostError('set-user-account', errorRes);
1300
- }));
1301
1371
  }
1302
- getUserAccount() {
1303
- return this.http
1304
- .get(`${this.config.api_url}/get-account.php`)
1305
- .pipe(map((response) => {
1372
+ getAsset(id) {
1373
+ const params = new HttpParams({ fromObject: { assets_id: id } });
1374
+ return this.getAssetRecords(params).pipe(map((response) => {
1306
1375
  if ((response.records === undefined) ||
1307
- (response.records.length === 0)) {
1376
+ (response.records.length <= 0)) {
1308
1377
  throw response;
1309
1378
  }
1310
1379
  const record = response.records[0];
1311
- return this.processUserAccount(record);
1380
+ return this.processAsset(record);
1312
1381
  }));
1313
1382
  }
1314
- setAddress(address_post_data) {
1315
- const body = {
1316
- address: address_post_data
1317
- };
1318
- return this.http
1319
- .post(`${this.config.api_url}/set-address.php`, body, {
1320
- headers: {
1321
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
1322
- },
1323
- responseType: 'json',
1324
- observe: 'body',
1325
- })
1326
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => new EsolveAddressResult(response))), catchError((errorRes) => {
1327
- return this.errorHandler.handleHttpPostError('set-registration', errorRes);
1383
+ getAssets(options) {
1384
+ const params = this.parseOptions(options);
1385
+ return this.getAssetRecords(params).pipe(map((response) => {
1386
+ var _a, _b;
1387
+ if (response.records === undefined) {
1388
+ throw response;
1389
+ }
1390
+ const assets = [];
1391
+ for (const record of response.records) {
1392
+ assets.push(this.processAsset(record));
1393
+ }
1394
+ const page = (_a = options === null || options === void 0 ? void 0 : options.page) !== null && _a !== void 0 ? _a : 0;
1395
+ const rows = (_b = options === null || options === void 0 ? void 0 : options.rows) !== null && _b !== void 0 ? _b : 0;
1396
+ const total = +response.additional_data.total_records;
1397
+ return new EsolveList(assets, page, rows, total);
1328
1398
  }));
1329
1399
  }
1330
- getAddresses() {
1331
- try {
1332
- this.loginGuard();
1333
- return this.http
1334
- .get(`${this.config.api_url}/get-addresses.php`, {
1335
- params: { user_id: this.user_id }
1336
- })
1337
- .pipe(map((response) => {
1338
- if (response.records === undefined) {
1339
- throw response;
1340
- }
1341
- return this.processUserAddress(response.records);
1342
- }));
1400
+ processAsset(record) {
1401
+ return new EsolveAsset(record);
1402
+ }
1403
+ getAssetRecords(params) {
1404
+ return this.http.get(`${this.config.api_url}/get-assets.php`, { params });
1405
+ }
1406
+ parseOptions(options) {
1407
+ let params = new HttpParams();
1408
+ if (!options) {
1409
+ return params;
1343
1410
  }
1344
- catch (error) {
1345
- return throwError(error);
1411
+ if (options.page) {
1412
+ params = params.set('page', options.page);
1346
1413
  }
1414
+ if (options.rows) {
1415
+ params = params.set('rows', options.rows);
1416
+ }
1417
+ if (options.asset_type) {
1418
+ params = params.set('asset_type', options.asset_type);
1419
+ }
1420
+ if (options.category_id) {
1421
+ params = params.set('category_id', options.category_id);
1422
+ }
1423
+ if (options.subcategory_id) {
1424
+ params = params.set('subcategory_id', options.subcategory_id);
1425
+ }
1426
+ if (options.manufacturers_id) {
1427
+ params = params.set('manufacturers_id', options.manufacturers_id);
1428
+ }
1429
+ if (options.ranges_id) {
1430
+ params = params.set('ranges_id', options.ranges_id);
1431
+ }
1432
+ if (options.asset_category) {
1433
+ params = params.set('asset_category', options.asset_category);
1434
+ }
1435
+ if (options.asset_sub_category) {
1436
+ params = params.set('asset_sub_category', options.asset_sub_category);
1437
+ }
1438
+ if (options.document_number) {
1439
+ params = params.set('document_number', options.document_number);
1440
+ }
1441
+ if (options.document_type) {
1442
+ params = params.set('document_type', options.document_type);
1443
+ }
1444
+ if (options.area_of_application) {
1445
+ params = params.set('area_of_application', options.area_of_application);
1446
+ }
1447
+ return params;
1347
1448
  }
1348
- deleteAddress(id) {
1349
- return this.http
1350
- .delete(`${this.config.api_url}/delete-address.php`, {
1351
- params: { id },
1352
- responseType: 'json',
1353
- observe: 'body'
1354
- })
1355
- .pipe(map((http_response) => {
1356
- if ((http_response.result === undefined) ||
1357
- (http_response.result === null) ||
1358
- (http_response.result.status !== 'success')) {
1359
- throw http_response;
1360
- }
1361
- return new EsolveResult(http_response.result.status, http_response.result.code, http_response.result.message);
1362
- }), catchError((errorRes) => {
1363
- return this.errorHandler.handleHttpDeleteError('delete-address', errorRes);
1364
- }));
1365
- }
1366
- register(user_registration) {
1367
- const body = {
1368
- user: user_registration
1369
- };
1449
+ }
1450
+ EsolveAssetsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAssetsService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1451
+ EsolveAssetsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAssetsService, providedIn: 'root' });
1452
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAssetsService, decorators: [{
1453
+ type: Injectable,
1454
+ args: [{
1455
+ providedIn: 'root',
1456
+ }]
1457
+ }], ctorParameters: function () {
1458
+ return [{ type: undefined, decorators: [{
1459
+ type: Inject,
1460
+ args: [ESOLVE_CONNECT_CONFIG]
1461
+ }] }, { type: i1$2.HttpClient }];
1462
+ } });
1463
+
1464
+ // Types
1465
+
1466
+ class EsolveAuthService {
1467
+ constructor(config, http, session, errorHandler, cookieService) {
1468
+ this.config = config;
1469
+ this.http = http;
1470
+ this.session = session;
1471
+ this.errorHandler = errorHandler;
1472
+ this.cookieService = cookieService;
1473
+ }
1474
+ getAccessToken(email, password, anonymous = false) {
1475
+ let params = new HttpParams();
1476
+ if (anonymous) {
1477
+ params = params.set('anonymous', true);
1478
+ }
1479
+ if (email !== '') {
1480
+ params = params.set('email', email);
1481
+ }
1482
+ if (password !== '') {
1483
+ params = params.set('password', password);
1484
+ }
1370
1485
  return this.http
1371
- .post(`${this.config.api_url}/set-registration.php`, body, {
1372
- headers: {
1373
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
1374
- },
1375
- responseType: 'json',
1376
- observe: 'body'
1486
+ .get(`${this.config.api_url}/get-access-token.php`, {
1487
+ params,
1488
+ headers: new HttpHeaders({
1489
+ 'Accept-Language': '*',
1490
+ }),
1377
1491
  })
1378
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
1379
- if (response.auto_login) {
1380
- this.sessionService.handleUpdateSession({
1381
- user_id: +response.esolve_id,
1382
- location_id: +response.session_data.location_id,
1383
- });
1492
+ .pipe(tap((responseData) => {
1493
+ if ((responseData.type === 'error') ||
1494
+ (responseData.type === 'exception')) {
1495
+ throw responseData;
1384
1496
  }
1385
- return new EsolveRegistrationResult(response);
1386
- })), catchError((errorRes) => {
1387
- return this.errorHandler.handleHttpPostError('set-registration', errorRes);
1497
+ }), catchError(this.handleError), tap((responseData) => {
1498
+ this.handleAuthentication(responseData.additional_data);
1388
1499
  }));
1389
1500
  }
1390
- changePassword(password, confirm_password) {
1501
+ autoLogin() {
1502
+ this.session.restore(this.handleExpiration(), () => {
1503
+ this.getAccessToken('', '', true).toPromise().then(() => { }, (error) => {
1504
+ console.error(error);
1505
+ });
1506
+ });
1507
+ }
1508
+ login(email, password) {
1391
1509
  const body = {
1392
- password,
1393
- confirm_password
1510
+ login: {
1511
+ email,
1512
+ password
1513
+ }
1394
1514
  };
1395
1515
  return this.http
1396
- .post(`${this.config.api_url}/set-change-password.php`, body, {
1516
+ .post(`${this.config.api_url}/set-login.php`, body, {
1397
1517
  headers: {
1398
1518
  'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
1399
1519
  },
1400
1520
  responseType: 'json',
1401
1521
  observe: 'body'
1402
1522
  })
1403
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
1404
- return new EsolveChangePasswordResult(response);
1405
- })), catchError((errorRes) => {
1406
- return this.errorHandler.handleHttpPostError('set-change-password', errorRes);
1407
- }));
1408
- }
1409
- sendForgotPasswordRequest(email) {
1410
- return this.http
1411
- .get(`${this.config.api_url}/get-forgot-password.php`, { params: { email } })
1412
1523
  .pipe(map((response) => {
1413
- if ((response.records === undefined) ||
1414
- !('reset_link_sent' in response.records)) {
1524
+ if ((response.responses === undefined) ||
1525
+ (response.responses.length <= 0)) {
1415
1526
  throw response;
1416
1527
  }
1417
- return response.records.reset_link_sent;
1528
+ const login_response = response.responses[0];
1529
+ if ((login_response.status.state !== 'success') &&
1530
+ (login_response.status.state !== 'warning')) {
1531
+ throw login_response;
1532
+ }
1533
+ for (const response_log of login_response.log) {
1534
+ if ((response_log.type === 'success') &&
1535
+ (response_log.message_code === 'login_success')) {
1536
+ const session_data = login_response.session_data;
1537
+ const user_id = +login_response.esolve_id;
1538
+ const location_id = +session_data.location_id;
1539
+ this.session.handleUpdateSession({
1540
+ user_id: user_id,
1541
+ location_id: location_id
1542
+ });
1543
+ return user_id;
1544
+ }
1545
+ }
1546
+ throw login_response;
1547
+ }), catchError((errorRes) => {
1548
+ return this.errorHandler.handleHttpPostError('set-login', errorRes);
1418
1549
  }));
1419
1550
  }
1420
- resetPassword(reset_key, password, confirm_password, auto_login = true) {
1551
+ logout() {
1552
+ this.session.clearTimer();
1553
+ this.cookieService.delete('_ws_id');
1554
+ return this.getAccessToken('', '', true).toPromise();
1555
+ }
1556
+ checkAccessToken(session) {
1557
+ var _a;
1558
+ session = session || this.session.currentSession;
1559
+ const token = (_a = session === null || session === void 0 ? void 0 : session.key) !== null && _a !== void 0 ? _a : '';
1421
1560
  return this.http
1422
- .post(`${this.config.api_url}/set-forgot-password.php`, {
1423
- reset_key,
1424
- password,
1425
- confirm_password,
1426
- auto_login
1427
- }, {
1428
- headers: {
1429
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
1430
- },
1431
- responseType: 'json',
1432
- observe: 'body'
1561
+ .get(`${this.config.api_url}/get-access-token.php`, {
1562
+ params: { key: token },
1563
+ headers: new HttpHeaders({
1564
+ 'Accept-Language': '*'
1565
+ }),
1433
1566
  })
1434
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
1435
- if (!response.login_required) {
1436
- this.sessionService.handleUpdateSession({
1437
- user_id: +response.esolve_id,
1438
- location_id: +response.session_data.location_id,
1439
- });
1567
+ .pipe(map((responseData) => {
1568
+ if ((responseData.type === 'error') ||
1569
+ (responseData.type === 'exception') ||
1570
+ (!responseData.additional_data.key_okay)) {
1571
+ throw responseData;
1440
1572
  }
1441
- return new EsolveResetPasswordResult(response);
1442
- })), catchError((errorRes) => {
1443
- return this.errorHandler.handleHttpPostError('set-forgot-password', errorRes);
1444
- }));
1573
+ const additional_data = responseData.additional_data;
1574
+ const result = {
1575
+ key: token,
1576
+ expires: additional_data.expires,
1577
+ expiry_time: additional_data.expiry_time,
1578
+ location_id: additional_data.location_id,
1579
+ user_id: additional_data.user_id,
1580
+ };
1581
+ return result;
1582
+ }))
1583
+ .toPromise();
1445
1584
  }
1446
- updateLocation(location_id) {
1447
- const body = { location_id };
1448
- return this.http
1449
- .post(`${this.config.api_url}/set-session-location.php`, body, {
1450
- headers: {
1451
- 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
1452
- },
1453
- responseType: 'json',
1454
- observe: 'body',
1455
- })
1456
- .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
1457
- this.sessionService.handleUpdateSession({ location_id });
1458
- return new EsolveLocationUpdateResult(response);
1459
- })));
1585
+ // Handlers
1586
+ handleExpiration() {
1587
+ return (session) => {
1588
+ this.checkAccessToken(session).then((response) => {
1589
+ this.handleAuthentication(response);
1590
+ }, () => {
1591
+ this.logout();
1592
+ });
1593
+ };
1460
1594
  }
1461
- getTransactions(options = {}) {
1462
- try {
1463
- this.loginGuard();
1464
- return this.http
1465
- .get(`${this.config.api_url}/get-transactions.php`, {
1466
- params: Object.assign({ user_id: this.user_id }, options)
1467
- })
1468
- .pipe(map((response) => {
1469
- var _a, _b;
1470
- if (response.records === undefined) {
1471
- throw response;
1472
- }
1473
- const items = this.processTransactions(response.records);
1474
- const total = (_a = +response.additional_data.total_records) !== null && _a !== void 0 ? _a : 0;
1475
- const rows = (_b = options.rows) !== null && _b !== void 0 ? _b : total;
1476
- const page = options.page || 1;
1477
- return new EsolveTransactionList(items, page, rows, total);
1478
- }));
1595
+ handleAuthentication(result) {
1596
+ if (!result.key) {
1597
+ return;
1479
1598
  }
1480
- catch (error) {
1599
+ this.session.handleSession(+result.user_id, +result.location_id, result.key, +result.expiry_time, +result.expires, this.handleExpiration());
1600
+ }
1601
+ handleError(errorRes) {
1602
+ const error = {
1603
+ message: 'An unknown error occurred',
1604
+ data: {},
1605
+ };
1606
+ if ((!errorRes.type) ||
1607
+ (!errorRes.service_type) ||
1608
+ (!errorRes.message)) {
1481
1609
  return throwError(error);
1482
1610
  }
1611
+ if (errorRes.message.trim() !== '') {
1612
+ error.message = errorRes.message;
1613
+ }
1614
+ if (errorRes.additional_data) {
1615
+ error.data = errorRes.additional_data;
1616
+ }
1617
+ return throwError(error);
1618
+ }
1619
+ }
1620
+ EsolveAuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAuthService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }, { token: EsolveSessionService }, { token: EsolveErrorHandlerService }, { token: EsolveCookieService }], target: i0.ɵɵFactoryTarget.Injectable });
1621
+ EsolveAuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAuthService, providedIn: 'root' });
1622
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAuthService, decorators: [{
1623
+ type: Injectable,
1624
+ args: [{
1625
+ providedIn: 'root',
1626
+ }]
1627
+ }], ctorParameters: function () {
1628
+ return [{ type: undefined, decorators: [{
1629
+ type: Inject,
1630
+ args: [ESOLVE_CONNECT_CONFIG]
1631
+ }] }, { type: i1$2.HttpClient }, { type: EsolveSessionService }, { type: EsolveErrorHandlerService }, { type: EsolveCookieService }];
1632
+ } });
1633
+
1634
+ class EsolveAddress {
1635
+ constructor(id, recipient, address_type, pobox, place_name, street_number, street, suburb, city, province, country, postal_code, latitude, longitude) {
1636
+ this.id = id;
1637
+ this.recipient = recipient;
1638
+ this.address_type = address_type;
1639
+ this.pobox = pobox;
1640
+ this.place_name = place_name;
1641
+ this.street_number = street_number;
1642
+ this.street = street;
1643
+ this.suburb = suburb;
1644
+ this.city = city;
1645
+ this.province = province;
1646
+ this.country = country;
1647
+ this.postal_code = postal_code;
1648
+ this.latitude = latitude;
1649
+ this.longitude = longitude;
1650
+ }
1651
+ }
1652
+
1653
+ class EsolveAddressResult extends EsolveResponseResult {
1654
+ constructor(response) {
1655
+ super(response);
1656
+ this.id = response.esolve_id;
1657
+ this.address_validated = response.address_validated;
1658
+ this.geocode_status = response.geocode_status;
1659
+ this.geocode_result = response.geocode_result;
1660
+ }
1661
+ }
1662
+
1663
+ class EsolveUserAccount {
1664
+ constructor(esolve_id, email, registration_type, title, first_name, last_name, initials, gender, identification_number) {
1665
+ this.esolve_id = esolve_id;
1666
+ this.email = email;
1667
+ this.registration_type = registration_type;
1668
+ this.title = title;
1669
+ this.first_name = first_name;
1670
+ this.last_name = last_name;
1671
+ this.initials = initials;
1672
+ this.gender = gender;
1673
+ this.identification_number = identification_number;
1674
+ }
1675
+ }
1676
+
1677
+ class EsolveUserAccountResult extends EsolveResponseResult {
1678
+ constructor(response) {
1679
+ super(response);
1680
+ this.id = 0;
1681
+ this.id = +response.esolve_id;
1682
+ }
1683
+ }
1684
+
1685
+ class EsolveUserAccountBusiness {
1686
+ constructor(name, vat_number, description, type) {
1687
+ this.name = name;
1688
+ this.vat_number = vat_number;
1689
+ this.description = description;
1690
+ this.type = type;
1691
+ }
1692
+ }
1693
+
1694
+ class EsolveUserAccountContact {
1695
+ constructor(tel_number, cell_number, fax_number) {
1696
+ this.tel_number = tel_number;
1697
+ this.cell_number = cell_number;
1698
+ this.fax_number = fax_number;
1699
+ }
1700
+ }
1701
+
1702
+ class EsolveTransactionAddress {
1703
+ constructor(recipient, address_type, address_description, street_number, street, suburb, city, province, country, postal_code, pobox) {
1704
+ this.recipient = recipient;
1705
+ this.address_type = address_type;
1706
+ this.address_description = address_description;
1707
+ this.street_number = street_number;
1708
+ this.street = street;
1709
+ this.suburb = suburb;
1710
+ this.city = city;
1711
+ this.province = province;
1712
+ this.country = country;
1713
+ this.postal_code = postal_code;
1714
+ this.pobox = pobox;
1715
+ }
1716
+ }
1717
+
1718
+ class EsolveTransactionClient {
1719
+ constructor(id, account, company_name, branch_code, email, first_name, last_name, contact_number) {
1720
+ this.id = id;
1721
+ this.account = account;
1722
+ this.company_name = company_name;
1723
+ this.branch_code = branch_code;
1724
+ this.email = email;
1725
+ this.first_name = first_name;
1726
+ this.last_name = last_name;
1727
+ this.contact_number = contact_number;
1728
+ }
1729
+ }
1730
+
1731
+ class EsolveTransactionItem {
1732
+ constructor(code, name, qty, discount, vat_rate, price, line_total) {
1733
+ this.code = code;
1734
+ this.name = name;
1735
+ this.qty = qty;
1736
+ this.discount = discount;
1737
+ this.vat_rate = vat_rate;
1738
+ this.price = price;
1739
+ this.line_total = line_total;
1740
+ }
1741
+ }
1742
+
1743
+ class EsolveTransactionItemPrice {
1744
+ constructor(
1745
+ /**
1746
+ * Price without tax
1747
+ */
1748
+ price,
1749
+ /**
1750
+ * Price with tax
1751
+ */
1752
+ price_with_tax,
1753
+ /**
1754
+ * Price without tax and with discounts applied if applicable
1755
+ */
1756
+ price_discounted,
1757
+ /**
1758
+ * Price with tax and with discounts applied if applicable
1759
+ */
1760
+ price_with_tax_discounted) {
1761
+ this.price = price;
1762
+ this.price_with_tax = price_with_tax;
1763
+ this.price_discounted = price_discounted;
1764
+ this.price_with_tax_discounted = price_with_tax_discounted;
1765
+ }
1766
+ }
1767
+
1768
+ class EsolveLocationAddress {
1769
+ constructor(street, suburb, city, province, country, postal_code, latitude, longitude) {
1770
+ this.street = street;
1771
+ this.suburb = suburb;
1772
+ this.city = city;
1773
+ this.province = province;
1774
+ this.country = country;
1775
+ this.postal_code = postal_code;
1776
+ this.latitude = latitude;
1777
+ this.longitude = longitude;
1778
+ }
1779
+ }
1780
+
1781
+ class EsolveLocationContactInfo {
1782
+ constructor(telnumber, cellnumber, email, fax) {
1783
+ this.telnumber = telnumber;
1784
+ this.cellnumber = cellnumber;
1785
+ this.email = email;
1786
+ this.fax = fax;
1787
+ }
1788
+ }
1789
+
1790
+ class EsolveLocationPOBoxAddress {
1791
+ constructor(pobox, city, postal_code) {
1792
+ this.pobox = pobox;
1793
+ this.city = city;
1794
+ this.postal_code = postal_code;
1795
+ }
1796
+ }
1797
+
1798
+ class EsolveLocationTradingTimes {
1799
+ constructor(monday, tuesday, wednesday, thursday, friday, saturday, sunday, public_holiday, trading_hours_additional_info = '') {
1800
+ this.monday = monday;
1801
+ this.tuesday = tuesday;
1802
+ this.wednesday = wednesday;
1803
+ this.thursday = thursday;
1804
+ this.friday = friday;
1805
+ this.saturday = saturday;
1806
+ this.sunday = sunday;
1807
+ this.public_holiday = public_holiday;
1808
+ this.trading_hours_additional_info = trading_hours_additional_info;
1483
1809
  }
1484
- getTransaction(id) {
1485
- try {
1486
- this.loginGuard();
1487
- return this.http
1488
- .get(`${this.config.api_url}/get-transactions.php`, {
1489
- params: {
1490
- user_id: this.user_id,
1491
- transaction_id: id,
1492
- }
1493
- })
1494
- .pipe(map((response) => {
1495
- if ((response.records === undefined) ||
1496
- (response.records.length <= 0)) {
1497
- throw response;
1498
- }
1499
- const items = this.processTransactions(response.records);
1500
- return items[0];
1501
- }));
1502
- }
1503
- catch (error) {
1504
- return throwError(error);
1505
- }
1810
+ }
1811
+
1812
+ class EsolveLocationTradingDay {
1813
+ constructor(open, close) {
1814
+ this.open = open;
1815
+ this.close = close;
1506
1816
  }
1507
- processUserAccount(record) {
1508
- if (!record) {
1509
- throw new Error('Invalid record');
1817
+ }
1818
+
1819
+ class EsolveLocation {
1820
+ constructor(record) {
1821
+ this.id = +record.id;
1822
+ this.identifier = record.identifier;
1823
+ this.description = record.description;
1824
+ this.head_office = record.head_office;
1825
+ this.erp_identifier = record.erp_identifier;
1826
+ this.external_system_code = record.external_system_code;
1827
+ this.default_location_for_payment_methods = record.default_location_for_payment_methods;
1828
+ this.userid = +record.userid;
1829
+ this.importance = +record.importance;
1830
+ this.active = record.is_active;
1831
+ this.website_url = record.website_url;
1832
+ this.address = new EsolveLocationAddress(record.street, record.suburb, record.city, record.province, record.country, record.postal_code, +record.latitude, +record.longitude);
1833
+ this.pobox_address = new EsolveLocationPOBoxAddress(record.pobox, record.pobox_city, record.pobox_postal_code);
1834
+ const telnumbers = [];
1835
+ if (record.branch_telnumber.length > 0) {
1836
+ telnumbers.push(record.branch_telnumber);
1510
1837
  }
1511
- if (+record.userid !== this._user_id) {
1512
- throw new Error('Invalid user account retrieved');
1838
+ if (record.branch_telnumber_2.length > 0) {
1839
+ telnumbers.push(record.branch_telnumber_2);
1513
1840
  }
1514
- const user_account = new EsolveUserAccount(+record.userid, record.email, record.registration_type, record.title, record.firstname, record.surname, record.initials, record.gender, record.idnumber);
1515
- user_account.contact_details = new EsolveUserAccountContact(record.telnumber, record.cellnumber, record.fax);
1516
- user_account.business_details = new EsolveUserAccountBusiness(record.busname, record.vatnum, record.busdescript, record.business_type);
1517
- return user_account;
1518
- }
1519
- processUserAddress(records) {
1520
- const user_addresses = [];
1521
- if (!records || (this._user_id === 0)) {
1522
- return user_addresses;
1841
+ if (record.branch_telnumber_3.length > 0) {
1842
+ telnumbers.push(record.branch_telnumber_3);
1523
1843
  }
1524
- for (const record of records) {
1525
- if (+record.userid !== this._user_id) {
1526
- continue;
1844
+ this.contact_info = new EsolveLocationContactInfo(telnumbers, record.branch_cellnumber, record.branch_email, record.branch_fax);
1845
+ const monday = new EsolveLocationTradingDay(record.monday_open_time, record.monday_close_time);
1846
+ const tuesday = new EsolveLocationTradingDay(record.tuesday_open_time, record.tuesday_close_time);
1847
+ const wednesday = new EsolveLocationTradingDay(record.wednesday_open_time, record.wednesday_close_time);
1848
+ const thursday = new EsolveLocationTradingDay(record.thursday_open_time, record.thursday_close_time);
1849
+ const friday = new EsolveLocationTradingDay(record.friday_open_time, record.friday_close_time);
1850
+ const saturday = new EsolveLocationTradingDay(record.saturday_open_time, record.saturday_close_time);
1851
+ const sunday = new EsolveLocationTradingDay(record.sunday_open_time, record.sunday_close_time);
1852
+ const public_holiday = new EsolveLocationTradingDay(record.public_holiday_open_time, record.public_holiday_close_time);
1853
+ this.trading_times = new EsolveLocationTradingTimes(monday, tuesday, wednesday, thursday, friday, saturday, sunday, public_holiday, record.trading_hours_additional_info);
1854
+ }
1855
+ }
1856
+
1857
+ class EsolveLocationsService {
1858
+ constructor(config, http) {
1859
+ this.config = config;
1860
+ this.http = http;
1861
+ }
1862
+ /**
1863
+ * Retrieves a list of stock locations
1864
+ *
1865
+ * @returns An `Observable` with an array of stock locations
1866
+ */
1867
+ getStockLocations() {
1868
+ return this.http
1869
+ .get(`${this.config.api_url}/get-locations.php`)
1870
+ .pipe(map((response) => {
1871
+ if (response.records === undefined) {
1872
+ throw response;
1527
1873
  }
1528
- user_addresses.push(new EsolveAddress(+record.id, record.recipient, record.address_type, record.pobox, record.place_name, record.street_number, record.street, record.suburb, record.city, record.province, record.country, record.postal_code, +record.latitude, +record.longitude));
1529
- }
1530
- return user_addresses;
1874
+ return this.processStockLocations(response.records);
1875
+ }));
1531
1876
  }
1532
- processTransactions(records) {
1533
- const transactions = [];
1877
+ /**
1878
+ * Processes the eSolve stock location records.
1879
+ *
1880
+ * @param records Records to process
1881
+ * @returns An array of processed stock location records
1882
+ */
1883
+ processStockLocations(records) {
1884
+ const stock_locations = [];
1534
1885
  if (records) {
1535
1886
  for (const record of records) {
1536
- const transaction = new EsolveTransaction(record);
1537
- transactions.push(transaction);
1887
+ stock_locations.push(new EsolveLocation(record));
1538
1888
  }
1539
1889
  }
1540
- return transactions;
1541
- }
1542
- loginGuard() {
1543
- if (this.user_id <= 0) {
1544
- this.errorHandler.throwError('login_required', 'Login is required');
1545
- }
1890
+ return stock_locations;
1546
1891
  }
1547
1892
  }
1548
- EsolveAccountService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAccountService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }, { token: EsolveSessionService }, { token: EsolveErrorHandlerService }, { token: EsolveResponseHandlerService }], target: i0.ɵɵFactoryTarget.Injectable });
1549
- EsolveAccountService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAccountService, providedIn: 'root' });
1550
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAccountService, decorators: [{
1893
+ EsolveLocationsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveLocationsService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1894
+ EsolveLocationsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveLocationsService, providedIn: 'root' });
1895
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveLocationsService, decorators: [{
1551
1896
  type: Injectable,
1552
1897
  args: [{
1553
1898
  providedIn: 'root',
@@ -1556,404 +1901,423 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
1556
1901
  return [{ type: undefined, decorators: [{
1557
1902
  type: Inject,
1558
1903
  args: [ESOLVE_CONNECT_CONFIG]
1559
- }] }, { type: i1$2.HttpClient }, { type: EsolveSessionService }, { type: EsolveErrorHandlerService }, { type: EsolveResponseHandlerService }];
1904
+ }] }, { type: i1$2.HttpClient }];
1560
1905
  } });
1561
1906
 
1562
- class EsolveBanner {
1563
- constructor(id, banner_display_container, identifier, type, title, article, sort_priority, link, images) {
1907
+ class EsolveTransactionLocation extends EsolveLocation {
1908
+ }
1909
+
1910
+ class EsolveTransactionPaymentMethod {
1911
+ constructor(id, name, description, integration_type, service_provider) {
1564
1912
  this.id = id;
1565
- this.banner_display_container = banner_display_container;
1566
- this.identifier = identifier;
1567
- this.type = type;
1568
- this.title = title;
1569
- this.article = article;
1570
- this.sort_priority = sort_priority;
1571
- this.link = link;
1572
- this.desktop_images = [];
1573
- this.mobile_images = [];
1574
- this.sub_images = [];
1575
- if (images.desktop) {
1576
- this.desktop_images = images.desktop;
1577
- }
1578
- if (images.mobile) {
1579
- this.mobile_images = images.mobile;
1580
- }
1581
- if (images.sub) {
1582
- this.sub_images = images.sub;
1583
- }
1913
+ this.name = name;
1914
+ this.description = description;
1915
+ this.integration_type = integration_type;
1916
+ this.service_provider = service_provider;
1584
1917
  }
1585
1918
  }
1586
1919
 
1587
- class EsolveBannerImage {
1588
- constructor(id, image_type, width, height, filename, hotspots) {
1920
+ class EsolveTransactionShippingMethod {
1921
+ constructor(id, name, delivery_category, location, description, pricing, client_to_collect) {
1589
1922
  this.id = id;
1590
- this.image_type = image_type;
1591
- this.width = width;
1592
- this.height = height;
1593
- this.filename = filename;
1594
- this.hotspots = hotspots;
1595
- }
1596
- get src() {
1597
- return '/images/banners/' + this.filename;
1923
+ this.name = name;
1924
+ this.delivery_category = delivery_category;
1925
+ this.location = location;
1926
+ this.description = description;
1927
+ this.pricing = pricing;
1928
+ this.client_to_collect = client_to_collect;
1598
1929
  }
1599
1930
  }
1600
1931
 
1601
- class EsolveBannerImageHotspot {
1602
- constructor(url, target, coords, coords_string) {
1603
- this.url = url;
1604
- this.target = target;
1605
- this.coords = coords;
1606
- this.coords_string = coords_string;
1932
+ class EsolveTransactionUser {
1933
+ constructor(id, email, first_name, last_name, tel_number, cell_number) {
1934
+ this.id = id;
1935
+ this.email = email;
1936
+ this.first_name = first_name;
1937
+ this.last_name = last_name;
1938
+ this.tel_number = tel_number;
1939
+ this.cell_number = cell_number;
1607
1940
  }
1608
1941
  }
1609
1942
 
1610
- class EsolveBannerService {
1611
- constructor(config, http) {
1612
- this.config = config;
1613
- this.http = http;
1614
- }
1615
- /**
1616
- * Retrieves banners records from eSolve instance
1617
- *
1618
- * @returns An observable of eSolve banners.
1619
- */
1620
- getBanners(identifier, banner_display_container, enable_date_filter = false) {
1621
- let params = new HttpParams({
1622
- fromObject: { enable_date_filter }
1623
- });
1624
- if (identifier) {
1625
- params = params.set('identifier', identifier);
1626
- }
1627
- if (banner_display_container) {
1628
- params = params.set('banner_display_container', banner_display_container);
1629
- }
1630
- return this.http
1631
- .get(`${this.config.api_url}/get-banners.php`, { params })
1632
- .pipe(map((response) => {
1633
- if (response.records === undefined) {
1634
- throw response;
1635
- }
1636
- return this.processBanners(response.records);
1637
- }));
1638
- }
1639
- processBannerImageHotspots(hotspot_records) {
1640
- const hotspots = [];
1641
- if (hotspot_records.length > 0) {
1642
- for (const hotspot_record of hotspot_records) {
1643
- const hotspot = new EsolveBannerImageHotspot(hotspot_record.url, hotspot_record.target, hotspot_record.coords, hotspot_record.coords_string);
1644
- hotspots.push(hotspot);
1645
- }
1943
+ class EsolveTransaction {
1944
+ constructor(record) {
1945
+ // Transaction Items
1946
+ this.items = [];
1947
+ this.id = +record.id;
1948
+ this.type = record.transaction_type;
1949
+ this.status = record.status;
1950
+ this.loyalty_number = record.loyaltynumber;
1951
+ this.external_order_number = record.external_order_number;
1952
+ this.external_invoice_number = record.external_invoice_number;
1953
+ this.date = new Date(+record.txdate_timestamp * 1000);
1954
+ this.expected_date = new Date(+record.expected_date_timestamp * 1000);
1955
+ this.invoice_amount = +record.invoice_amount;
1956
+ this.vat = +record.vat;
1957
+ this.discount = +record.discount;
1958
+ this.total = +record.total;
1959
+ this.shipping_total = +record.shipping_total;
1960
+ this.insurance_total = +record.insurance_total;
1961
+ this.payment = +record.payment;
1962
+ this.payment_reference = record.payment_reference;
1963
+ this.payment_description = record.payment_description;
1964
+ this.gateway_transaction_id = record.gateway_transaction_id;
1965
+ this.address = new EsolveTransactionAddress(record.recipient, record.address_type, record.address_description, record.street_number, record.street, record.suburb, record.city, record.province, record.country, record.postal_code, record.pobox);
1966
+ if (record.user) {
1967
+ this.user = new EsolveTransactionUser(+record.user.id, record.user.email, record.user.firstname, record.user.surname, record.user.telnumber, record.user.cellnumber);
1646
1968
  }
1647
- return hotspots;
1648
- }
1649
- processBannerImages(image_records, banner_type) {
1650
- const images = [];
1651
- if (image_records.length > 0) {
1652
- for (const image_record of image_records) {
1653
- const image = new EsolveBannerImage(+image_record.id, image_record.image_type, +image_record.width, +image_record.height, image_record.filename);
1654
- if ((banner_type === 'hotspot') && (image_record.hotspots)) {
1655
- const hotspots = this.processBannerImageHotspots(image_record.hotspots);
1656
- image.hotspots = hotspots;
1657
- }
1658
- images.push(image);
1659
- }
1969
+ if (record.client) {
1970
+ this.client = new EsolveTransactionClient(+record.client.id, record.client.account, record.client.company_name, record.client.branch_code, record.client.email, record.client.firstname, record.client.surname, record.client.contact_number);
1660
1971
  }
1661
- return images;
1972
+ if (record.location_details) {
1973
+ this.location = new EsolveTransactionLocation(record.location_details);
1974
+ }
1975
+ if (record.payment_method_details) {
1976
+ this.payment_method = new EsolveTransactionPaymentMethod(record.payment_method_details.id, record.payment_method_details.paymethod_name, record.payment_method_details.description, record.payment_method_details.integration_type, record.payment_method_details.service_provider);
1977
+ }
1978
+ if (record.shipping_method_details) {
1979
+ this.shipping_method = new EsolveTransactionShippingMethod(+record.shipping_method_details.id, record.shipping_method_details.carrier_name, record.shipping_method_details.delivery_category, record.shipping_method_details.location, record.shipping_method_details.description, record.shipping_method_details.pricing, !!record.shipping_method_details.client_to_collect);
1980
+ }
1981
+ this.parseTransactionItems(record.transaction_items);
1662
1982
  }
1663
- /**
1664
- * Process banner records into banner objects
1665
- * @param records Array of records
1666
- * @returns List of banners
1667
- */
1668
- processBanners(records) {
1669
- const banners = [];
1670
- if ((records) && (records.length > 0)) {
1671
- for (const record of records) {
1672
- const image_sets = {};
1673
- if (record.images.desktop) {
1674
- image_sets.desktop = this.processBannerImages(record.images.desktop, record.type);
1675
- }
1676
- if (record.images.mobile) {
1677
- image_sets.mobile = this.processBannerImages(record.images.mobile, record.type);
1678
- }
1679
- if (record.images.sub) {
1680
- image_sets.sub = this.processBannerImages(record.images.sub, record.type);
1681
- }
1682
- const banner = new EsolveBanner(+record.id, record.banner_display_container, record.identifier, record.type, record.title, record.article, +record.sort_priority, {
1683
- url: record.link.url,
1684
- target: record.link.target
1685
- }, image_sets);
1686
- banners.push(banner);
1687
- }
1983
+ parseTransactionItems(record_items) {
1984
+ for (const record_item of record_items) {
1985
+ const price = new EsolveTransactionItemPrice(+record_item.price_exclusive, +record_item.price_inclusive, +record_item.price_exclusive_after_discount, +record_item.price_inclusive_after_discount);
1986
+ const line_total = new EsolveTransactionItemPrice(+record_item.line_total_exclusive, +record_item.line_total_inclusive, +record_item.line_total_exclusive_after_discount, +record_item.line_total_inclusive_after_discount);
1987
+ const item = new EsolveTransactionItem(record_item.code, record_item.name, +record_item.qty, +record_item.discount, +record_item.vat_rate, price, line_total);
1988
+ this.items.push(item);
1688
1989
  }
1689
- return banners;
1690
1990
  }
1691
- }
1692
- EsolveBannerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveBannerService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1693
- EsolveBannerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveBannerService, providedIn: 'root' });
1694
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveBannerService, decorators: [{
1695
- type: Injectable,
1696
- args: [{
1697
- providedIn: 'root',
1698
- }]
1699
- }], ctorParameters: function () {
1700
- return [{ type: undefined, decorators: [{
1701
- type: Inject,
1702
- args: [ESOLVE_CONNECT_CONFIG]
1703
- }] }, { type: i1$2.HttpClient }];
1704
- } });
1991
+ }
1705
1992
 
1706
- // Types
1993
+ class EsolveTransactionList extends EsolveList {
1994
+ }
1707
1995
 
1708
- class EsolveHeading {
1709
- constructor(identifier, value) {
1710
- this.identifier = identifier;
1711
- this.value = value;
1996
+ // Classes
1997
+
1998
+ class EsolveChangePasswordResult extends EsolveResponseResult {
1999
+ constructor(response) {
2000
+ super(response);
2001
+ this.password_updated = (response.status.state === 'success');
1712
2002
  }
1713
2003
  }
1714
2004
 
1715
- class EsolveMediaArticle {
1716
- constructor(identifier, title, article, image_url = '', tags = [], topics = [], seo_title = '', seo_keywords = '', seo_description = '') {
1717
- this.identifier = identifier;
1718
- this.title = title;
1719
- this.article = article;
1720
- this.image_url = image_url;
1721
- this.tags = tags;
1722
- this.topics = topics;
1723
- if (seo_title.trim() === '') {
1724
- seo_title = this.title;
1725
- }
1726
- this.seo_details = new EsolveSeoInfo(seo_title, seo_description, seo_keywords);
2005
+ class EsolveResetPasswordResult extends EsolveResponseResult {
2006
+ constructor(response) {
2007
+ super(response);
2008
+ this.id = response.esolve_id;
2009
+ this.reset_success = response.reset_success;
2010
+ this.password_matches_old = response.password_matches_old;
2011
+ this.login_required = response.login_required;
1727
2012
  }
1728
2013
  }
1729
2014
 
1730
- class EsolveTag {
1731
- constructor(id, tag_phrase, tag_weight, description) {
1732
- this.id = id;
1733
- this.tag_phrase = tag_phrase;
1734
- this.tag_weight = tag_weight;
1735
- this.description = description;
2015
+ class EsolveRegistrationResult extends EsolveResponseResult {
2016
+ constructor(response) {
2017
+ super(response);
2018
+ this.user_id = response.esolve_id;
2019
+ this.guest = response.guest;
2020
+ this.auto_login = response.auto_login;
2021
+ this.authentication_required = response.authentication_required;
2022
+ this.location_id = response.session_data.location_id;
1736
2023
  }
1737
2024
  }
1738
2025
 
1739
- class EsolveTopic {
1740
- constructor(id, name, short_description, sort_priority) {
1741
- this.id = id;
1742
- this.name = name;
1743
- this.short_description = short_description;
1744
- this.sort_priority = sort_priority;
2026
+ class EsolveLocationUpdateResult extends EsolveResponseResult {
2027
+ constructor(response) {
2028
+ super(response);
2029
+ this.location_updated = (response.esolve_id > 0);
1745
2030
  }
1746
2031
  }
1747
2032
 
1748
- class EsolveTopicService {
1749
- constructor(config, http) {
2033
+ class EsolveAccountService {
2034
+ constructor(config, http, sessionService, errorHandler, responseHandler) {
1750
2035
  this.config = config;
1751
2036
  this.http = http;
2037
+ this.sessionService = sessionService;
2038
+ this.errorHandler = errorHandler;
2039
+ this.responseHandler = responseHandler;
2040
+ this._user_id = 0;
2041
+ this.sessionService.session.subscribe((session) => {
2042
+ if (session.key !== '') {
2043
+ this.user_id = session.id;
2044
+ }
2045
+ });
1752
2046
  }
1753
- /**
1754
- * Retrieves active topics from the list of topic ID's. Note that inactive or expired
1755
- * topics will not be retrieved.
1756
- *
1757
- * @param topic_id_list List of topic ID's that need to be retrieved
1758
- */
1759
- getTopics(topic_id_list = []) {
1760
- let params = new HttpParams();
1761
- if (topic_id_list.length > 0) {
1762
- params = params.append('topic_id', topic_id_list.join(','));
2047
+ get user_id() {
2048
+ return this._user_id;
2049
+ }
2050
+ set user_id(value) {
2051
+ value = ((value > 0) ? value : 0);
2052
+ if (this._user_id !== value) {
2053
+ this._user_id = value;
1763
2054
  }
1764
- return this.http.get(`${this.config.api_url}/get-topics.php`, { params }).pipe(map(response => {
1765
- if (response.records === undefined) {
2055
+ }
2056
+ updateUserAccount(user_account_data) {
2057
+ const body = {
2058
+ account: user_account_data
2059
+ };
2060
+ return this.http
2061
+ .post(`${this.config.api_url}/set-user-account.php`, body, {
2062
+ headers: {
2063
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
2064
+ },
2065
+ responseType: 'json',
2066
+ observe: 'body'
2067
+ })
2068
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => new EsolveUserAccountResult(response))), catchError((errorRes) => {
2069
+ return this.errorHandler.handleHttpPostError('set-user-account', errorRes);
2070
+ }));
2071
+ }
2072
+ getUserAccount() {
2073
+ return this.http
2074
+ .get(`${this.config.api_url}/get-account.php`)
2075
+ .pipe(map((response) => {
2076
+ if ((response.records === undefined) ||
2077
+ (response.records.length === 0)) {
1766
2078
  throw response;
1767
2079
  }
1768
- return this.processTopics(response.records);
2080
+ const record = response.records[0];
2081
+ return this.processUserAccount(record);
1769
2082
  }));
1770
2083
  }
1771
- processTopics(records) {
1772
- const topics = [];
1773
- if (records) {
1774
- for (const record of records) {
1775
- const topic = new EsolveTopic(+record.id, record.name, record.short_description, +record.sort_priority);
1776
- topics.push(topic);
2084
+ setAddress(address_post_data) {
2085
+ const body = {
2086
+ address: address_post_data
2087
+ };
2088
+ return this.http
2089
+ .post(`${this.config.api_url}/set-address.php`, body, {
2090
+ headers: {
2091
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
2092
+ },
2093
+ responseType: 'json',
2094
+ observe: 'body',
2095
+ })
2096
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => new EsolveAddressResult(response))), catchError((errorRes) => {
2097
+ return this.errorHandler.handleHttpPostError('set-registration', errorRes);
2098
+ }));
2099
+ }
2100
+ getAddresses() {
2101
+ try {
2102
+ this.loginGuard();
2103
+ return this.http
2104
+ .get(`${this.config.api_url}/get-addresses.php`, {
2105
+ params: { user_id: this.user_id }
2106
+ })
2107
+ .pipe(map((response) => {
2108
+ if (response.records === undefined) {
2109
+ throw response;
2110
+ }
2111
+ return this.processUserAddress(response.records);
2112
+ }));
2113
+ }
2114
+ catch (error) {
2115
+ return throwError(error);
2116
+ }
2117
+ }
2118
+ deleteAddress(id) {
2119
+ return this.http
2120
+ .delete(`${this.config.api_url}/delete-address.php`, {
2121
+ params: { id },
2122
+ responseType: 'json',
2123
+ observe: 'body'
2124
+ })
2125
+ .pipe(map((http_response) => {
2126
+ if ((http_response.result === undefined) ||
2127
+ (http_response.result === null) ||
2128
+ (http_response.result.status !== 'success')) {
2129
+ throw http_response;
2130
+ }
2131
+ return new EsolveResult(http_response.result.status, http_response.result.code, http_response.result.message);
2132
+ }), catchError((errorRes) => {
2133
+ return this.errorHandler.handleHttpDeleteError('delete-address', errorRes);
2134
+ }));
2135
+ }
2136
+ register(user_registration) {
2137
+ const body = {
2138
+ user: user_registration
2139
+ };
2140
+ return this.http
2141
+ .post(`${this.config.api_url}/set-registration.php`, body, {
2142
+ headers: {
2143
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
2144
+ },
2145
+ responseType: 'json',
2146
+ observe: 'body'
2147
+ })
2148
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
2149
+ if (response.auto_login) {
2150
+ this.sessionService.handleUpdateSession({
2151
+ user_id: +response.esolve_id,
2152
+ location_id: +response.session_data.location_id,
2153
+ });
1777
2154
  }
1778
- }
1779
- return topics;
2155
+ return new EsolveRegistrationResult(response);
2156
+ })), catchError((errorRes) => {
2157
+ return this.errorHandler.handleHttpPostError('set-registration', errorRes);
2158
+ }));
1780
2159
  }
1781
- }
1782
- EsolveTopicService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveTopicService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1783
- EsolveTopicService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveTopicService, providedIn: 'root' });
1784
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveTopicService, decorators: [{
1785
- type: Injectable,
1786
- args: [{
1787
- providedIn: 'root',
1788
- }]
1789
- }], ctorParameters: function () {
1790
- return [{ type: undefined, decorators: [{
1791
- type: Inject,
1792
- args: [ESOLVE_CONNECT_CONFIG]
1793
- }] }, { type: i1$2.HttpClient }];
1794
- } });
1795
-
1796
- class EsolveMediaService {
1797
- constructor(config, http) {
1798
- this.config = config;
1799
- this.http = http;
2160
+ changePassword(password, confirm_password) {
2161
+ const body = {
2162
+ password,
2163
+ confirm_password
2164
+ };
2165
+ return this.http
2166
+ .post(`${this.config.api_url}/set-change-password.php`, body, {
2167
+ headers: {
2168
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
2169
+ },
2170
+ responseType: 'json',
2171
+ observe: 'body'
2172
+ })
2173
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
2174
+ return new EsolveChangePasswordResult(response);
2175
+ })), catchError((errorRes) => {
2176
+ return this.errorHandler.handleHttpPostError('set-change-password', errorRes);
2177
+ }));
1800
2178
  }
1801
- /**
1802
- * Retrieves the media record from the eSolve instance using the identifier
1803
- *
1804
- * @param identifier String representing the eSolve media identifier
1805
- */
1806
- getMediaArticle(identifier) {
1807
- const params = new HttpParams({ fromObject: { identifier } });
1808
- // TODO: Error Handling
1809
- return this.getMediaRecords(params).pipe(map((response) => {
2179
+ sendForgotPasswordRequest(email) {
2180
+ return this.http
2181
+ .get(`${this.config.api_url}/get-forgot-password.php`, { params: { email } })
2182
+ .pipe(map((response) => {
1810
2183
  if ((response.records === undefined) ||
1811
- (response.records.length <= 0)) {
1812
- throw response;
1813
- }
1814
- const mediaRecord = response.records[0];
1815
- if (!mediaRecord.active) {
2184
+ !('reset_link_sent' in response.records)) {
1816
2185
  throw response;
1817
2186
  }
1818
- return this.processMediaRecord(mediaRecord);
2187
+ return response.records.reset_link_sent;
1819
2188
  }));
1820
2189
  }
1821
- /**
1822
- * Retrieves a group of media records from the eSolve instance linked to a group
1823
- *
1824
- * @param media_group String representing the eSolve media group
1825
- */
1826
- getGroupedMediaArticles(media_group) {
1827
- const params = new HttpParams({
1828
- fromObject: { media_group_sef: media_group }
1829
- });
1830
- return this.getMediaRecords(params).pipe(map((response) => {
1831
- const mediaArticles = [];
1832
- if ((response.records !== undefined) &&
1833
- (response.records.length > 0)) {
1834
- for (const mediaRecord of response.records) {
1835
- if (mediaRecord.active) {
1836
- mediaArticles.push(this.processMediaRecord(mediaRecord));
1837
- }
1838
- }
2190
+ resetPassword(reset_key, password, confirm_password, auto_login = true) {
2191
+ return this.http
2192
+ .post(`${this.config.api_url}/set-forgot-password.php`, {
2193
+ reset_key,
2194
+ password,
2195
+ confirm_password,
2196
+ auto_login
2197
+ }, {
2198
+ headers: {
2199
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
2200
+ },
2201
+ responseType: 'json',
2202
+ observe: 'body'
2203
+ })
2204
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
2205
+ if (!response.login_required) {
2206
+ this.sessionService.handleUpdateSession({
2207
+ user_id: +response.esolve_id,
2208
+ location_id: +response.session_data.location_id,
2209
+ });
1839
2210
  }
1840
- return mediaArticles;
2211
+ return new EsolveResetPasswordResult(response);
2212
+ })), catchError((errorRes) => {
2213
+ return this.errorHandler.handleHttpPostError('set-forgot-password', errorRes);
1841
2214
  }));
1842
2215
  }
1843
- /**
1844
- * Retrieves the media heading records from the eSolve instance using the identifiers
1845
- *
1846
- * @param identifiers Array of strings representing the eSolve heading identifiers
1847
- */
1848
- getHeadings(identifiers) {
2216
+ updateLocation(location_id) {
2217
+ const body = { location_id };
1849
2218
  return this.http
1850
- .get(`${this.config.api_url}/get-headings.php`, {
1851
- params: {
1852
- identifier: identifiers.join(','),
2219
+ .post(`${this.config.api_url}/set-session-location.php`, body, {
2220
+ headers: {
2221
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
1853
2222
  },
2223
+ responseType: 'json',
2224
+ observe: 'body',
1854
2225
  })
1855
- .pipe(map((response) => {
1856
- const headings = [];
1857
- if ((response.records !== undefined) &&
1858
- (response.records.length > 0)) {
1859
- for (const heading_record of response.records) {
1860
- headings.push(this.processHeadingRecord(heading_record));
1861
- }
1862
- }
1863
- return headings;
1864
- }));
2226
+ .pipe(map((http_response) => this.responseHandler.validateSingleHttpResponse(http_response, (response) => {
2227
+ this.sessionService.handleUpdateSession({ location_id });
2228
+ return new EsolveLocationUpdateResult(response);
2229
+ })));
1865
2230
  }
1866
- /**
1867
- * Processes media article record
1868
- *
1869
- * @param record Record from eSolve instance
1870
- */
1871
- processMediaRecord(record) {
1872
- const tags = [];
1873
- const topics = [];
1874
- if ((record.tags) && (record.tags.length > 0)) {
1875
- for (const tag of record.tags) {
1876
- tags.push(new EsolveTag(+tag.id, tag.tag_phrase, +tag.tag_weight, tag.description));
1877
- }
2231
+ getTransactions(options = {}) {
2232
+ try {
2233
+ this.loginGuard();
2234
+ return this.http
2235
+ .get(`${this.config.api_url}/get-transactions.php`, {
2236
+ params: Object.assign({ user_id: this.user_id }, options)
2237
+ })
2238
+ .pipe(map((response) => {
2239
+ var _a, _b;
2240
+ if (response.records === undefined) {
2241
+ throw response;
2242
+ }
2243
+ const items = this.processTransactions(response.records);
2244
+ const total = (_a = +response.additional_data.total_records) !== null && _a !== void 0 ? _a : 0;
2245
+ const rows = (_b = options.rows) !== null && _b !== void 0 ? _b : total;
2246
+ const page = options.page || 1;
2247
+ return new EsolveTransactionList(items, page, rows, total);
2248
+ }));
1878
2249
  }
1879
- if ((record.topics) && (record.topics.length > 0)) {
1880
- for (const topic of record.topics) {
1881
- topics.push(new EsolveTopic(+topic.id, topic.name, topic.short_description, +topic.sort_priority));
1882
- }
2250
+ catch (error) {
2251
+ return throwError(error);
1883
2252
  }
1884
- return new EsolveMediaArticle(record.identifier, record.title, record.article, record.image_url, tags, topics, record.seo_page_title, record.seo_keywords, record.seo_description);
1885
- }
1886
- /**
1887
- * Processes media heading record
1888
- *
1889
- * @param record Record from eSolve instance
1890
- */
1891
- processHeadingRecord(record) {
1892
- return new EsolveHeading(record.identifier, record.value);
1893
- }
1894
- /**
1895
- * Retrieves media records from eSolve instance.
1896
- *
1897
- * @param params HTTP params
1898
- */
1899
- getMediaRecords(params) {
1900
- return this.http.get(`${this.config.api_url}/get-media.php`, { params });
1901
- }
1902
- }
1903
- EsolveMediaService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMediaService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1904
- EsolveMediaService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMediaService, providedIn: 'root' });
1905
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMediaService, decorators: [{
1906
- type: Injectable,
1907
- args: [{
1908
- providedIn: 'root',
1909
- }]
1910
- }], ctorParameters: function () {
1911
- return [{ type: undefined, decorators: [{
1912
- type: Inject,
1913
- args: [ESOLVE_CONNECT_CONFIG]
1914
- }] }, { type: i1$2.HttpClient }];
1915
- } });
1916
-
1917
- class EsolveMenuItem {
1918
- constructor(url, name, target, children = []) {
1919
- this.url = url;
1920
- this.name = name;
1921
- this.target = target;
1922
- this.children = children;
1923
2253
  }
1924
- }
1925
-
1926
- class EsolveMenuService {
1927
- constructor(config, http) {
1928
- this.config = config;
1929
- this.http = http;
2254
+ getTransaction(id) {
2255
+ try {
2256
+ this.loginGuard();
2257
+ return this.http
2258
+ .get(`${this.config.api_url}/get-transactions.php`, {
2259
+ params: {
2260
+ user_id: this.user_id,
2261
+ transaction_id: id,
2262
+ }
2263
+ })
2264
+ .pipe(map((response) => {
2265
+ if ((response.records === undefined) ||
2266
+ (response.records.length <= 0)) {
2267
+ throw response;
2268
+ }
2269
+ const items = this.processTransactions(response.records);
2270
+ return items[0];
2271
+ }));
2272
+ }
2273
+ catch (error) {
2274
+ return throwError(error);
2275
+ }
1930
2276
  }
1931
- getMenuTree(identifier) {
1932
- return this.http
1933
- .get(`${this.config.api_url}/get-menu-tree.php`, { params: { identifier } })
1934
- .pipe(map((response) => {
1935
- if ((!response) || (response.records === undefined)) {
1936
- throw response;
1937
- }
1938
- else if (response.records.length === 0) {
1939
- return [];
2277
+ processUserAccount(record) {
2278
+ if (!record) {
2279
+ throw new Error('Invalid record');
2280
+ }
2281
+ if (+record.userid !== this._user_id) {
2282
+ throw new Error('Invalid user account retrieved');
2283
+ }
2284
+ const user_account = new EsolveUserAccount(+record.userid, record.email, record.registration_type, record.title, record.firstname, record.surname, record.initials, record.gender, record.idnumber);
2285
+ user_account.contact_details = new EsolveUserAccountContact(record.telnumber, record.cellnumber, record.fax);
2286
+ user_account.business_details = new EsolveUserAccountBusiness(record.busname, record.vatnum, record.busdescript, record.business_type);
2287
+ return user_account;
2288
+ }
2289
+ processUserAddress(records) {
2290
+ const user_addresses = [];
2291
+ if (!records || (this._user_id === 0)) {
2292
+ return user_addresses;
2293
+ }
2294
+ for (const record of records) {
2295
+ if (+record.userid !== this._user_id) {
2296
+ continue;
1940
2297
  }
1941
- return this.handleMenu(response.records);
1942
- }));
2298
+ user_addresses.push(new EsolveAddress(+record.id, record.recipient, record.address_type, record.pobox, record.place_name, record.street_number, record.street, record.suburb, record.city, record.province, record.country, record.postal_code, +record.latitude, +record.longitude));
2299
+ }
2300
+ return user_addresses;
1943
2301
  }
1944
- handleMenu(records) {
1945
- const menu = [];
1946
- if (typeof records !== 'undefined') {
1947
- for (const menuTreeRecord of records) {
1948
- menu.push(new EsolveMenuItem(menuTreeRecord.sef_url, menuTreeRecord.name, menuTreeRecord.target, this.handleMenu(menuTreeRecord.children)));
2302
+ processTransactions(records) {
2303
+ const transactions = [];
2304
+ if (records) {
2305
+ for (const record of records) {
2306
+ const transaction = new EsolveTransaction(record);
2307
+ transactions.push(transaction);
1949
2308
  }
1950
2309
  }
1951
- return menu;
2310
+ return transactions;
2311
+ }
2312
+ loginGuard() {
2313
+ if (this.user_id <= 0) {
2314
+ this.errorHandler.throwError('login_required', 'Login is required');
2315
+ }
1952
2316
  }
1953
2317
  }
1954
- EsolveMenuService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMenuService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1955
- EsolveMenuService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMenuService, providedIn: 'root' });
1956
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMenuService, decorators: [{
2318
+ EsolveAccountService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAccountService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }, { token: EsolveSessionService }, { token: EsolveErrorHandlerService }, { token: EsolveResponseHandlerService }], target: i0.ɵɵFactoryTarget.Injectable });
2319
+ EsolveAccountService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAccountService, providedIn: 'root' });
2320
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveAccountService, decorators: [{
1957
2321
  type: Injectable,
1958
2322
  args: [{
1959
2323
  providedIn: 'root',
@@ -1962,319 +2326,287 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
1962
2326
  return [{ type: undefined, decorators: [{
1963
2327
  type: Inject,
1964
2328
  args: [ESOLVE_CONNECT_CONFIG]
1965
- }] }, { type: i1$2.HttpClient }];
2329
+ }] }, { type: i1$2.HttpClient }, { type: EsolveSessionService }, { type: EsolveErrorHandlerService }, { type: EsolveResponseHandlerService }];
1966
2330
  } });
1967
2331
 
1968
- class EsolveNewsGroup {
1969
- constructor(id, name, description, sef_name) {
1970
- this.id = id;
1971
- this.name = name;
1972
- this.description = description;
1973
- this.sef_name = sef_name;
1974
- }
1975
- }
1976
-
1977
- class EsolveNewsArticle {
1978
- constructor(id, title, sef_title, article, short_description, txdate, active, image, featured, author, seo_title = '', seo_keywords = '') {
2332
+ class EsolveBanner {
2333
+ constructor(id, banner_display_container, identifier, type, title, article, sort_priority, link, images) {
1979
2334
  this.id = id;
2335
+ this.banner_display_container = banner_display_container;
2336
+ this.identifier = identifier;
2337
+ this.type = type;
1980
2338
  this.title = title;
1981
- this.sef_title = sef_title;
1982
2339
  this.article = article;
1983
- this.short_description = short_description;
1984
- this.txdate = txdate;
1985
- this.active = active;
1986
- this.image = image;
1987
- this.featured = featured;
1988
- this.author = author;
1989
- if (seo_title.trim() === '') {
1990
- seo_title = this.title;
2340
+ this.sort_priority = sort_priority;
2341
+ this.link = link;
2342
+ this.desktop_images = [];
2343
+ this.mobile_images = [];
2344
+ this.sub_images = [];
2345
+ if (images.desktop) {
2346
+ this.desktop_images = images.desktop;
2347
+ }
2348
+ if (images.mobile) {
2349
+ this.mobile_images = images.mobile;
2350
+ }
2351
+ if (images.sub) {
2352
+ this.sub_images = images.sub;
1991
2353
  }
1992
- this.seo_details = new EsolveSeoInfo(seo_title, short_description, seo_keywords);
1993
2354
  }
1994
2355
  }
1995
2356
 
1996
- class EsolveNewsArticleList {
1997
- constructor(newsArticles, total, page) {
1998
- this.newsArticles = newsArticles;
1999
- this.total = total;
2000
- this.page = page;
2357
+ class EsolveBannerImage {
2358
+ constructor(id, image_type, width, height, filename, hotspots) {
2359
+ this.id = id;
2360
+ this.image_type = image_type;
2361
+ this.width = width;
2362
+ this.height = height;
2363
+ this.filename = filename;
2364
+ this.hotspots = hotspots;
2365
+ }
2366
+ get src() {
2367
+ return '/images/banners/' + this.filename;
2001
2368
  }
2002
2369
  }
2003
2370
 
2004
- class EsolveNewsArticleAuthor {
2005
- constructor(userid, email, firstname, surname) {
2006
- this.userid = userid;
2007
- this.email = email;
2008
- this.firstname = firstname;
2009
- this.surname = surname;
2371
+ class EsolveBannerImageHotspot {
2372
+ constructor(url, target, coords, coords_string) {
2373
+ this.url = url;
2374
+ this.target = target;
2375
+ this.coords = coords;
2376
+ this.coords_string = coords_string;
2010
2377
  }
2011
2378
  }
2012
2379
 
2013
- class EsolveNewsService {
2380
+ class EsolveBannerService {
2014
2381
  constructor(config, http) {
2015
2382
  this.config = config;
2016
2383
  this.http = http;
2017
2384
  }
2018
- getNewsArticle(identifier) {
2019
- const params = new HttpParams({ fromObject: { sef_title: identifier } });
2020
- return this.getNewsRecords(params).pipe(map(response => {
2021
- if ((response.records === undefined) ||
2022
- (response.records.length <= 0)) {
2023
- throw response;
2024
- }
2025
- const newsRecord = response.records[0];
2026
- if (!newsRecord.active) {
2027
- throw response;
2028
- }
2029
- return this.processNewsArticle(newsRecord);
2030
- }));
2031
- }
2032
- getNewsArticles(options) {
2033
- let params = new HttpParams();
2034
- if (options.news_group_id) {
2035
- params = params.set('news_group_id', options.news_group_id.toString());
2036
- }
2037
- else if (options.news_group_sef) {
2038
- params = params.set('news_group_sef', options.news_group_sef.toString());
2039
- }
2040
- if (options.page) {
2041
- params = params.set('page', options.page.toString());
2042
- }
2043
- if (options.rows) {
2044
- params = params.set('rows', options.rows.toString());
2045
- }
2046
- if (options.feature_only) {
2047
- params = params.set('feature_only', options.feature_only.toString());
2048
- }
2049
- if (options.manufacturers_id) {
2050
- params = params.set('manufacturers_id', options.manufacturers_id.toString());
2051
- }
2052
- if (options.ranges_id) {
2053
- params = params.set('ranges_id', options.ranges_id.toString());
2054
- }
2055
- if (options.from_date) {
2056
- params = params.set('from_date', options.from_date.toString());
2385
+ /**
2386
+ * Retrieves banners records from eSolve instance
2387
+ *
2388
+ * @returns An observable of eSolve banners.
2389
+ */
2390
+ getBanners(identifier, banner_display_container, enable_date_filter = false) {
2391
+ let params = new HttpParams({
2392
+ fromObject: { enable_date_filter }
2393
+ });
2394
+ if (identifier) {
2395
+ params = params.set('identifier', identifier);
2057
2396
  }
2058
- if (options.to_date) {
2059
- params = params.set('to_date', options.to_date.toString());
2397
+ if (banner_display_container) {
2398
+ params = params.set('banner_display_container', banner_display_container);
2060
2399
  }
2061
- return this.getNewsRecords(params).pipe(map(response => {
2062
- if (response.records === undefined) {
2063
- throw response;
2064
- }
2065
- const newsArticles = [];
2066
- response.records.forEach(newsArticleRecord => {
2067
- newsArticles.push(this.processNewsArticle(newsArticleRecord));
2068
- });
2069
- return new EsolveNewsArticleList(newsArticles, response.additional_data.total_records, options.page || 0);
2070
- }));
2071
- }
2072
- getNewsGroups() {
2073
2400
  return this.http
2074
- .get(`${this.config.api_url}/get-news-groups.php`)
2401
+ .get(`${this.config.api_url}/get-banners.php`, { params })
2075
2402
  .pipe(map((response) => {
2076
2403
  if (response.records === undefined) {
2077
2404
  throw response;
2078
2405
  }
2079
- const newsGroups = [];
2080
- response.records.forEach(newsGroupRecord => {
2081
- newsGroups.push(new EsolveNewsGroup(newsGroupRecord.id, newsGroupRecord.name, newsGroupRecord.description, newsGroupRecord.sef_name));
2082
- });
2083
- return newsGroups;
2406
+ return this.processBanners(response.records);
2084
2407
  }));
2085
2408
  }
2086
- processNewsArticle(newsRecord) {
2087
- const author = new EsolveNewsArticleAuthor(newsRecord.user.userid, newsRecord.user.email, newsRecord.user.firstname, newsRecord.user.surname);
2088
- return new EsolveNewsArticle(newsRecord.id, newsRecord.title, newsRecord.sef_title, newsRecord.article, newsRecord.short_description, newsRecord.txdate, newsRecord.active, newsRecord.image, newsRecord.featured, author, newsRecord.seo_page_title, newsRecord.seo_keywords);
2089
- }
2090
- getNewsRecords(params) {
2091
- return this.http.get(`${this.config.api_url}/get-news.php`, { params });
2092
- }
2093
- }
2094
- EsolveNewsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveNewsService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
2095
- EsolveNewsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveNewsService, providedIn: 'root' });
2096
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveNewsService, decorators: [{
2097
- type: Injectable,
2098
- args: [{
2099
- providedIn: 'root',
2100
- }]
2101
- }], ctorParameters: function () {
2102
- return [{ type: undefined, decorators: [{
2103
- type: Inject,
2104
- args: [ESOLVE_CONNECT_CONFIG]
2105
- }] }, { type: i1$2.HttpClient }];
2106
- } });
2107
-
2108
- class EsolveColour {
2109
- constructor(record) {
2110
- var _a, _b, _c;
2111
- this.id = (_a = record.id) !== null && _a !== void 0 ? _a : 0;
2112
- this.colour = (_b = record.colour) !== null && _b !== void 0 ? _b : '';
2113
- this.description = (_c = record.description) !== null && _c !== void 0 ? _c : '';
2114
- }
2115
- }
2116
-
2117
- class EsolveCategoryTreeItem {
2118
- constructor(type, esolve_id, parent_id, description, sef_description, short_description, sort_priority, active, display_only, image_name, seo_title, seo_keywords, seo_description, children) {
2119
- this.type = type;
2120
- this.esolve_id = esolve_id;
2121
- this.parent_id = parent_id;
2122
- this.description = description;
2123
- this.sef_description = sef_description;
2124
- this.short_description = short_description;
2125
- this.sort_priority = sort_priority;
2126
- this.active = active;
2127
- this.display_only = display_only;
2128
- this.image_name = image_name;
2129
- this.id = '';
2130
- this.image_path = '';
2131
- if (this.type === 'category') {
2132
- this.id = `<<CAT>>${this.esolve_id}`;
2133
- if (children != null) {
2134
- this.children = children;
2409
+ processBannerImageHotspots(hotspot_records) {
2410
+ const hotspots = [];
2411
+ if (hotspot_records.length > 0) {
2412
+ for (const hotspot_record of hotspot_records) {
2413
+ const hotspot = new EsolveBannerImageHotspot(hotspot_record.url, hotspot_record.target, hotspot_record.coords, hotspot_record.coords_string);
2414
+ hotspots.push(hotspot);
2135
2415
  }
2136
- this.image_path = '/images/categories/';
2137
2416
  }
2138
- else {
2139
- this.id = `<<SUB>>${this.esolve_id}`;
2140
- this.image_path = '/images/subcategories/';
2417
+ return hotspots;
2418
+ }
2419
+ processBannerImages(image_records, banner_type) {
2420
+ const images = [];
2421
+ if (image_records.length > 0) {
2422
+ for (const image_record of image_records) {
2423
+ const image = new EsolveBannerImage(+image_record.id, image_record.image_type, +image_record.width, +image_record.height, image_record.filename);
2424
+ if ((banner_type === 'hotspot') && (image_record.hotspots)) {
2425
+ const hotspots = this.processBannerImageHotspots(image_record.hotspots);
2426
+ image.hotspots = hotspots;
2427
+ }
2428
+ images.push(image);
2429
+ }
2141
2430
  }
2142
- if (seo_title.trim() === '') {
2143
- seo_title = this.description;
2431
+ return images;
2432
+ }
2433
+ /**
2434
+ * Process banner records into banner objects
2435
+ * @param records Array of records
2436
+ * @returns List of banners
2437
+ */
2438
+ processBanners(records) {
2439
+ const banners = [];
2440
+ if ((records) && (records.length > 0)) {
2441
+ for (const record of records) {
2442
+ const image_sets = {};
2443
+ if (record.images.desktop) {
2444
+ image_sets.desktop = this.processBannerImages(record.images.desktop, record.type);
2445
+ }
2446
+ if (record.images.mobile) {
2447
+ image_sets.mobile = this.processBannerImages(record.images.mobile, record.type);
2448
+ }
2449
+ if (record.images.sub) {
2450
+ image_sets.sub = this.processBannerImages(record.images.sub, record.type);
2451
+ }
2452
+ const banner = new EsolveBanner(+record.id, record.banner_display_container, record.identifier, record.type, record.title, record.article, +record.sort_priority, {
2453
+ url: record.link.url,
2454
+ target: record.link.target
2455
+ }, image_sets);
2456
+ banners.push(banner);
2457
+ }
2144
2458
  }
2145
- this.seo_details = new EsolveSeoInfo(seo_title, seo_description, seo_keywords);
2146
- }
2147
- get small_image_src() {
2148
- return this.getImagePath('small');
2149
- }
2150
- get thumbnail_image_src() {
2151
- return this.getImagePath('thumb');
2459
+ return banners;
2152
2460
  }
2153
- get tiny_image_src() {
2154
- return this.getImagePath('tiny');
2461
+ }
2462
+ EsolveBannerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveBannerService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
2463
+ EsolveBannerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveBannerService, providedIn: 'root' });
2464
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveBannerService, decorators: [{
2465
+ type: Injectable,
2466
+ args: [{
2467
+ providedIn: 'root',
2468
+ }]
2469
+ }], ctorParameters: function () {
2470
+ return [{ type: undefined, decorators: [{
2471
+ type: Inject,
2472
+ args: [ESOLVE_CONNECT_CONFIG]
2473
+ }] }, { type: i1$2.HttpClient }];
2474
+ } });
2475
+
2476
+ // Types
2477
+
2478
+ class EsolveHeading {
2479
+ constructor(identifier, value) {
2480
+ this.identifier = identifier;
2481
+ this.value = value;
2155
2482
  }
2156
- getImagePath(image_size) {
2157
- if (this.image_name !== '') {
2158
- return `${this.image_path}${image_size}/${this.image_name}`;
2483
+ }
2484
+
2485
+ class EsolveMediaArticle {
2486
+ constructor(identifier, title, article, image_url = '', tags = [], topics = [], seo_title = '', seo_keywords = '', seo_description = '') {
2487
+ this.identifier = identifier;
2488
+ this.title = title;
2489
+ this.article = article;
2490
+ this.image_url = image_url;
2491
+ this.tags = tags;
2492
+ this.topics = topics;
2493
+ if (seo_title.trim() === '') {
2494
+ seo_title = this.title;
2159
2495
  }
2160
- return '';
2496
+ this.seo_details = new EsolveSeoInfo(seo_title, seo_description, seo_keywords);
2161
2497
  }
2162
2498
  }
2163
2499
 
2164
- class EsolveCategoryTreeService {
2500
+ class EsolveMediaService {
2165
2501
  constructor(config, http) {
2166
2502
  this.config = config;
2167
2503
  this.http = http;
2168
2504
  }
2169
2505
  /**
2170
- * Retrieves the category tree from eSolve instance and coverts it to the correct format.
2506
+ * Retrieves the media record from the eSolve instance using the identifier
2507
+ *
2508
+ * @param identifier String representing the eSolve media identifier
2171
2509
  */
2172
- getCategoryTree() {
2173
- return this.http
2174
- .get(`${this.config.api_url}/get-tree.php`)
2175
- .pipe(map((response) => {
2176
- if (response.records === undefined) {
2510
+ getMediaArticle(identifier) {
2511
+ const params = new HttpParams({ fromObject: { identifier } });
2512
+ // TODO: Error Handling
2513
+ return this.getMediaRecords(params).pipe(map((response) => {
2514
+ if ((response.records === undefined) ||
2515
+ (response.records.length <= 0)) {
2177
2516
  throw response;
2178
2517
  }
2179
- return this.processTree(response.records);
2518
+ const mediaRecord = response.records[0];
2519
+ if (!mediaRecord.active) {
2520
+ throw response;
2521
+ }
2522
+ return this.processMediaRecord(mediaRecord);
2180
2523
  }));
2181
2524
  }
2182
2525
  /**
2183
- * Retrieve the details of a category tree item from the eSolve instance and
2184
- * converts it to the correct format.
2526
+ * Retrieves a group of media records from the eSolve instance linked to a group
2185
2527
  *
2186
- * @param options Filter options
2528
+ * @param media_group String representing the eSolve media group
2187
2529
  */
2188
- getCategoryTreeItem(options) {
2189
- let type;
2190
- let esolve_id;
2191
- let sef_description;
2192
- if (options.id) {
2193
- const categoryIdentifier = this.processID(options.id);
2194
- if (categoryIdentifier) {
2195
- type = categoryIdentifier.type;
2196
- esolve_id = categoryIdentifier.esolve_id;
2530
+ getGroupedMediaArticles(media_group) {
2531
+ const params = new HttpParams({
2532
+ fromObject: { media_group_sef: media_group }
2533
+ });
2534
+ return this.getMediaRecords(params).pipe(map((response) => {
2535
+ const mediaArticles = [];
2536
+ if ((response.records !== undefined) &&
2537
+ (response.records.length > 0)) {
2538
+ for (const mediaRecord of response.records) {
2539
+ if (mediaRecord.active) {
2540
+ mediaArticles.push(this.processMediaRecord(mediaRecord));
2541
+ }
2542
+ }
2197
2543
  }
2198
- }
2199
- else if (options.type) {
2200
- type = options.type;
2201
- if (options.esolve_id) {
2202
- esolve_id = options.esolve_id;
2544
+ return mediaArticles;
2545
+ }));
2546
+ }
2547
+ /**
2548
+ * Retrieves the media heading records from the eSolve instance using the identifiers
2549
+ *
2550
+ * @param identifiers Array of strings representing the eSolve heading identifiers
2551
+ */
2552
+ getHeadings(identifiers) {
2553
+ return this.http
2554
+ .get(`${this.config.api_url}/get-headings.php`, {
2555
+ params: {
2556
+ identifier: identifiers.join(','),
2557
+ },
2558
+ })
2559
+ .pipe(map((response) => {
2560
+ const headings = [];
2561
+ if ((response.records !== undefined) &&
2562
+ (response.records.length > 0)) {
2563
+ for (const heading_record of response.records) {
2564
+ headings.push(this.processHeadingRecord(heading_record));
2565
+ }
2203
2566
  }
2204
- else if (options.sef_description) {
2205
- sef_description = options.sef_description;
2567
+ return headings;
2568
+ }));
2569
+ }
2570
+ /**
2571
+ * Processes media article record
2572
+ *
2573
+ * @param record Record from eSolve instance
2574
+ */
2575
+ processMediaRecord(record) {
2576
+ const tags = [];
2577
+ const topics = [];
2578
+ if ((record.tags) && (record.tags.length > 0)) {
2579
+ for (const tag of record.tags) {
2580
+ tags.push(new EsolveTag(tag));
2206
2581
  }
2207
2582
  }
2208
- if (type && (esolve_id || sef_description)) {
2209
- let params = new HttpParams();
2210
- params = params.set('type', type);
2211
- if (esolve_id) {
2212
- params = params.set('id', esolve_id);
2213
- }
2214
- if (sef_description) {
2215
- params = params.set('sef_description', sef_description);
2583
+ if ((record.topics) && (record.topics.length > 0)) {
2584
+ for (const topic of record.topics) {
2585
+ topics.push(new EsolveTopic(topic));
2216
2586
  }
2217
- return this.http
2218
- .get(`${this.config.api_url}/get-tree-item.php`, { params })
2219
- .pipe(map((response) => {
2220
- if ((response.records === undefined) ||
2221
- (response.records.length <= 0)) {
2222
- throw response;
2223
- }
2224
- return this.processTreeItem(response.records[0]);
2225
- }));
2226
2587
  }
2227
- return throwError('Invalid options');
2588
+ return new EsolveMediaArticle(record.identifier, record.title, record.article, record.image_url, tags, topics, record.seo_page_title, record.seo_keywords, record.seo_description);
2228
2589
  }
2229
2590
  /**
2230
- * Processes the eSolve tree records and converts them into the correct format.
2591
+ * Processes media heading record
2231
2592
  *
2232
- * @param tree_records Records to process
2593
+ * @param record Record from eSolve instance
2233
2594
  */
2234
- processTree(tree_records) {
2235
- const tree_items = [];
2236
- if (tree_records) {
2237
- for (const tree_record of tree_records) {
2238
- let esolve_id = '';
2239
- let parent_id = '';
2240
- let children = [];
2241
- if (tree_record.type === 'category') {
2242
- children = this.processTree(tree_record.children);
2243
- esolve_id = tree_record.menu_id;
2244
- parent_id = tree_record.owner_menu_id;
2245
- }
2246
- else {
2247
- esolve_id = tree_record.id;
2248
- parent_id = tree_record.menu_id;
2249
- }
2250
- tree_items.push(new EsolveCategoryTreeItem(tree_record.type, esolve_id, parent_id, tree_record.description, tree_record.sef_description, tree_record.seo_description, tree_record.sort_priority, tree_record.active, tree_record.display_only, tree_record.image, tree_record.seo_page_title, tree_record.seo_keywords, tree_record.short_description, children));
2251
- }
2252
- }
2253
- return tree_items;
2254
- }
2255
- processTreeItem(record) {
2256
- return new EsolveCategoryTreeItem(record.type, record.id, record.parent_id, record.description, record.sef_description, record.short_description, record.sort_priority, record.active, record.display_only, record.image, record.seo_page_title, record.seo_keywords, record.seo_description);
2595
+ processHeadingRecord(record) {
2596
+ return new EsolveHeading(record.identifier, record.value);
2257
2597
  }
2258
- processID(id) {
2259
- let type;
2260
- let esolve_id;
2261
- const type_code_regex = /^\<\<(CAT|SUB)\>\>/g;
2262
- const match_results = id.match(type_code_regex);
2263
- if (match_results) {
2264
- const type_code = match_results[0];
2265
- type = (type_code === '<<CAT>>' ? 'category' : 'subcategory');
2266
- esolve_id = id.replace(type_code_regex, '');
2267
- return {
2268
- type,
2269
- esolve_id
2270
- };
2271
- }
2272
- return null;
2598
+ /**
2599
+ * Retrieves media records from eSolve instance.
2600
+ *
2601
+ * @param params HTTP params
2602
+ */
2603
+ getMediaRecords(params) {
2604
+ return this.http.get(`${this.config.api_url}/get-media.php`, { params });
2273
2605
  }
2274
2606
  }
2275
- EsolveCategoryTreeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveCategoryTreeService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
2276
- EsolveCategoryTreeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveCategoryTreeService, providedIn: 'root' });
2277
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveCategoryTreeService, decorators: [{
2607
+ EsolveMediaService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMediaService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
2608
+ EsolveMediaService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMediaService, providedIn: 'root' });
2609
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMediaService, decorators: [{
2278
2610
  type: Injectable,
2279
2611
  args: [{
2280
2612
  providedIn: 'root',
@@ -2286,102 +2618,46 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
2286
2618
  }] }, { type: i1$2.HttpClient }];
2287
2619
  } });
2288
2620
 
2289
- class EsolveManufacturer {
2290
- constructor(id, manufacturer, sef_manufacturer, title, article, sort_priority, is_active, featured, image_name, seo_title = '', seo_keywords = '', seo_description = '') {
2291
- this.id = id;
2292
- this.manufacturer = manufacturer;
2293
- this.sef_manufacturer = sef_manufacturer;
2294
- this.title = title;
2295
- this.article = article;
2296
- this.sort_priority = sort_priority;
2297
- this.is_active = is_active;
2298
- this.featured = featured;
2299
- this.image_name = image_name;
2300
- this.image_path = '/images/manufacturers/';
2301
- if (this.title.trim() === '') {
2302
- this.title = this.manufacturer;
2303
- }
2304
- if (seo_title.trim() === '') {
2305
- seo_title = this.title;
2306
- }
2307
- this.seo_details = new EsolveSeoInfo(seo_title, seo_description, seo_keywords);
2308
- }
2309
- get original_image_src() {
2310
- return this.getImagePath('original');
2311
- }
2312
- get small_image_src() {
2313
- return this.getImagePath('small');
2314
- }
2315
- get thumbnail_image_src() {
2316
- return this.getImagePath('thumb');
2317
- }
2318
- get tiny_image_src() {
2319
- return this.getImagePath('tiny');
2320
- }
2321
- getImagePath(image_size) {
2322
- if (this.image_name !== '') {
2323
- return `${this.image_path}${image_size}/${this.image_name}`;
2324
- }
2325
- return '';
2621
+ class EsolveMenuItem {
2622
+ constructor(url, name, target, children = []) {
2623
+ this.url = url;
2624
+ this.name = name;
2625
+ this.target = target;
2626
+ this.children = children;
2326
2627
  }
2327
2628
  }
2328
2629
 
2329
- class EsolveManufacturersService {
2630
+ class EsolveMenuService {
2330
2631
  constructor(config, http) {
2331
2632
  this.config = config;
2332
2633
  this.http = http;
2333
2634
  }
2334
- getManufacturer(id) {
2335
- const params = new HttpParams({
2336
- fromObject: { manufacturers_id: id }
2337
- });
2338
- return this.getManufacturerSingle(params);
2339
- }
2340
- getManufacturerFromSEF(sef_manufacturer) {
2341
- const params = new HttpParams({
2342
- fromObject: { sef_manufacturer }
2343
- });
2344
- return this.getManufacturerSingle(params);
2345
- }
2346
- getManufacturers(options) {
2347
- let params = new HttpParams();
2348
- if (options === null || options === void 0 ? void 0 : options.featured_only) {
2349
- params = params.set('featured_only', options.featured_only);
2350
- }
2351
- return this.getManufacturerRecords(params).pipe(map((records) => {
2352
- const manufacturers = [];
2353
- for (const record of records) {
2354
- manufacturers.push(this.processManufacturer(record));
2355
- }
2356
- return manufacturers;
2357
- }), catchError(() => {
2358
- return of([]);
2359
- }));
2360
- }
2361
- getManufacturerSingle(params) {
2362
- return this.getManufacturerRecords(params).pipe(map((records) => {
2363
- const record = records[0];
2364
- return this.processManufacturer(record);
2365
- }));
2366
- }
2367
- getManufacturerRecords(params) {
2635
+ getMenuTree(identifier) {
2368
2636
  return this.http
2369
- .get(`${this.config.api_url}/get-manufacturers.php`, { params })
2637
+ .get(`${this.config.api_url}/get-menu-tree.php`, { params: { identifier } })
2370
2638
  .pipe(map((response) => {
2371
- if ((response.records === undefined) ||
2372
- (response.records.length <= 0)) {
2639
+ if ((!response) || (response.records === undefined)) {
2373
2640
  throw response;
2374
2641
  }
2375
- return response.records;
2642
+ else if (response.records.length === 0) {
2643
+ return [];
2644
+ }
2645
+ return this.handleMenu(response.records);
2376
2646
  }));
2377
2647
  }
2378
- processManufacturer(record) {
2379
- return new EsolveManufacturer(+record.id, record.manufacturer, record.sef_manufacturer, record.title, record.article, +record.sort_priority, !!+record.is_active, !!+record.featured, record.image_name, record.seo_page_title, record.seo_keywords, record.seo_description);
2648
+ handleMenu(records) {
2649
+ const menu = [];
2650
+ if (typeof records !== 'undefined') {
2651
+ for (const menuTreeRecord of records) {
2652
+ menu.push(new EsolveMenuItem(menuTreeRecord.sef_url, menuTreeRecord.name, menuTreeRecord.target, this.handleMenu(menuTreeRecord.children)));
2653
+ }
2654
+ }
2655
+ return menu;
2380
2656
  }
2381
2657
  }
2382
- EsolveManufacturersService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveManufacturersService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
2383
- EsolveManufacturersService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveManufacturersService, providedIn: 'root' });
2384
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveManufacturersService, decorators: [{
2658
+ EsolveMenuService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMenuService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
2659
+ EsolveMenuService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMenuService, providedIn: 'root' });
2660
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveMenuService, decorators: [{
2385
2661
  type: Injectable,
2386
2662
  args: [{
2387
2663
  providedIn: 'root',
@@ -2393,97 +2669,195 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
2393
2669
  }] }, { type: i1$2.HttpClient }];
2394
2670
  } });
2395
2671
 
2396
- class EsolveRange {
2397
- constructor(id, range, sef_range, manufacturers_id, title, article, is_active, featured, sort_priority, image_name, seo_title = '', seo_keywords = '', seo_description = '') {
2672
+ class EsolveNewsGroup {
2673
+ constructor(id, name, description, sef_name) {
2398
2674
  this.id = id;
2399
- this.range = range;
2400
- this.sef_range = sef_range;
2401
- this.manufacturers_id = manufacturers_id;
2402
- this.title = title;
2403
- this.article = article;
2404
- this.is_active = is_active;
2405
- this.featured = featured;
2406
- this.sort_priority = sort_priority;
2407
- this.image_name = image_name;
2408
- this.image_path = '/images/ranges/';
2409
- if (this.title.trim() === '') {
2410
- this.title = this.range;
2675
+ this.name = name;
2676
+ this.description = description;
2677
+ this.sef_name = sef_name;
2678
+ }
2679
+ }
2680
+
2681
+ class EsolveNewsArticleAuthor {
2682
+ constructor(userid, email, firstname, surname) {
2683
+ this.userid = userid;
2684
+ this.email = email;
2685
+ this.firstname = firstname;
2686
+ this.surname = surname;
2687
+ }
2688
+ }
2689
+
2690
+ class EsolveNewsArticle {
2691
+ constructor(record) {
2692
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2693
+ this.id = 0;
2694
+ this.title = '';
2695
+ this.sef_title = '';
2696
+ this.article = '';
2697
+ this.short_description = '';
2698
+ this.txdate = '';
2699
+ this.active = false;
2700
+ this.image = '';
2701
+ this.featured = false;
2702
+ this.topics = [];
2703
+ this.tags = [];
2704
+ let seo_title = '';
2705
+ let seo_description = '';
2706
+ let seo_keywords = '';
2707
+ if (record) {
2708
+ this.id = +((_a = record.id) !== null && _a !== void 0 ? _a : 0);
2709
+ this.title = (_b = record.title) !== null && _b !== void 0 ? _b : '';
2710
+ this.sef_title = (_c = record.sef_title) !== null && _c !== void 0 ? _c : '';
2711
+ this.article = (_d = record.article) !== null && _d !== void 0 ? _d : '';
2712
+ this.txdate = (_e = record.txdate) !== null && _e !== void 0 ? _e : '';
2713
+ this.image = (_f = record.image) !== null && _f !== void 0 ? _f : '';
2714
+ this.short_description = (_g = record.short_description) !== null && _g !== void 0 ? _g : '';
2715
+ if (record.active) {
2716
+ this.active = !!+record.active;
2717
+ }
2718
+ if (record.featured) {
2719
+ this.featured = !!+record.featured;
2720
+ }
2721
+ seo_title = (_h = record.seo_page_title) !== null && _h !== void 0 ? _h : '';
2722
+ seo_description = (_j = record.short_description) !== null && _j !== void 0 ? _j : '';
2723
+ seo_keywords = (_k = record.seo_keywords) !== null && _k !== void 0 ? _k : '';
2724
+ if (record.news_group) {
2725
+ const group_record = record.news_group;
2726
+ this.group = new EsolveNewsGroup(+group_record.id, group_record.name, group_record.description, group_record.sef_name);
2727
+ }
2728
+ if (record.user) {
2729
+ this.author = new EsolveNewsArticleAuthor(record.user.userid, record.user.email, record.user.firstname, record.user.surname);
2730
+ }
2731
+ if (record.manufacturer) {
2732
+ this.manufacturer = new EsolveManufacturer(record.manufacturer);
2733
+ }
2734
+ if (record.range) {
2735
+ this.range = new EsolveRange(record.range);
2736
+ }
2737
+ if (record.topics && record.topics.length > 0) {
2738
+ const topics = record.topics;
2739
+ for (const topic of topics) {
2740
+ this.topics.push(new EsolveTopic(topic));
2741
+ }
2742
+ }
2743
+ if (record.tags && record.tags.length > 0) {
2744
+ const tags = record.tags;
2745
+ for (const tag of tags) {
2746
+ this.tags.push(new EsolveTag(tag));
2747
+ }
2748
+ }
2411
2749
  }
2412
2750
  if (seo_title.trim() === '') {
2413
2751
  seo_title = this.title;
2414
2752
  }
2415
2753
  this.seo_details = new EsolveSeoInfo(seo_title, seo_description, seo_keywords);
2416
2754
  }
2417
- get image_src() {
2418
- return this.getImagePath();
2419
- }
2420
- getImagePath() {
2421
- if (this.image_name !== '') {
2422
- return `${this.image_path}${this.image_name}`;
2423
- }
2424
- return '';
2755
+ }
2756
+
2757
+ class EsolveNewsArticleList {
2758
+ constructor(newsArticles, total, page) {
2759
+ this.newsArticles = newsArticles;
2760
+ this.total = total;
2761
+ this.page = page;
2425
2762
  }
2426
2763
  }
2427
2764
 
2428
- class EsolveRangesService {
2765
+ class EsolveNewsService {
2429
2766
  constructor(config, http) {
2430
2767
  this.config = config;
2431
2768
  this.http = http;
2432
2769
  }
2433
- getRange(id) {
2434
- const params = new HttpParams({
2435
- fromObject: { ranges_id: id }
2436
- });
2437
- return this.getRangeSingle(params);
2438
- }
2439
- getRangeFromSEF(sef_range) {
2440
- const params = new HttpParams({
2441
- fromObject: { sef_range }
2442
- });
2443
- return this.getRangeSingle(params);
2444
- }
2445
- getRanges(options) {
2446
- let params = new HttpParams();
2447
- if (options === null || options === void 0 ? void 0 : options.featured_only) {
2448
- params = params.set('featured_only', options.featured_only);
2449
- }
2450
- if (options === null || options === void 0 ? void 0 : options.manufacturers_id) {
2451
- params = params.set('manufacturers_id', options.manufacturers_id);
2452
- }
2453
- return this.getRangeRecords(params).pipe(map((records) => {
2454
- const ranges = [];
2455
- for (const record of records) {
2456
- ranges.push(this.processRange(record));
2770
+ getNewsArticle(identifier) {
2771
+ const params = new HttpParams({ fromObject: { sef_title: identifier } });
2772
+ return this.getNewsRecords(params).pipe(map((response) => {
2773
+ if ((response.records === undefined) ||
2774
+ (response.records.length <= 0)) {
2775
+ throw response;
2457
2776
  }
2458
- return ranges;
2459
- }), catchError(() => {
2460
- return of([]);
2777
+ const record = response.records[0];
2778
+ if (!record.active) {
2779
+ throw response;
2780
+ }
2781
+ return this.processNewsArticle(record);
2461
2782
  }));
2462
2783
  }
2463
- getRangeSingle(params) {
2464
- return this.getRangeRecords(params).pipe(map((records) => {
2465
- const record = records[0];
2466
- return this.processRange(record);
2784
+ getNewsArticles(options) {
2785
+ const params = this.parseOptions(options);
2786
+ return this.getNewsRecords(params).pipe(map((response) => {
2787
+ var _a;
2788
+ if (response.records === undefined) {
2789
+ throw response;
2790
+ }
2791
+ const news_articles = [];
2792
+ for (const record of response.records) {
2793
+ news_articles.push(this.processNewsArticle(record));
2794
+ }
2795
+ const page = (_a = options === null || options === void 0 ? void 0 : options.page) !== null && _a !== void 0 ? _a : 0;
2796
+ const total_records = +response.additional_data.total_records;
2797
+ return new EsolveNewsArticleList(news_articles, total_records, page);
2467
2798
  }));
2468
2799
  }
2469
- getRangeRecords(params) {
2800
+ getNewsGroups() {
2470
2801
  return this.http
2471
- .get(`${this.config.api_url}/get-ranges.php`, { params })
2802
+ .get(`${this.config.api_url}/get-news-groups.php`)
2472
2803
  .pipe(map((response) => {
2473
- if ((response.records === undefined) ||
2474
- (response.records.length <= 0)) {
2804
+ if (response.records === undefined) {
2475
2805
  throw response;
2476
2806
  }
2477
- return response.records;
2807
+ const news_groups = [];
2808
+ for (const record of response.records) {
2809
+ news_groups.push(new EsolveNewsGroup(record.id, record.name, record.description, record.sef_name));
2810
+ }
2811
+ return news_groups;
2478
2812
  }));
2479
2813
  }
2480
- processRange(record) {
2481
- return new EsolveRange(+record.id, record.range, record.sef_range, record.manufacturers_id, record.title, record.article, !!+record.is_active, !!+record.featured, +record.sort_priority, record.image_name, record.seo_page_title, record.seo_keywords, record.seo_description);
2814
+ processNewsArticle(record) {
2815
+ return new EsolveNewsArticle(record);
2816
+ }
2817
+ getNewsRecords(params) {
2818
+ return this.http.get(`${this.config.api_url}/get-news.php`, { params });
2819
+ }
2820
+ parseOptions(options) {
2821
+ let params = new HttpParams();
2822
+ if (!options) {
2823
+ return params;
2824
+ }
2825
+ if (options.news_group_id) {
2826
+ params = params.set('news_group_id', options.news_group_id);
2827
+ }
2828
+ else if (options.news_group_sef) {
2829
+ params = params.set('news_group_sef', options.news_group_sef);
2830
+ }
2831
+ if (options.page) {
2832
+ params = params.set('page', options.page);
2833
+ }
2834
+ if (options.rows) {
2835
+ params = params.set('rows', options.rows);
2836
+ }
2837
+ if (options.feature_only) {
2838
+ params = params.set('feature_only', options.feature_only);
2839
+ }
2840
+ if (options.manufacturers_id) {
2841
+ params = params.set('manufacturers_id', options.manufacturers_id);
2842
+ }
2843
+ if (options.ranges_id) {
2844
+ params = params.set('ranges_id', options.ranges_id);
2845
+ }
2846
+ if (options.from_date) {
2847
+ params = params.set('from_date', options.from_date);
2848
+ }
2849
+ if (options.to_date) {
2850
+ params = params.set('to_date', options.to_date);
2851
+ }
2852
+ if (options.search_phrase) {
2853
+ params = params.set('search_phrase', options.search_phrase);
2854
+ }
2855
+ return params;
2482
2856
  }
2483
2857
  }
2484
- EsolveRangesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveRangesService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
2485
- EsolveRangesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveRangesService, providedIn: 'root' });
2486
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveRangesService, decorators: [{
2858
+ EsolveNewsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveNewsService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
2859
+ EsolveNewsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveNewsService, providedIn: 'root' });
2860
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: EsolveNewsService, decorators: [{
2487
2861
  type: Injectable,
2488
2862
  args: [{
2489
2863
  providedIn: 'root',
@@ -2495,6 +2869,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
2495
2869
  }] }, { type: i1$2.HttpClient }];
2496
2870
  } });
2497
2871
 
2872
+ // Types
2873
+
2874
+ class EsolveColour {
2875
+ constructor(record) {
2876
+ var _a, _b, _c;
2877
+ this.id = (_a = record.id) !== null && _a !== void 0 ? _a : 0;
2878
+ this.colour = (_b = record.colour) !== null && _b !== void 0 ? _b : '';
2879
+ this.description = (_c = record.description) !== null && _c !== void 0 ? _c : '';
2880
+ }
2881
+ }
2882
+
2498
2883
  class EsolveStockBadge {
2499
2884
  constructor(id, text, identifier, font_colour, badge_colour, sort_priority) {
2500
2885
  this.id = id;
@@ -2560,7 +2945,7 @@ class EsolveStockLeadTimes {
2560
2945
 
2561
2946
  class EsolveStockItemBase {
2562
2947
  constructor(record = {}) {
2563
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
2948
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
2564
2949
  /**
2565
2950
  * eSolve Generated ID
2566
2951
  */
@@ -2593,6 +2978,26 @@ class EsolveStockItemBase {
2593
2978
  * Featured state
2594
2979
  */
2595
2980
  this.featured = false;
2981
+ /**
2982
+ * Height measured in meters (m)
2983
+ */
2984
+ this.height = 0;
2985
+ /**
2986
+ * Width measured in meters (m)
2987
+ */
2988
+ this.width = 0;
2989
+ /**
2990
+ * Length / depth measured in meters (m)
2991
+ */
2992
+ this.length = 0;
2993
+ /**
2994
+ * Weight measured in kilograms (kg)
2995
+ */
2996
+ this.weight = 0;
2997
+ /**
2998
+ * Units used to measure the quantity
2999
+ */
3000
+ this.unit_of_measure = 'unit';
2596
3001
  /**
2597
3002
  * ID of default category linked to the stock item
2598
3003
  *
@@ -2657,18 +3062,25 @@ class EsolveStockItemBase {
2657
3062
  this.ranges_id = +((_l = record.ranges_id) !== null && _l !== void 0 ? _l : 0);
2658
3063
  this.active = !!+((_m = record.is_active) !== null && _m !== void 0 ? _m : false);
2659
3064
  this.featured = !!+((_o = record.is_featured) !== null && _o !== void 0 ? _o : false);
2660
- base_price = +((_p = record.regular_sellprice) !== null && _p !== void 0 ? _p : 0);
2661
- base_price_with_tax = +((_q = record.regular_sellprice_inclusive) !== null && _q !== void 0 ? _q : 0);
2662
- sell_price = +((_r = record.sellprice) !== null && _r !== void 0 ? _r : 0);
2663
- sell_price_with_tax = +((_s = record.sellprice_inclusive) !== null && _s !== void 0 ? _s : 0);
3065
+ this.height = +((_p = record.height) !== null && _p !== void 0 ? _p : 0);
3066
+ this.width = +((_q = record.width) !== null && _q !== void 0 ? _q : 0);
3067
+ this.length = +((_r = record.length) !== null && _r !== void 0 ? _r : 0);
3068
+ this.weight = +((_s = record.weight) !== null && _s !== void 0 ? _s : 0);
3069
+ if (record.unit_of_measure) {
3070
+ this.unit_of_measure = record.unit_of_measure;
3071
+ }
3072
+ base_price = +((_t = record.regular_sellprice) !== null && _t !== void 0 ? _t : 0);
3073
+ base_price_with_tax = +((_u = record.regular_sellprice_inclusive) !== null && _u !== void 0 ? _u : 0);
3074
+ sell_price = +((_v = record.sellprice) !== null && _v !== void 0 ? _v : 0);
3075
+ sell_price_with_tax = +((_w = record.sellprice_inclusive) !== null && _w !== void 0 ? _w : 0);
2664
3076
  if ((record.tags) && (record.tags.length > 0)) {
2665
3077
  for (const tag of record.tags) {
2666
- this.tags.push(new EsolveTag(+tag.id, tag.tag_phrase, +tag.tag_weight, tag.description));
3078
+ this.tags.push(new EsolveTag(tag));
2667
3079
  }
2668
3080
  }
2669
3081
  if ((record.topics) && (record.topics.length > 0)) {
2670
3082
  for (const topic of record.topics) {
2671
- this.topics.push(new EsolveTopic(+topic.id, topic.name, topic.short_description, +topic.sort_priority));
3083
+ this.topics.push(new EsolveTopic(topic));
2672
3084
  }
2673
3085
  }
2674
3086
  if ((record.badges) && (record.badges.length > 0)) {
@@ -2683,10 +3095,10 @@ class EsolveStockItemBase {
2683
3095
  this.subcategory = new EsolveCategoryTreeItem(record.subcategory.type, record.subcategory.id, record.subcategory.parent_id, record.subcategory.description, record.subcategory.sef_description, record.subcategory.short_description, record.subcategory.sort_priority, record.subcategory.active, record.subcategory.display_only, record.subcategory.image, record.subcategory.seo_page_title, record.subcategory.seo_keywords, record.subcategory.seo_description);
2684
3096
  }
2685
3097
  if (record.manufacturer) {
2686
- this.manufacturer = new EsolveManufacturer(record.manufacturer.id, record.manufacturer.manufacturer, record.manufacturer.sef_manufacturer, record.manufacturer.title, record.manufacturer.article, record.manufacturer.sort_priority, record.manufacturer.is_active, record.manufacturer.featured, record.manufacturer.image_name, record.manufacturer.seo_page_title, record.manufacturer.seo_keywords, record.manufacturer.seo_description);
3098
+ this.manufacturer = new EsolveManufacturer(record.manufacturer);
2687
3099
  }
2688
3100
  if (record.range) {
2689
- this.range = new EsolveRange(record.range.id, record.range.range, record.range.sef_range, record.range.manufacturers_id, record.range.title, record.range.article, record.range.is_active, record.range.featured, record.range.sort_priority, record.range.image_name, record.range.seo_page_title, record.range.seo_keywords, record.range.seo_description);
3101
+ this.range = new EsolveRange(record.range);
2690
3102
  }
2691
3103
  if (record.colours && record.colours.length > 0) {
2692
3104
  for (const colour of record.colours) {
@@ -2699,8 +3111,8 @@ class EsolveStockItemBase {
2699
3111
  if (record.custom_fields) {
2700
3112
  this.custom_fields = record.custom_fields;
2701
3113
  }
2702
- seo_title = (_t = record.seo_page_title) !== null && _t !== void 0 ? _t : '';
2703
- seo_keywords = (_u = record.seo_keywords) !== null && _u !== void 0 ? _u : '';
3114
+ seo_title = (_x = record.seo_page_title) !== null && _x !== void 0 ? _x : '';
3115
+ seo_keywords = (_y = record.seo_keywords) !== null && _y !== void 0 ? _y : '';
2704
3116
  }
2705
3117
  this.price = new EsolveStockPrice(base_price, base_price_with_tax, sell_price, sell_price_with_tax);
2706
3118
  if (seo_title.trim() === '') {
@@ -2906,8 +3318,12 @@ class EsolveStockImageCollection {
2906
3318
  }
2907
3319
  ;
2908
3320
 
3321
+ // Classes
3322
+
2909
3323
  ;
2910
3324
 
3325
+ // Interfaces
3326
+
2911
3327
  class EsolveStockService {
2912
3328
  constructor(config, http) {
2913
3329
  this.config = config;
@@ -2966,6 +3382,15 @@ class EsolveStockService {
2966
3382
  if (options.rows) {
2967
3383
  params = params.set('rows', options.rows);
2968
3384
  }
3385
+ if (options.sort) {
3386
+ const sort = options.sort;
3387
+ if (sort.field) {
3388
+ params = params.set('sort', sort.field);
3389
+ }
3390
+ if (sort.order) {
3391
+ params = params.set('order', sort.order);
3392
+ }
3393
+ }
2969
3394
  if (options.search_phrase) {
2970
3395
  params = params.set('search_phrase', options.search_phrase);
2971
3396
  }
@@ -3034,9 +3459,27 @@ class EsolveStockService {
3034
3459
  *
3035
3460
  * @param code Stock item code
3036
3461
  */
3037
- getRecipeItems(code) {
3462
+ getRecipeItems(code, options) {
3463
+ let params = new HttpParams().set('code', code);
3464
+ if (options) {
3465
+ if (options.page) {
3466
+ params = params.set('page', options.page);
3467
+ }
3468
+ if (options.rows) {
3469
+ params = params.set('rows', options.rows);
3470
+ }
3471
+ if (options.sort) {
3472
+ const sort = options.sort;
3473
+ if (sort.field) {
3474
+ params = params.set('sort', sort.field);
3475
+ }
3476
+ if (sort.order) {
3477
+ params = params.set('order', sort.order);
3478
+ }
3479
+ }
3480
+ }
3038
3481
  return this.http
3039
- .get(`${this.config.api_url}/get-recipe-items.php`, { params: { code } })
3482
+ .get(`${this.config.api_url}/get-recipe-items.php`, { params })
3040
3483
  .pipe(map((response) => {
3041
3484
  if ((response.records === undefined) ||
3042
3485
  (response.records.length <= 0)) {
@@ -3062,6 +3505,15 @@ class EsolveStockService {
3062
3505
  is_active: (_f = options.is_active) !== null && _f !== void 0 ? _f : true,
3063
3506
  },
3064
3507
  });
3508
+ if (options.sort) {
3509
+ const sort = options.sort;
3510
+ if (sort.field) {
3511
+ params = params.set('sort', sort.field);
3512
+ }
3513
+ if (sort.order) {
3514
+ params = params.set('order', sort.order);
3515
+ }
3516
+ }
3065
3517
  if (options.media_identifier) {
3066
3518
  params = params.append('media_identifier', options.media_identifier);
3067
3519
  }
@@ -3167,8 +3619,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
3167
3619
  }] }, { type: i1$2.HttpClient }];
3168
3620
  } });
3169
3621
 
3170
- // Types
3171
-
3172
3622
  class EsolveSpecialImage {
3173
3623
  constructor(record) {
3174
3624
  this.id = +record.id;
@@ -4094,5 +4544,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
4094
4544
  * Generated bundle index. Do not edit.
4095
4545
  */
4096
4546
 
4097
- export { EsolveAccountService, EsolveAdditionalStockImage, EsolveAddress, EsolveAddressResult, EsolveAuthService, EsolveBankingDetails, EsolveBanner, EsolveBannerImage, EsolveBannerImageHotspot, EsolveBannerService, EsolveCartItem, EsolveCartService, EsolveCartStockItem, EsolveCartTotals, EsolveCategoryTreeItem, EsolveCategoryTreeService, EsolveChangePasswordResult, EsolveCheckoutResult, EsolveColour, EsolveCookieService, EsolveEnquiryResult, EsolveEnquiryService, EsolveErrorHandlerService, EsolveGeocodeAddressResult, EsolveGeocodeCoordsResult, EsolveGeocodeResult, EsolveGeocoderService, EsolveHeading, EsolveHttpError, EsolveLinkedAsset, EsolveLinkedStockItem, EsolveList, EsolveLocation, EsolveLocationAddress, EsolveLocationContactInfo, EsolveLocationPOBoxAddress, EsolveLocationTradingDay, EsolveLocationTradingTimes, EsolveLocationsService, EsolveManufacturer, EsolveManufacturersService, EsolveMediaArticle, EsolveMediaService, EsolveMediaStockItem, EsolveMenuItem, EsolveMenuService, EsolveNewsArticle, EsolveNewsArticleAuthor, EsolveNewsArticleList, EsolveNewsGroup, EsolveNewsService, EsolvePaymentMethod, EsolvePaymentResult, EsolvePaymentService, EsolveRange, EsolveRangesService, EsolveRecipeStockItem, EsolveRegistrationResult, EsolveResetPasswordResult, EsolveResponseHandlerService, EsolveResponseResult, EsolveResult, EsolveSeoInfo, EsolveSeoService, EsolveSession, EsolveSessionService, EsolveShippingCost, EsolveShippingMethod, EsolveShippingService, EsolveShippingTotals, EsolveSpecial, EsolveSpecialImage, EsolveSpecialImageCollection, EsolveSpecialsService, EsolveStockBadge, EsolveStockGroup, EsolveStockGroupItem, EsolveStockImage, EsolveStockImageCollection, EsolveStockItem, EsolveStockItemBase, EsolveStockItemList, EsolveStockLeadTimes, EsolveStockPrice, EsolveStockService, EsolveTag, EsolveTopic, EsolveTopicService, EsolveTransaction, EsolveTransactionAddress, EsolveTransactionClient, EsolveTransactionItem, EsolveTransactionItemPrice, EsolveTransactionList, EsolveTransactionLocation, EsolveTransactionPaymentMethod, EsolveTransactionShippingMethod, EsolveTransactionUser, EsolveUserAccount, EsolveUserAccountBusiness, EsolveUserAccountContact, EsolveUserAccountResult, EsolveVaultItem, EsolveVaultItemResult, NgEsolveConnectModule };
4547
+ export { EsolveAccountService, EsolveAdditionalStockImage, EsolveAddress, EsolveAddressResult, EsolveAsset, EsolveAssetsService, EsolveAuthService, EsolveBankingDetails, EsolveBanner, EsolveBannerImage, EsolveBannerImageHotspot, EsolveBannerService, EsolveCartItem, EsolveCartService, EsolveCartStockItem, EsolveCartTotals, EsolveCategoryTreeItem, EsolveCategoryTreeService, EsolveChangePasswordResult, EsolveCheckoutResult, EsolveColour, EsolveCookieService, EsolveEnquiryResult, EsolveEnquiryService, EsolveErrorHandlerService, EsolveGeocodeAddressResult, EsolveGeocodeCoordsResult, EsolveGeocodeResult, EsolveGeocoderService, EsolveHeading, EsolveHttpError, EsolveLinkedAsset, EsolveLinkedStockItem, EsolveList, EsolveLocation, EsolveLocationAddress, EsolveLocationContactInfo, EsolveLocationPOBoxAddress, EsolveLocationTradingDay, EsolveLocationTradingTimes, EsolveLocationsService, EsolveManufacturer, EsolveManufacturersService, EsolveMediaArticle, EsolveMediaService, EsolveMediaStockItem, EsolveMenuItem, EsolveMenuService, EsolveNewsArticle, EsolveNewsArticleAuthor, EsolveNewsArticleList, EsolveNewsGroup, EsolveNewsService, EsolvePaymentMethod, EsolvePaymentResult, EsolvePaymentService, EsolveRange, EsolveRangesService, EsolveRecipeStockItem, EsolveRegistrationResult, EsolveResetPasswordResult, EsolveResponseHandlerService, EsolveResponseResult, EsolveResult, EsolveSeoInfo, EsolveSeoService, EsolveSession, EsolveSessionService, EsolveShippingCost, EsolveShippingMethod, EsolveShippingService, EsolveShippingTotals, EsolveSpecial, EsolveSpecialImage, EsolveSpecialImageCollection, EsolveSpecialsService, EsolveStockBadge, EsolveStockGroup, EsolveStockGroupItem, EsolveStockImage, EsolveStockImageCollection, EsolveStockItem, EsolveStockItemBase, EsolveStockItemList, EsolveStockLeadTimes, EsolveStockPrice, EsolveStockService, EsolveTag, EsolveTagsService, EsolveTopic, EsolveTopicService, EsolveTransaction, EsolveTransactionAddress, EsolveTransactionClient, EsolveTransactionItem, EsolveTransactionItemPrice, EsolveTransactionList, EsolveTransactionLocation, EsolveTransactionPaymentMethod, EsolveTransactionShippingMethod, EsolveTransactionUser, EsolveUserAccount, EsolveUserAccountBusiness, EsolveUserAccountContact, EsolveUserAccountResult, EsolveVaultItem, EsolveVaultItemResult, NgEsolveConnectModule };
4098
4548
  //# sourceMappingURL=esolve-ng-esolve-connect.mjs.map