@infrab4a/connect 4.25.0-beta.10 → 4.25.0-beta.11

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.
package/index.cjs.js CHANGED
@@ -5602,6 +5602,17 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5602
5602
  });
5603
5603
  this.productRepository = productRepository;
5604
5604
  this.categoryFilterRepository = categoryFilterRepository;
5605
+ this.reorganizeMostRelevantsProducts = (products, mostRelevantsIds, limit) => {
5606
+ const mostRelevantWithouyStock = products.filter((product) => mostRelevantsIds.includes(product.id) && product.stock.quantity <= 0);
5607
+ const firstProducts = products
5608
+ .filter((product) => mostRelevantsIds.includes(product.id) && product.stock.quantity > 0)
5609
+ .sort((a, b) => mostRelevantsIds.indexOf(a.id) - mostRelevantsIds.indexOf(b.id));
5610
+ const lastProducts = products
5611
+ .filter((product) => !mostRelevantsIds.includes(product.id) && product.stock.quantity > 0)
5612
+ .concat(mostRelevantWithouyStock);
5613
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
5614
+ return limit ? categoryMostRelevants.slice(0, limit) : categoryMostRelevants;
5615
+ };
5605
5616
  }
5606
5617
  async create(params) {
5607
5618
  const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
@@ -5704,55 +5715,60 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5704
5715
  var _a;
5705
5716
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
5706
5717
  return [];
5707
- const mostRelevants = category.getMostRelevantByShop(shop);
5708
- const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
5718
+ const fields = [
5719
+ 'id',
5720
+ 'name',
5721
+ 'slug',
5722
+ 'images',
5723
+ 'miniatures',
5724
+ 'price',
5725
+ 'fullPrice',
5726
+ 'subscriberDiscountPercentage',
5727
+ 'subscriberPrice',
5728
+ 'stock',
5729
+ 'published',
5730
+ 'CEST',
5731
+ 'EAN',
5732
+ 'NCM',
5733
+ 'brand',
5734
+ 'costPrice',
5735
+ 'hasVariants',
5736
+ 'isKit',
5737
+ 'sku',
5738
+ 'rate',
5739
+ 'tags',
5740
+ 'type',
5741
+ 'shoppingCount',
5742
+ 'gender',
5743
+ 'createdAt',
5744
+ ];
5709
5745
  const products = [];
5746
+ const mostRelevantsIds = category.getMostRelevantByShop(shop);
5747
+ if (mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length) {
5748
+ const { data: mostRelevants } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
5749
+ operator: exports.Where.IN,
5750
+ value: mostRelevantsIds,
5751
+ }, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
5752
+ stock: 'desc',
5753
+ shoppingCount: 'desc',
5754
+ rate: 'desc',
5755
+ name: 'asc',
5756
+ } }), shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5757
+ if (mostRelevants.length >= mostRelevantsIds.length)
5758
+ return this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
5759
+ products.push(...mostRelevants);
5760
+ }
5761
+ const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
5710
5762
  const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
5711
5763
  operator: exports.Where.IN,
5712
- value: mostRelevantProductsIds,
5713
- }, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields: [
5714
- 'id',
5715
- 'name',
5716
- 'slug',
5717
- 'images',
5718
- 'miniatures',
5719
- 'price',
5720
- 'fullPrice',
5721
- 'subscriberDiscountPercentage',
5722
- 'subscriberPrice',
5723
- 'stock',
5724
- 'published',
5725
- 'CEST',
5726
- 'EAN',
5727
- 'NCM',
5728
- 'brand',
5729
- 'costPrice',
5730
- 'hasVariants',
5731
- 'isKit',
5732
- 'sku',
5733
- 'rate',
5734
- 'tags',
5735
- 'type',
5736
- 'shoppingCount',
5737
- 'gender',
5738
- 'createdAt',
5739
- ], options: { enableCount: false }, orderBy: {
5764
+ value: productIds,
5765
+ }, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
5740
5766
  stock: 'desc',
5741
5767
  shoppingCount: 'desc',
5742
5768
  rate: 'desc',
5743
5769
  name: 'asc',
5744
5770
  } }), shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5745
- const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5746
- const firstProducts = productsData
5747
- .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
5748
- .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
5749
- const lastProducts = productsData
5750
- .filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
5751
- .concat(mostRelevantWithouyStock);
5752
- const categoryMostRelevants = firstProducts.concat(lastProducts);
5753
- const resultFinal = categoryMostRelevants.slice(0, options.limit);
5754
- products.push(...resultFinal);
5755
- return products;
5771
+ return this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
5756
5772
  }
5757
5773
  async getChildren(parentId, _optionsCache) {
5758
5774
  const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
package/index.esm.js CHANGED
@@ -5596,6 +5596,17 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5596
5596
  });
5597
5597
  this.productRepository = productRepository;
5598
5598
  this.categoryFilterRepository = categoryFilterRepository;
