@infrab4a/connect 4.16.1-beta.3 → 4.16.2-beta.0

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
@@ -4934,7 +4934,6 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4934
4934
  categories.push(...(await this.find({
4935
4935
  filters: {
4936
4936
  id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) },
4937
- // shops: { operator: Where.IN, value: [shop] },
4938
4937
  published: true,
4939
4938
  },
4940
4939
  }).then(({ data }) => data)));
@@ -4953,7 +4952,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4953
4952
  const mostRelevants = category.getMostRelevantByShop(shop);
4954
4953
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
4955
4954
  const products = [];
4956
- const { data: productsData } = await this.productRepository.find(Object.assign(Object.assign({ filters: Object.assign({ id: { operator: exports.Where.IN, value: mostRelevantProductsIds }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
4955
+ const { data: productsData } = await this.productRepository.find({
4956
+ filters: {
4957
+ id: { operator: exports.Where.IN, value: mostRelevantProductsIds },
4958
+ published: true,
4959
+ },
4960
+ fields: [
4957
4961
  'id',
4958
4962
  'name',
4959
4963
  'slug',
@@ -4979,8 +4983,25 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4979
4983
  'shoppingCount',
4980
4984
  'gender',
4981
4985
  'createdAt',
4982
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }));
4983
- products.push(...productsData.sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id)));
4986
+ ],
4987
+ options: { enableCount: false },
4988
+ orderBy: {
4989
+ shoppingCount: 'desc',
4990
+ rate: 'desc',
4991
+ stock: 'desc',
4992
+ name: 'asc',
4993
+ },
4994
+ });
4995
+ const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
4996
+ const firstProducts = productsData
4997
+ .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
4998
+ .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
4999
+ const lastProducts = productsData
5000
+ .filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
5001
+ .concat(mostRelevantWithouyStock);
5002
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
5003
+ const resultFinal = categoryMostRelevants.slice(0, options.limit);
5004
+ products.push(...resultFinal);
4984
5005
  return products;
4985
5006
  }
4986
5007
  async getChildren(parentId) {
package/index.esm.js CHANGED
@@ -4928,7 +4928,6 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4928
4928
  categories.push(...(await this.find({
4929
4929
  filters: {
4930
4930
  id: { operator: Where.IN, value: categoriesHasura.filter(Boolean) },
4931
- // shops: { operator: Where.IN, value: [shop] },
4932
4931
  published: true,
4933
4932
  },
4934
4933
  }).then(({ data }) => data)));
@@ -4947,7 +4946,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4947
4946
  const mostRelevants = category.getMostRelevantByShop(shop);
4948
4947
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
4949
4948
  const products = [];
4950
- const { data: productsData } = await this.productRepository.find(Object.assign(Object.assign({ filters: Object.assign({ id: { operator: Where.IN, value: mostRelevantProductsIds }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})), fields: [
4949
+ const { data: productsData } = await this.productRepository.find({
4950
+ filters: {
4951
+ id: { operator: Where.IN, value: mostRelevantProductsIds },
4952
+ published: true,
4953
+ },
4954
+ fields: [
4951
4955
  'id',
4952
4956
  'name',
4953
4957
  'slug',
@@ -4973,8 +4977,25 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4973
4977
  'shoppingCount',
4974
4978
  'gender',
4975
4979
  'createdAt',
4976
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }));
4977
- products.push(...productsData.sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id)));
4980
+ ],
4981
+ options: { enableCount: false },
4982
+ orderBy: {
4983
+ shoppingCount: 'desc',
4984
+ rate: 'desc',
4985
+ stock: 'desc',
4986
+ name: 'asc',
4987
+ },
4988
+ });
4989
+ const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
4990
+ const firstProducts = productsData
4991
+ .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
4992
+ .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
4993
+ const lastProducts = productsData
4994
+ .filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
4995
+ .concat(mostRelevantWithouyStock);
4996
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
4997
+ const resultFinal = categoryMostRelevants.slice(0, options.limit);
4998
+ products.push(...resultFinal);
4978
4999
  return products;
4979
5000
  }
4980
5001
  async getChildren(parentId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.16.1-beta.3",
3
+ "version": "4.16.2-beta.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },