Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Converts units, updates model
- */
- unitConverter(index: number): Promise<number> {
- const unitElement = this.products[index].units.get(this.products[index].unitId);
- //if unit never loaded
- if (unitElement === undefined || unitElement.basicUnit === undefined) {
- //load unit and change unit data
- this.products[index].unitsLoaded = false;
- const params: b2b.UnitConvertRequest = {
- cartId: this.products[index].cartId.toString() || '1',
- id: this.products[index].id.toString(),
- unitNo: this.products[index].unitId.toString() || '0',
- features: this.parametersToString(0) || '',
- warehouseId: this.filters.currentFilter.warehouse.id || '0'
- };
- return this.unitConverterRequest(params).then(res => {
- const unitData = Object.assign(res, {
- converter: (res.auxiliaryUnit) ? FormattingUtils.unitConverterString(res.denominator, res.auxiliaryUnit, res.numerator, res.basicUnit) : null,
- max: FormattingUtils.stringToNum(res.stockLevel)
- });
- this.products[index].units.set(this.products[index].unitId, unitData);
- this.products[index] = Object.assign(this.products[index], unitData);
- this.products[index].unitsLoaded = true;
- return index;
- });
- } else {
- //change unit data
- this.products[index] = Object.assign(this.products[index], unitElement);
- return Promise.resolve(index);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment