@ppg_pl/tinting 0.0.3 → 0.0.4

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.
@@ -2569,10 +2569,21 @@ const fetchColors = async (filters) => {
2569
2569
  return [];
2570
2570
  }
2571
2571
  };
2572
+ const getSampleSortForProduct = (sample, productId) => {
2573
+ var _a, _b;
2574
+ const link = (_a = sample === null || sample === void 0 ? void 0 : sample.Products) === null || _a === void 0 ? void 0 : _a.find((p) => p.Product_id === productId);
2575
+ // put null/undefined at the end
2576
+ return (_b = link === null || link === void 0 ? void 0 : link.sort) !== null && _b !== void 0 ? _b : Number.POSITIVE_INFINITY;
2577
+ };
2572
2578
  const fetchSamplesColors = async (filters) => {
2573
2579
  try {
2580
+ // you already include Products.* in the query
2581
+ const { id: productId } = filters;
2574
2582
  const response = await ApiService.getData(`items/Sample?${fetchColorsQuery(Object.assign({}, filters))}`);
2575
- return (response === null || response === void 0 ? void 0 : response.data) || [];
2583
+ const data = (response === null || response === void 0 ? void 0 : response.data) || [];
2584
+ // order by junction sort
2585
+ const ordered = [...data].sort((a, b) => getSampleSortForProduct(a, productId) - getSampleSortForProduct(b, productId));
2586
+ return ordered;
2576
2587
  }
2577
2588
  catch (error) {
2578
2589
  console.error('Error fetching samples colors:', error);