@veloceapps/sdk 3.1.19 → 3.1.21

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.
@@ -458,11 +458,6 @@
458
458
  this.sfApiService = sfApiService;
459
459
  this.quoteSubj$ = new rxjs.BehaviorSubject(null);
460
460
  this.resetSubj$ = new rxjs.BehaviorSubject(true);
461
- /**
462
- * @key pricePlanId
463
- * @value priceListId
464
- */
465
- this.planIdsMap = {};
466
461
  this.isInitialized = false;
467
462
  this.allPriceLists = [];
468
463
  this.assetPriceLists = [];
@@ -481,7 +476,10 @@
481
476
  _this.allPriceLists = allPriceLists;
482
477
  _this.quoteSubj$.next(quote);
483
478
  _this.context.update(Object.assign(Object.assign(Object.assign({}, context), quote.context), { properties: Object.assign(Object.assign({}, context.properties), quote.context.properties) }));
484
- }), operators.switchMap(function () { return _this.populateActivePriceLists$(); }), operators.map(function () { return rxjs.noop(); }), operators.tap(function () { return (_this.isInitialized = true); }), operators.take(1));
479
+ }), operators.tap(function () {
480
+ _this.populateActivePriceLists$();
481
+ _this.isInitialized = true;
482
+ }), operators.map(function () { return rxjs.noop(); }), operators.take(1));
485
483
  };
486
484
  QuoteDraftService.prototype.setCurrentLineItemState = function (lineItems) {
487
485
  var quoteDraft = this.quoteSubj$.value;
@@ -625,61 +623,42 @@
625
623
  QuoteDraftService.prototype.updateActivePriceList = function (priceListId) {
626
624
  this.context.update({ properties: { PriceListId: priceListId } });
627
625
  };
628
- /**
629
- * Query PricePlan infos for the assets
630
- * TODO: remove when backend will send priceListId for assets
631
- */
632
- QuoteDraftService.prototype.getAssetsPlanInfos$ = function (quoteDraft) {
633
- var _a;
634
- var pricePlanIds = (_a = quoteDraft === null || quoteDraft === void 0 ? void 0 : quoteDraft.initialState.map(function (li) { return li.planId; }).filter(function (id) { return typeof id === 'string'; }).filter(function (item, i, arr) { return arr.indexOf(item) === i; })) !== null && _a !== void 0 ? _a : [];
635
- if (!pricePlanIds.length) {
636
- return rxjs.of([]);
637
- }
638
- var priceListIdFieldName = 'VELOCPQ__PriceListId__c';
639
- var searchRequest = {
640
- rawCondition: "Id in ('" + pricePlanIds.join("','") + "')",
641
- fields: ['Id', priceListIdFieldName],
642
- };
643
- return this.sfApiService
644
- .query(searchRequest, 'VELOCPQ__PricePlan__c')
645
- .pipe(operators.map(function (result) { return result.map(function (item) { return ({ id: item.Id, priceListId: item[priceListIdFieldName] }); }).filter(Boolean); }));
646
- };
647
626
  QuoteDraftService.prototype.populateActivePriceLists$ = function () {
648
627
  var _this = this;
649
628
  var ctx = this.context.resolve();
650
629
  var quoteDraft = this.quoteDraft;
651
630
  if (!quoteDraft) {
652
- return rxjs.of(undefined);
631
+ return;
653
632
  }
654
633
  // In ACCOUNT mode populate price lists from related assets
655
634
  if (ctx.mode === core.ConfigurationContextMode.ACCOUNT) {
656
- return this.getAssetsPlanInfos$(quoteDraft).pipe(operators.tap(function (pricePlanInfos) {
657
- _this.assetPriceLists = pricePlanInfos.map(function (item) {
658
- var _a, _b;
659
- return ({
660
- id: item.priceListId,
661
- name: (_b = (_a = _this.allPriceLists.find(function (priceList) { return priceList.id === item.priceListId; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '',
662
- });
663
- });
664
- _this.planIdsMap = pricePlanInfos.reduce(function (trunk, item) {
665
- var _c;
666
- return (Object.assign(Object.assign({}, trunk), (_c = {}, _c[item.id] = item.priceListId, _c)));
667
- }, {});
668
- var activePriceList = _this.assetPriceLists[0];
669
- _this.updateActivePriceList(activePriceList.id);
670
- // Update PriceListId in context properties
671
- // TODO: remove it when backend will have such logic
672
- if (_this.assetPriceLists.length) {
673
- _this.context.update({ properties: { PriceListId: activePriceList.id } });
635
+ // Populate list of price lists
636
+ this.assetPriceLists = quoteDraft.currentState
637
+ .map(function (_c) {
638
+ var priceListId = _c.priceListId;
639
+ return priceListId;
640
+ })
641
+ .reduce(function (trunk, priceListId) {
642
+ var _a, _b;
643
+ if (!priceListId || trunk.some(function (item) { return item.id === priceListId; })) {
644
+ return trunk;
674
645
  }
675
- }), operators.map(rxjs.noop));
646
+ return __spreadArray(__spreadArray([], __read(trunk)), [
647
+ { id: priceListId, name: (_b = (_a = _this.allPriceLists.find(function (item) { return item.id === priceListId; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '' },
648
+ ]);
649
+ }, []);
650
+ var activePriceList = this.assetPriceLists[0];
651
+ this.updateActivePriceList(activePriceList.id);
652
+ // Update PriceListId in context properties
653
+ // TODO: remove it when backend will have such logic
654
+ if (this.assetPriceLists.length) {
655
+ this.context.update({ properties: { PriceListId: activePriceList.id } });
656
+ }
676
657
  }
677
- return rxjs.of(undefined);
678
658
  };
679
659
  QuoteDraftService.prototype.filterByActivePriceList = function (lineItems) {
680
- var _this = this;
681
660
  var ctx = this.context.resolve();
682
- return lineItems.filter(function (li) { return !li.planId || _this.planIdsMap[li.planId] === ctx.properties.PriceListId; });
661
+ return lineItems.filter(function (li) { return !li.priceListId || li.priceListId === ctx.properties.PriceListId; });
683
662
  };
684
663
  QuoteDraftService.prototype.markAsUpdated = function () {
685
664
  if (this.isInitialized && !this.hasUnsavedChanges) {
@@ -1120,10 +1099,9 @@
1120
1099
  };
1121
1100
  ConfigurationService.prototype.configureExternal$ = function (productId, qty) {
1122
1101
  var _this = this;
1123
- // TODO: uncomment when procedure issue is fixed on backend side
1124
- // this.updateCurrentStates({
1125
- // currentState: this.quoteDraftService.quoteSnapshot?.currentState ?? [],
1126
- // });
1102
+ this.updateCurrentStates({
1103
+ currentState: this.quoteDraftService.currentState,
1104
+ });
1127
1105
  return this.runtimeService.init({ productId: productId, defaultQty: qty }).pipe(operators.switchMap(function () { return _this.configure(); }), operators.first(), operators.catchError(function (error) {
1128
1106
  _this.messageService.add({ severity: components.ToastType.error, summary: error });
1129
1107
  throw error;