@snabcentr/client-core 4.12.0 → 4.13.0

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.
@@ -7082,9 +7082,36 @@ class ScOrderDraftsService {
7082
7082
  params: { offer_id: offerId, order_id: order.id },
7083
7083
  });
7084
7084
  });
7085
- this.offerMap.get(offerId)?.update();
7085
+ this.removeOrderedProductsFromCache(offerId, data.items ?? []);
7086
7086
  }));
7087
7087
  }
7088
+ /**
7089
+ * Убирает заказанные позиции из кэша черновика локально (сервер сразу после заказа ещё может вернуть их в списке).
7090
+ *
7091
+ * @param offerId Идентификатор черновика.
7092
+ * @param orderedItemIds Идентификаторы заказанных позиций.
7093
+ */
7094
+ removeOrderedProductsFromCache(offerId, orderedItemIds) {
7095
+ const cachedItem = this.offerMap.get(offerId);
7096
+ if (!cachedItem || orderedItemIds.length === 0) {
7097
+ return;
7098
+ }
7099
+ const orderedIds = new Set(orderedItemIds.map(String));
7100
+ cachedItem.item$.pipe(take(1)).subscribe((draft) => {
7101
+ if (draft === loadingPlaceholder) {
7102
+ return;
7103
+ }
7104
+ const currentDraft = draft;
7105
+ const remainingProducts = currentDraft.products.filter((product) => !orderedIds.has(product.id));
7106
+ if (remainingProducts.length === currentDraft.products.length) {
7107
+ return;
7108
+ }
7109
+ const updatedDraft = new ScOrderDraft(currentDraft);
7110
+ updatedDraft.products = remainingProducts;
7111
+ updatedDraft.sum = remainingProducts.reduce((sum, product) => sum + product.costRub, 0);
7112
+ cachedItem.setValue(updatedDraft);
7113
+ });
7114
+ }
7088
7115
  /**
7089
7116
  * Добавляет продукт в коммерческое предложение/черновик.
7090
7117
  *