@infrab4a/connect 4.25.0-beta.9 → 4.25.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
|
@@ -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"]);
|
|
@@ -5701,58 +5712,83 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5701
5712
|
return homeSections;
|
|
5702
5713
|
}
|
|
5703
5714
|
async mountCategory(category, shop, options, optionsCache) {
|
|
5704
|
-
var _a;
|
|
5715
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
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
|
-
|
|
5708
|
-
|
|
5718
|
+
if (((_b = this.cache) === null || _b === void 0 ? void 0 : _b.cacheAdapter) && ((_c = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _c === void 0 ? void 0 : _c.enabled)) {
|
|
5719
|
+
const cacheKey = `${this.model.name.toLowerCase()}:mountCategory:${category.id}:${shop}:${MD5GeneratorHelper.generateMD5(options)}`;
|
|
5720
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
5721
|
+
if (cachedData) {
|
|
5722
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
5723
|
+
return JSON.parse(cachedData);
|
|
5724
|
+
}
|
|
5725
|
+
}
|
|
5726
|
+
const fields = [
|
|
5727
|
+
'id',
|
|
5728
|
+
'name',
|
|
5729
|
+
'slug',
|
|
5730
|
+
'images',
|
|
5731
|
+
'miniatures',
|
|
5732
|
+
'price',
|
|
5733
|
+
'fullPrice',
|
|
5734
|
+
'subscriberDiscountPercentage',
|
|
5735
|
+
'subscriberPrice',
|
|
5736
|
+
'stock',
|
|
5737
|
+
'published',
|
|
5738
|
+
'CEST',
|
|
5739
|
+
'EAN',
|
|
5740
|
+
'NCM',
|
|
5741
|
+
'brand',
|
|
5742
|
+
'costPrice',
|
|
5743
|
+
'hasVariants',
|
|
5744
|
+
'isKit',
|
|
5745
|
+
'sku',
|
|
5746
|
+
'rate',
|
|
5747
|
+
'tags',
|
|
5748
|
+
'type',
|
|
5749
|
+
'shoppingCount',
|
|
5750
|
+
'gender',
|
|
5751
|
+
'createdAt',
|
|
5752
|
+
];
|
|
5709
5753
|
const products = [];
|
|
5754
|
+
const mostRelevantsIds = category.getMostRelevantByShop(shop);
|
|
5755
|
+
if (mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length) {
|
|
5756
|
+
const { data: mostRelevants } = await this.productRepository.findCatalog({
|
|
5757
|
+
filters: Object.assign({ id: {
|
|
5758
|
+
operator: exports.Where.IN,
|
|
5759
|
+
value: mostRelevantsIds,
|
|
5760
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})),
|
|
5761
|
+
fields,
|
|
5762
|
+
options: { enableCount: false },
|
|
5763
|
+
orderBy: {
|
|
5764
|
+
stock: 'desc',
|
|
5765
|
+
shoppingCount: 'desc',
|
|
5766
|
+
rate: 'desc',
|
|
5767
|
+
name: 'asc',
|
|
5768
|
+
},
|
|
5769
|
+
}, shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5770
|
+
if (mostRelevants.length >= mostRelevantsIds.length) {
|
|
5771
|
+
const result = this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
|
|
5772
|
+
if (((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter) && ((_e = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _e === void 0 ? void 0 : _e.enabled))
|
|
5773
|
+
await this.saveToCache(category, shop, options, optionsCache, result);
|
|
5774
|
+
return result;
|
|
5775
|
+
}
|
|
5776
|
+
products.push(...mostRelevants);
|
|
5777
|
+
}
|
|
5778
|
+
const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
|
|
5710
5779
|
const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
|
|
5711
5780
|
operator: exports.Where.IN,
|
|
5712
|
-
value:
|
|
5713
|
-
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, (options.limit ? { 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: {
|
|
5781
|
+
value: productIds,
|
|
5782
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
|
|
5740
5783
|
stock: 'desc',
|
|
5741
5784
|
shoppingCount: 'desc',
|
|
5742
5785
|
rate: 'desc',
|
|
5743
5786
|
name: 'asc',
|
|
5744
5787
|
} }), shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5745
|
-
const
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
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;
|
|
5788
|
+
const result = this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
|
|
5789
|
+
if (((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) && ((_g = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _g === void 0 ? void 0 : _g.enabled))
|
|
5790
|
+
await this.saveToCache(category, shop, options, optionsCache, result);
|
|
5791
|
+
return result;
|
|
5756
5792
|
}
|
|
5757
5793
|
async getChildren(parentId, _optionsCache) {
|
|
5758
5794
|
const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
|
|
@@ -5888,6 +5924,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5888
5924
|
return filters;
|
|
5889
5925
|
}
|
|
5890
5926
|
}
|
|
5927
|
+
async saveToCache(category, shop, options, optionsCache, result) {
|
|
5928
|
+
var _a;
|
|
5929
|
+
const cacheKey = `${this.model.name.toLowerCase()}:mountCategory:${category.id}:${shop}:${MD5GeneratorHelper.generateMD5(options)}`;
|
|
5930
|
+
await this.cache.cacheAdapter.set({
|
|
5931
|
+
key: cacheKey,
|
|
5932
|
+
data: JSON.stringify(result),
|
|
5933
|
+
expirationInSeconds: ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.ttl) || this.cache.ttlDefault,
|
|
5934
|
+
});
|
|
5935
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5936
|
+
}
|
|
5891
5937
|
}
|
|
5892
5938
|
tslib.__decorate([
|
|
5893
5939
|
Log(),
|
|
@@ -5908,6 +5954,7 @@ tslib.__decorate([
|
|
|
5908
5954
|
tslib.__metadata("design:returntype", Promise)
|
|
5909
5955
|
], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
|
|
5910
5956
|
tslib.__decorate([
|
|
5957
|
+
Log(),
|
|
5911
5958
|
Log(),
|
|
5912
5959
|
tslib.__metadata("design:type", Function),
|
|
5913
5960
|
tslib.__metadata("design:paramtypes", [Category, String, Object, Object]),
|
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"]);
|
|
@@ -5695,58 +5706,83 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5695
5706
|
return homeSections;
|
|
5696
5707
|
}
|
|
5697
5708
|
async mountCategory(category, shop, options, optionsCache) {
|
|
5698
|
-
var _a;
|
|
5709
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
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
|
-
|
|
5702
|
-
|
|
5712
|
+
if (((_b = this.cache) === null || _b === void 0 ? void 0 : _b.cacheAdapter) && ((_c = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _c === void 0 ? void 0 : _c.enabled)) {
|
|
5713
|
+
const cacheKey = `${this.model.name.toLowerCase()}:mountCategory:${category.id}:${shop}:${MD5GeneratorHelper.generateMD5(options)}`;
|
|
5714
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
5715
|
+
if (cachedData) {
|
|
5716
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
5717
|
+
return JSON.parse(cachedData);
|
|
5718
|
+
}
|
|
5719
|
+
}
|
|
5720
|
+
const fields = [
|
|
5721
|
+
'id',
|
|
5722
|
+
'name',
|
|
5723
|
+
'slug',
|
|
5724
|
+
'images',
|
|
5725
|
+
'miniatures',
|
|
5726
|
+
'price',
|
|
5727
|
+
'fullPrice',
|
|
5728
|
+
'subscriberDiscountPercentage',
|
|
5729
|
+
'subscriberPrice',
|
|
5730
|
+
'stock',
|
|
5731
|
+
'published',
|
|
5732
|
+
'CEST',
|
|
5733
|
+
'EAN',
|
|
5734
|
+
'NCM',
|
|
5735
|
+
'brand',
|
|
5736
|
+
'costPrice',
|
|
5737
|
+
'hasVariants',
|
|
5738
|
+
'isKit',
|
|
5739
|
+
'sku',
|
|
5740
|
+
'rate',
|
|
5741
|
+
'tags',
|
|
5742
|
+
'type',
|
|
5743
|
+
'shoppingCount',
|
|
5744
|
+
'gender',
|
|
5745
|
+
'createdAt',
|
|
5746
|
+
];
|
|
5703
5747
|
const products = [];
|
|
5748
|
+
const mostRelevantsIds = category.getMostRelevantByShop(shop);
|
|
5749
|
+
if (mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length) {
|
|
5750
|
+
const { data: mostRelevants } = await this.productRepository.findCatalog({
|
|
5751
|
+
filters: Object.assign({ id: {
|
|
5752
|
+
operator: Where.IN,
|
|
5753
|
+
value: mostRelevantsIds,
|
|
5754
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})),
|
|
5755
|
+
fields,
|
|
5756
|
+
options: { enableCount: false },
|
|
5757
|
+
orderBy: {
|
|
5758
|
+
stock: 'desc',
|
|
5759
|
+
shoppingCount: 'desc',
|
|
5760
|
+
rate: 'desc',
|
|
5761
|
+
name: 'asc',
|
|
5762
|
+
},
|
|
5763
|
+
}, shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5764
|
+
if (mostRelevants.length >= mostRelevantsIds.length) {
|
|
5765
|
+
const result = this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
|
|
5766
|
+
if (((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter) && ((_e = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _e === void 0 ? void 0 : _e.enabled))
|
|
5767
|
+
await this.saveToCache(category, shop, options, optionsCache, result);
|
|
5768
|
+
return result;
|
|
5769
|
+
}
|
|
5770
|
+
products.push(...mostRelevants);
|
|
5771
|
+
}
|
|
5772
|
+
const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
|
|
5704
5773
|
const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
|
|
5705
5774
|
operator: Where.IN,
|
|
5706
|
-
value:
|
|
5707
|
-
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})) }, (options.limit ? { 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: {
|
|
5775
|
+
value: productIds,
|
|
5776
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
|
|
5734
5777
|
stock: 'desc',
|
|
5735
5778
|
shoppingCount: 'desc',
|
|
5736
5779
|
rate: 'desc',
|
|
5737
5780
|
name: 'asc',
|
|
5738
5781
|
} }), shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5739
|
-
const
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
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;
|
|
5782
|
+
const result = this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
|
|
5783
|
+
if (((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) && ((_g = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _g === void 0 ? void 0 : _g.enabled))
|
|
5784
|
+
await this.saveToCache(category, shop, options, optionsCache, result);
|
|
5785
|
+
return result;
|
|
5750
5786
|
}
|
|
5751
5787
|
async getChildren(parentId, _optionsCache) {
|
|
5752
5788
|
const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
|
|
@@ -5882,6 +5918,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5882
5918
|
return filters;
|
|
5883
5919
|
}
|
|
5884
5920
|
}
|
|
5921
|
+
async saveToCache(category, shop, options, optionsCache, result) {
|
|
5922
|
+
var _a;
|
|
5923
|
+
const cacheKey = `${this.model.name.toLowerCase()}:mountCategory:${category.id}:${shop}:${MD5GeneratorHelper.generateMD5(options)}`;
|
|
5924
|
+
await this.cache.cacheAdapter.set({
|
|
5925
|
+
key: cacheKey,
|
|
5926
|
+
data: JSON.stringify(result),
|
|
5927
|
+
expirationInSeconds: ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.ttl) || this.cache.ttlDefault,
|
|
5928
|
+
});
|
|
5929
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5930
|
+
}
|
|
5885
5931
|
}
|
|
5886
5932
|
__decorate([
|
|
5887
5933
|
Log(),
|
|
@@ -5902,6 +5948,7 @@ __decorate([
|
|
|
5902
5948
|
__metadata("design:returntype", Promise)
|
|
5903
5949
|
], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
|
|
5904
5950
|
__decorate([
|
|
5951
|
+
Log(),
|
|
5905
5952
|
Log(),
|
|
5906
5953
|
__metadata("design:type", Function),
|
|
5907
5954
|
__metadata("design:paramtypes", [Category, String, Object, Object]),
|
package/package.json
CHANGED