Guest User

Untitled

a guest
Mar 4th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /**
  2.     * Converts units, updates model
  3.     */
  4.     unitConverter(index: number): Promise<number> {
  5.  
  6.  
  7.         const unitElement = this.products[index].units.get(this.products[index].unitId);
  8.  
  9.         //if unit never loaded
  10.         if (unitElement === undefined || unitElement.basicUnit === undefined) {
  11.  
  12.             //load unit and change unit data
  13.  
  14.             this.products[index].unitsLoaded = false;
  15.  
  16.             const params: b2b.UnitConvertRequest = {
  17.                 cartId: this.products[index].cartId.toString() || '1',
  18.                 id: this.products[index].id.toString(),
  19.                 unitNo: this.products[index].unitId.toString() || '0',
  20.                 features: this.parametersToString(0) || '',
  21.                 warehouseId: this.filters.currentFilter.warehouse.id || '0'
  22.             };
  23.  
  24.  
  25.             return this.unitConverterRequest(params).then(res => {
  26.  
  27.                 const unitData = Object.assign(res, {
  28.                     converter: (res.auxiliaryUnit) ? FormattingUtils.unitConverterString(res.denominator, res.auxiliaryUnit, res.numerator, res.basicUnit) : null,
  29.                     max: FormattingUtils.stringToNum(res.stockLevel)
  30.                 });
  31.  
  32.                 this.products[index].units.set(this.products[index].unitId, unitData);
  33.  
  34.                 this.products[index] = Object.assign(this.products[index], unitData);
  35.  
  36.                 this.products[index].unitsLoaded = true;
  37.  
  38.                 return index;
  39.             });
  40.  
  41.         } else {
  42.  
  43.             //change unit data
  44.  
  45.             this.products[index] = Object.assign(this.products[index], unitElement);
  46.  
  47.             return Promise.resolve(index);
  48.         }
  49.  
  50.  
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment