@veloceapps/sdk 3.0.14 → 3.0.16

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.
@@ -1792,18 +1792,36 @@
1792
1792
  var FlowUpdateService = /** @class */ (function () {
1793
1793
  function FlowUpdateService() {
1794
1794
  }
1795
- FlowUpdateService.prototype.update = function (rootLineItem, params) {
1796
- switch (params.attributeType) {
1797
- case 'QTY':
1798
- return this.updateQty(rootLineItem, params);
1799
- case 'EFFECTIVE_START_DATE':
1800
- return this.updateEffectiveStartDate(rootLineItem, params);
1801
- case 'END_DATE':
1802
- return this.updateEndDate(rootLineItem, params);
1803
- case 'PRICE_ADJUSTMENT':
1804
- return this.updatePriceAdjustment(rootLineItem, params);
1805
- default:
1806
- return rootLineItem;
1795
+ FlowUpdateService.prototype.update = function (rootLineItems, updates) {
1796
+ var _this = this;
1797
+ var remainingUpdates = __spreadArray([], __read(updates));
1798
+ var currentLevel = rootLineItems;
1799
+ while (currentLevel.length && remainingUpdates.length) {
1800
+ currentLevel.forEach(function (li) {
1801
+ var unhandledUpdates = [];
1802
+ remainingUpdates.forEach(function (update) {
1803
+ var updated = false;
1804
+ switch (update.dataType) {
1805
+ case 'LINEITEM':
1806
+ updated = _this.applyLineItemUpdate(li, update);
1807
+ break;
1808
+ case 'CHARGE':
1809
+ updated = _this.applyChargeUpdate(li, update);
1810
+ break;
1811
+ case 'GROUP_CHARGE':
1812
+ updated = _this.applyChargeGroupUpdate(li, update);
1813
+ break;
1814
+ default:
1815
+ // Unknown dataType. Do not try to handle it anymore
1816
+ updated = true;
1817
+ }
1818
+ if (!updated) {
1819
+ unhandledUpdates.push(update);
1820
+ }
1821
+ });
1822
+ remainingUpdates = unhandledUpdates;
1823
+ });
1824
+ currentLevel = lodash.flatten(currentLevel.map(function (parent) { return parent.lineItems; }));
1807
1825
  }
1808
1826
  };
1809
1827
  FlowUpdateService.prototype.delete = function (lineItems, id) {
@@ -1823,77 +1841,64 @@
1823
1841
  var filtered = lineItems.filter(function (lineItem) { return !idsToRemove.includes(lineItem.id); });
1824
1842
  return filtered.map(function (lineItem) { return new LineItemWorker(lineItem).remove(id).li; });
1825
1843
  };
1826
- FlowUpdateService.prototype.updateQty = function (rootLineItem, params) {
1827
- // change quantity allowed only for lineItem
1828
- if (params.dataType !== 'LINEITEM') {
1829
- return rootLineItem;
1830
- }
1831
- var lineItem = findLineItem(params.id, [rootLineItem]);
1832
- if (!lineItem) {
1833
- return rootLineItem;
1834
- }
1835
- if (lineItem.id !== rootLineItem.id) {
1836
- throw new Error('Quantity can be changed only for root product');
1837
- }
1838
- var updated = new LineItemWorker(rootLineItem).replace(Object.assign(Object.assign({}, lineItem), { qty: params.newValue }));
1839
- return updated.li;
1840
- };
1841
- FlowUpdateService.prototype.updateEffectiveStartDate = function (rootLineItem, params) {
1842
- var lineItem = findLineItem(params.id, [rootLineItem]);
1843
- if (!lineItem) {
1844
- return rootLineItem;
1845
- }
1846
- var updated = new LineItemWorker(rootLineItem).replace(Object.assign(Object.assign({}, lineItem), { effectiveStartDate: moment__default["default"](params.newValue).format('YYYY-MM-DD') }));
1847
- return updated.li;
1848
- };
1849
- FlowUpdateService.prototype.updateEndDate = function (rootLineItem, params) {
1850
- var lineItem = findLineItem(params.id, [rootLineItem]);
1851
- if (!lineItem) {
1852
- return rootLineItem;
1853
- }
1854
- var updated = new LineItemWorker(rootLineItem).replace(Object.assign(Object.assign({}, lineItem), { endDate: moment__default["default"](params.newValue).format('YYYY-MM-DD') }));
1855
- return updated.li;
1856
- };
1857
- FlowUpdateService.prototype.updatePriceAdjustment = function (rootLineItem, params) {
1858
- var comparator = params.dataType === 'LINEITEM'
1859
- ? function (li) { return li.id === params.id; }
1860
- : params.dataType === 'CHARGE'
1861
- ? function (li) { return li.chargeItems.some(function (_a) {
1862
- var id = _a.id;
1863
- return id === params.id;
1864
- }); }
1865
- : params.dataType === 'GROUP_CHARGE'
1866
- ? function (li) { return li.chargeGroupItems.some(function (_a) {
1867
- var id = _a.id;
1868
- return id === params.id;
1869
- }); }
1870
- : undefined;
1871
- if (!comparator) {
1872
- return rootLineItem;
1873
- }
1874
- var lineItem = findLineItemWithComparator([rootLineItem], comparator);
1875
- if (!lineItem) {
1876
- return rootLineItem;
1877
- }
1878
- var updated;
1879
- if (params.dataType === 'LINEITEM') {
1880
- updated = Object.assign(Object.assign({}, lineItem), { chargeItems: lineItem.chargeItems.map(function (chargeItem, index) {
1881
- return index === 0 ? Object.assign(Object.assign({}, chargeItem), { priceAdjustment: params.newValue }) : chargeItem;
1882
- }) });
1883
- }
1884
- else if (params.dataType === 'CHARGE') {
1885
- updated = Object.assign(Object.assign({}, lineItem), { chargeItems: lineItem.chargeItems.map(function (chargeItem) {
1886
- return chargeItem.id === params.id ? Object.assign(Object.assign({}, chargeItem), { priceAdjustment: params.newValue }) : chargeItem;
1887
- }) });
1888
- }
1889
- else if (params.dataType === 'GROUP_CHARGE') {
1890
- updated = Object.assign(Object.assign({}, lineItem), { chargeGroupItems: lineItem.chargeGroupItems.map(function (chargeGroupItem) {
1891
- return chargeGroupItem.id === params.id
1892
- ? Object.assign(Object.assign({}, chargeGroupItem), { priceAdjustment: params.newValue }) : chargeGroupItem;
1893
- }) });
1894
- }
1895
- var updatedRootLineItem = updated ? new LineItemWorker(rootLineItem).replace(updated).li : rootLineItem;
1896
- return updatedRootLineItem;
1844
+ FlowUpdateService.prototype.applyLineItemUpdate = function (lineItem, update) {
1845
+ if (lineItem.id !== update.id) {
1846
+ return false;
1847
+ }
1848
+ switch (update.attributeType) {
1849
+ case 'QTY':
1850
+ lineItem.qty = update.newValue;
1851
+ break;
1852
+ case 'EFFECTIVE_START_DATE':
1853
+ lineItem.effectiveStartDate = moment__default["default"](update.newValue).format('YYYY-MM-DD');
1854
+ break;
1855
+ case 'END_DATE':
1856
+ lineItem.endDate = moment__default["default"](update.newValue).format('YYYY-MM-DD');
1857
+ break;
1858
+ case 'PRICE_ADJUSTMENT':
1859
+ {
1860
+ var _a = __read(lineItem.chargeItems, 1), charge = _a[0];
1861
+ if (charge) {
1862
+ charge.priceAdjustment = update.newValue;
1863
+ }
1864
+ }
1865
+ break;
1866
+ default:
1867
+ throw new Error("Not suppored AttributeType for LineItem update: " + update.attributeType);
1868
+ }
1869
+ return true;
1870
+ };
1871
+ FlowUpdateService.prototype.applyChargeUpdate = function (lineItem, update) {
1872
+ var foundCharge = lineItem.chargeItems.find(function (_a) {
1873
+ var id = _a.id;
1874
+ return id === update.id;
1875
+ });
1876
+ if (!foundCharge) {
1877
+ return false;
1878
+ }
1879
+ if (update.attributeType === 'PRICE_ADJUSTMENT') {
1880
+ foundCharge.priceAdjustment = update.newValue;
1881
+ }
1882
+ else {
1883
+ throw new Error("Not suppored AttributeType for Charge Item update: " + update.attributeType);
1884
+ }
1885
+ return true;
1886
+ };
1887
+ FlowUpdateService.prototype.applyChargeGroupUpdate = function (lineItem, update) {
1888
+ var foundChargeGroup = lineItem.chargeGroupItems.find(function (_a) {
1889
+ var id = _a.id;
1890
+ return id === update.id;
1891
+ });
1892
+ if (!foundChargeGroup) {
1893
+ return false;
1894
+ }
1895
+ if (update.attributeType === 'PRICE_ADJUSTMENT') {
1896
+ foundChargeGroup.priceAdjustment = update.newValue;
1897
+ }
1898
+ else {
1899
+ throw new Error("Not suppored AttributeType for Charge Group Item update: " + update.attributeType);
1900
+ }
1901
+ return true;
1897
1902
  };
1898
1903
  return FlowUpdateService;
1899
1904
  }());
@@ -1930,12 +1935,13 @@
1930
1935
  FlowConfigurationService.prototype.calculate = function (currentState) {
1931
1936
  this.calculate$(currentState).subscribe();
1932
1937
  };
1933
- FlowConfigurationService.prototype.update$ = function (params) {
1938
+ FlowConfigurationService.prototype.update$ = function (updates) {
1934
1939
  var _this = this;
1935
- return rxjs.of([]).pipe(rxjs.map(function () { return _this.lineItems.value.map(function (li) { return _this.updateService.update(li, params); }); }), this.handleError(), rxjs.switchMap(function (currentState) { return _this.calculate$(currentState); }));
1940
+ var lineItems = lodash.cloneDeep(this.lineItems.value);
1941
+ return rxjs.of([]).pipe(rxjs.tap(function () { return _this.updateService.update(lineItems, updates); }), this.handleError(), rxjs.switchMap(function () { return _this.calculate$(lineItems); }));
1936
1942
  };
1937
- FlowConfigurationService.prototype.update = function (params) {
1938
- this.update$(params).subscribe();
1943
+ FlowConfigurationService.prototype.update = function (updates) {
1944
+ this.update$(updates).subscribe();
1939
1945
  };
1940
1946
  FlowConfigurationService.prototype.delete$ = function (ids) {
1941
1947
  var _this = this;