5599
+ this.reorganizeMostRelevantsProducts = (products, mostRelevantsIds, limit) => {
5600
+ const mostRelevantWithouyStock = products.filter((product) => mostRelevantsIds.includes(product.id) && product.stock.quantity <= 0);
5601
+ const firstProducts = products
5602
+ .filter((product) => mostRelevantsIds.includes(product.id) && product.stock.quantity > 0)
5603
+ .sort((a, b) => mostRelevantsIds.indexOf(a.id) - mostRelevantsIds.indexOf(b.id));
5604
+ const lastProducts = products
5605
+ .filter((product) => !mostRelevantsIds.includes(product.id) && product.stock.quantity > 0)
5606
+ .concat(mostRelevantWithouyStock);
5607
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
5608
+ return limit ? categoryMostRelevants.slice(0, limit) : categoryMostRelevants;
5609
+ };
5599
5610
  }
5600
5611
  async create(params) {
5601
5612
  const { images, mostRelevants, metadatas } = params, data = __rest(params, ["images", "mostRelevants", "metadatas"]);
@@ -5698,55 +5709,60 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5698
5709
  var _a;
5699
5710
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
5700
5711
  return [];
5701
- const mostRelevants = category.getMostRelevantByShop(shop);
5702
- const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
5712
+ const fields = [
5713
+ 'id',
5714
+ 'name',
5715
+ 'slug',
5716
+ 'images',
5717
+ 'miniatures',
5718
+ 'price',
5719
+ 'fullPrice',
5720
+ 'subscriberDiscountPercentage',
5721
+ 'subscriberPrice',
5722
+ 'stock',
5723
+ 'published',
5724
+ 'CEST',
5725
+ 'EAN',
5726
+ 'NCM',
5727
+ 'brand',
5728
+ 'costPrice',
5729
+ 'hasVariants',
5730
+ 'isKit',
5731
+ 'sku',
5732
+ 'rate',
5733
+ 'tags',
5734
+ 'type',
5735
+ 'shoppingCount',
5736
+ 'gender',
5737
+ 'createdAt',
5738
+ ];
5703
5739
  const products = [];
5740
+ const mostRelevantsIds = category.getMostRelevantByShop(shop);
5741
+ if (mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length) {
5742
+ const { data: mostRelevants } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
5743
+ operator: Where.IN,
5744
+ value: mostRelevantsIds,
5745
+ }, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
5746
+ stock: 'desc',
5747
+ shoppingCount: 'desc',
5748
+ rate: 'desc',
5749
+ name: 'asc',
5750
+ } }), shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5751
+ if (mostRelevants.length >= mostRelevantsIds.length)
5752
+ return this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
5753
+ products.push(...mostRelevants);
5754
+ }
5755
+ const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
5704
5756
  const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
5705
5757
  operator: Where.IN,
5706
- value: mostRelevantProductsIds,
5707
- }, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields: [
5708
- 'id',
5709
- 'name',
5710
- 'slug',
5711
- 'images',
5712
- 'miniatures',
5713
- 'price',
5714
- 'fullPrice',
5715
- 'subscriberDiscountPercentage',
5716
- 'subscriberPrice',
5717
- 'stock',
5718
- 'published',
5719
- 'CEST',
5720
- 'EAN',
5721
- 'NCM',
5722
- 'brand',
5723
- 'costPrice',
5724
- 'hasVariants',
5725
- 'isKit',
5726
- 'sku',
5727
- 'rate',
5728
- 'tags',
5729
- 'type',
5730
- 'shoppingCount',
5731
- 'gender',
5732
- 'createdAt',
5733
- ], options: { enableCount: false }, orderBy: {
5758
+ value: productIds,
5759
+ }, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
5734
5760
  stock: 'desc',
5735
5761
  shoppingCount: 'desc',
5736
5762
  rate: 'desc',
5737
5763
  name: 'asc',
5738
5764
  } }), shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5739
- const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5740
- const firstProducts = productsData
5741
- .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
5742
- .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
5743
- const lastProducts = productsData
5744
- .filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
5745
- .concat(mostRelevantWithouyStock);
5746
- const categoryMostRelevants = firstProducts.concat(lastProducts);
5747
- const resultFinal = categoryMostRelevants.slice(0, options.limit);
5748
- products.push(...resultFinal);
5749
- return products;
5765
+ return this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
5750
5766
  }
5751
5767
  async getChildren(parentId, _optionsCache) {
5752
5768
  const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.25.0-beta.10",
3
+ "version": "4.25.0-beta.11",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -42,5 +42,6 @@ export declare class CategoryHasuraGraphQLRepository extends CategoryHasuraGraph
42
42
  private updateProducts;
43
43
  private updateMetadata;
44
44
  private updateFilters;
45
+ private reorganizeMostRelevantsProducts;
45
46
  }
46
47
  export {};