@infrab4a/connect 4.25.0-beta.10 → 4.25.0-beta.12
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,65 @@ 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
|
|
5708
|
-
|
|
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({
|
|
5749
|
+
filters: Object.assign({ id: {
|
|
5750
|
+
operator: exports.Where.IN,
|
|
5751
|
+
value: mostRelevantsIds,
|
|
5752
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})),
|
|
5753
|
+
fields,
|
|
5754
|
+
options: { enableCount: false },
|
|
5755
|
+
orderBy: {
|
|
5756
|
+
stock: 'desc',
|
|
5757
|
+
shoppingCount: 'desc',
|
|
5758
|
+
rate: 'desc',
|
|
5759
|
+
name: 'asc',
|
|
5760
|
+
},
|
|
5761
|
+
}, shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5762
|
+
if (mostRelevants.length >= mostRelevantsIds.length)
|
|
5763
|
+
return this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
|
|
5764
|
+
products.push(...mostRelevants);
|
|
5765
|
+
}
|
|
5766
|
+
const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
|
|
5710
5767
|
const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
|
|
5711
5768
|
operator: exports.Where.IN,
|
|
5712
|
-
value:
|
|
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: {
|
|
5769
|
+
value: productIds,
|
|
5770
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
|
|
5740
5771
|
stock: 'desc',
|
|
5741
5772
|
shoppingCount: 'desc',
|
|
5742
5773
|
rate: 'desc',
|
|
5743
5774
|
name: 'asc',
|
|
5744
5775
|
} }), shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5745
|
-
|
|
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;
|
|
5776
|
+
return this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
|
|
5756
5777
|
}
|
|
5757
5778
|
async getChildren(parentId, _optionsCache) {
|
|
5758
5779
|
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,65 @@ 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
|
|
5702
|
-
|
|
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({
|
|
5743
|
+
filters: Object.assign({ id: {
|
|
5744
|
+
operator: Where.IN,
|
|
5745
|
+
value: mostRelevantsIds,
|
|
5746
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})),
|
|
5747
|
+
fields,
|
|
5748
|
+
options: { enableCount: false },
|
|
5749
|
+
orderBy: {
|
|
5750
|
+
stock: 'desc',
|
|
5751
|
+
shoppingCount: 'desc',
|
|
5752
|
+
rate: 'desc',
|
|
5753
|
+
name: 'asc',
|
|
5754
|
+
},
|
|
5755
|
+
}, shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5756
|
+
if (mostRelevants.length >= mostRelevantsIds.length)
|
|
5757
|
+
return this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
|
|
5758
|
+
products.push(...mostRelevants);
|
|
5759
|
+
}
|
|
5760
|
+
const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
|
|
5704
5761
|
const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
|
|
5705
5762
|
operator: Where.IN,
|
|
5706
|
-
value:
|
|
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: {
|
|
5763
|
+
value: productIds,
|
|
5764
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
|
|
5734
5765
|
stock: 'desc',
|
|
5735
5766
|
shoppingCount: 'desc',
|
|
5736
5767
|
rate: 'desc',
|
|
5737
5768
|
name: 'asc',
|
|
5738
5769
|
} }), shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5739
|
-
|
|
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;
|
|
5770
|
+
return this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
|
|
5750
5771
|
}
|
|
5751
5772
|
async getChildren(parentId, _optionsCache) {
|
|
5752
5773
|
const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
|
package/package.json
CHANGED