@infrab4a/connect-angular 4.1.5-beta.2 → 4.1.5-beta.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.
@@ -1538,23 +1538,27 @@ class CatalogService {
1538
1538
  }
1539
1539
  async findCatalogByTermAndSortByMostRevelant(options, limits) {
1540
1540
  const productIds = await this.findCatalogIdsByElasticSearch(options.term);
1541
- const limitedProductId = productIds.slice(limits.offset, limits.offset + limits.limit);
1542
- const productResult = await this.productRepository.findCatalog({
1541
+ const totalResult = await this.productRepository.findCatalog({
1542
+ fields: ['id'],
1543
1543
  filters: {
1544
- id: { operator: Where.IN, value: limitedProductId },
1544
+ id: { operator: Where.IN, value: productIds },
1545
1545
  ...this.buildFilterQuery(options?.filters || {}),
1546
1546
  },
1547
- }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1548
- const totalResult = await this.productRepository.findCatalog({
1549
- fields: ['id'],
1550
- filters: { id: { operator: Where.IN, value: productIds } },
1551
- limits: { limit: 1, offset: 0 },
1552
1547
  options: {
1553
1548
  minimal: ['price'],
1554
1549
  maximum: ['price'],
1555
1550
  distinct: ['brand'],
1556
1551
  },
1557
1552
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1553
+ const limitedProductId = totalResult.data
1554
+ .slice(limits.offset, limits.offset + limits.limit)
1555
+ .map((product) => product.id);
1556
+ const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1557
+ const productResult = await this.productRepository.findCatalog({
1558
+ filters: {
1559
+ id: { operator: Where.IN, value: orderedId },
1560
+ },
1561
+ });
1558
1562
  return {
1559
1563
  data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1560
1564
  count: totalResult.count,