@infrab4a/connect-angular 4.5.3-beta.5 → 4.5.3-beta.7

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.
@@ -1777,22 +1777,15 @@ class CatalogService {
1777
1777
  async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1778
1778
  console.log('mostRelevant', mostRelevants);
1779
1779
  console.log('productIds', productIds);
1780
- const { offset } = limits;
1781
- if (offset === 0) {
1782
- limits.limit -= mostRelevants.length;
1783
- }
1784
- if (offset > 0) {
1785
- limits.offset -= mostRelevants.length;
1786
- }
1787
- console.log('limits', limits);
1788
1780
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1789
1781
  console.log('mostRelevantProductsIds', mostRelevantProductsIds);
1790
1782
  const totalResult = await this.productRepository.findCatalog({
1791
1783
  fields: ['id', 'stock'],
1792
1784
  filters: {
1793
1785
  id: { operator: Where.IN, value: mostRelevantProductsIds },
1794
- ...this.buildFilterQuery(options?.filters || {}),
1795
1786
  },
1787
+ // limits,
1788
+ orderBy: this.buildSortQuery('news'),
1796
1789
  options: {
1797
1790
  minimal: ['price'],
1798
1791
  maximum: ['price'],
@@ -1800,22 +1793,38 @@ class CatalogService {
1800
1793
  },
1801
1794
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1802
1795
  console.log('totalResult', totalResult.count);
1803
- const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1804
- const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1805
- const productIdsStock = mostRelevantProductsIds.filter((product) => stockData.some((result) => result.id == product));
1806
- const productIdsStockOut = mostRelevantProductsIds.filter((product) => stockOut.some((result) => result.id == product));
1807
- const limitedProductId = productIdsStock
1808
- .concat(productIdsStockOut)
1809
- .slice(limits.offset, limits.offset + limits.limit);
1810
- const orderedId = mostRelevantProductsIds.filter((product) => limitedProductId.includes(product));
1811
- console.log('orderedId', orderedId);
1812
- const productResult = await this.productRepository.findCatalog({
1813
- filters: {
1814
- id: { operator: Where.IN, value: orderedId },
1815
- },
1816
- });
1796
+ // const stockData = totalResult.data.filter((product) => product.stock.quantity > 0)
1797
+ // const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0)
1798
+ // const productIdsStock = mostRelevantProductsIds.filter((product) =>
1799
+ // stockData.some((result) => result.id == product),
1800
+ // )
1801
+ // const productIdsStockOut = mostRelevantProductsIds.filter((product) =>
1802
+ // stockOut.some((result) => result.id == product),
1803
+ // )
1804
+ // const limitedProductId = productIdsStock
1805
+ // .concat(productIdsStockOut)
1806
+ // .slice(limits.offset, limits.offset + limits.limit)
1807
+ const firstProducts = totalResult.data.filter((product) => mostRelevants.includes(product.id));
1808
+ const lastProducts = totalResult.data.filter((product) => !mostRelevants.includes(product.id));
1809
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
1810
+ // const orderedId = mostRelevantProductsIds.filter((product) => limitedProductId.includes(product))
1811
+ // console.log('orderedId', orderedId)
1812
+ // const productResult = await this.productRepository.findCatalog({
1813
+ // filters: {
1814
+ // id: { operator: Where.IN, value: orderedId },
1815
+ // },
1816
+ // })
1817
+ // const totalResult = categoryMostRelevants.
1818
+ // Pesquisa os most_relevant
1819
+ // Valida stock
1820
+ // Pesquisa os news
1821
+ // Valida stock
1822
+ // Junta e faz o slice
1823
+ // Valida se não tem repetido
1824
+ const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1825
+ console.log('resultFinal', resultFinal);
1817
1826
  return {
1818
- data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1827
+ data: resultFinal,
1819
1828
  count: totalResult.count,
1820
1829
  maximum: totalResult.maximum,
1821
1830
  minimal: totalResult.minimal,