@infrab4a/connect-angular 4.5.4-beta.0 → 4.5.4-beta.1

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.
@@ -1733,9 +1733,10 @@ class CatalogService {
1733
1733
  async findCatalog(options, limits) {
1734
1734
  if (this.hasTerm(options) && options.sort === 'most-relevant') {
1735
1735
  const productsIds = await this.findCatalogIdsByElasticSearch(options.term);
1736
- return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1736
+ return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1737
1737
  }
1738
1738
  if (this.hasCategory(options) && options.sort === 'most-relevant') {
1739
+ const mostRelevant = options.category.mostRelevant ?? [];
1739
1740
  const productsIds = await this.productRepository
1740
1741
  .find({
1741
1742
  fields: ['id'],
@@ -1744,7 +1745,7 @@ class CatalogService {
1744
1745
  },
1745
1746
  })
1746
1747
  .then((products) => products.data.map((product) => product.id));
1747
- return this.findCatalogAndSortByMostRevelant(productsIds, options, limits);
1748
+ return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
1748
1749
  }
1749
1750
  const repoParams = {
1750
1751
  filters: {
@@ -1773,7 +1774,32 @@ class CatalogService {
1773
1774
  .search(term, 999, this.shop)
1774
1775
  .then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
1775
1776
  }
1776
- async findCatalogAndSortByMostRevelant(productIds, options, limits) {
1777
+ async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1778
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1779
+ const totalResult = await this.productRepository.findCatalog({
1780
+ filters: {
1781
+ id: { operator: Where.IN, value: mostRelevantProductsIds },
1782
+ },
1783
+ orderBy: this.buildSortQuery('news'),
1784
+ options: {
1785
+ minimal: ['price'],
1786
+ maximum: ['price'],
1787
+ distinct: ['brand'],
1788
+ },
1789
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1790
+ const firstProducts = totalResult.data.filter((product) => mostRelevants.includes(product.id));
1791
+ const lastProducts = totalResult.data.filter((product) => !mostRelevants.includes(product.id));
1792
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
1793
+ const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1794
+ return {
1795
+ data: resultFinal,
1796
+ count: totalResult.count,
1797
+ maximum: totalResult.maximum,
1798
+ minimal: totalResult.minimal,
1799
+ distinct: totalResult.distinct,
1800
+ };
1801
+ }
1802
+ async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1777
1803
  const totalResult = await this.productRepository.findCatalog({
1778
1804
  fields: ['id', 'stock'],
1779
1805
  filters: {