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

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
@@ -5712,9 +5712,17 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5712
5712
  return homeSections;
5713
5713
  }
5714
5714
  async mountCategory(category, shop, options, optionsCache) {
5715
- var _a;
5715
+ var _a, _b, _c, _d, _e, _f, _g;
5716
5716
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
5717
5717
  return [];
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
+ }
5718
5726
  const fields = [
5719
5727
  'id',
5720
5728
  'name',
@@ -5745,17 +5753,26 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5745
5753
  const products = [];
5746
5754
  const mostRelevantsIds = category.getMostRelevantByShop(shop);
5747
5755
  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: {
5756
+ const { data: mostRelevants } = await this.productRepository.findCatalog({
5757
+ filters: Object.assign({ id: {
5749
5758
  operator: exports.Where.IN,
5750
5759
  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: {
5760
+ }, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})),
5761
+ fields,
5762
+ options: { enableCount: false },
5763
+ orderBy: {
5752
5764
  stock: 'desc',
5753
5765
  shoppingCount: 'desc',
5754
5766
  rate: 'desc',
5755
5767
  name: 'asc',
5756
- } }), shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5757
- if (mostRelevants.length >= mostRelevantsIds.length)
5758
- return this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
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
+ }
5759
5776
  products.push(...mostRelevants);
5760
5777
  }
5761
5778
  const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
@@ -5768,7 +5785,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5768
5785
  rate: 'desc',
5769
5786
  name: 'asc',
5770
5787
  } }), shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5771
- return this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
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;
5772
5792
  }
5773
5793
  async getChildren(parentId, _optionsCache) {
5774
5794
  const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
@@ -5904,6 +5924,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5904
5924
  return filters;
5905
5925
  }
5906
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
+ }
5907
5937
  }
5908
5938
  tslib.__decorate([
5909
5939
  Log(),
@@ -5924,6 +5954,7 @@ tslib.__decorate([
5924
5954
  tslib.__metadata("design:returntype", Promise)
5925
5955
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5926
5956
  tslib.__decorate([
5957
+ Log(),
5927
5958
  Log(),
5928
5959
  tslib.__metadata("design:type", Function),
5929
5960
  tslib.__metadata("design:paramtypes", [Category, String, Object, Object]),
package/index.esm.js CHANGED
@@ -5706,9 +5706,17 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5706
5706
  return homeSections;
5707
5707
  }
5708
5708
  async mountCategory(category, shop, options, optionsCache) {
5709
- var _a;
5709
+ var _a, _b, _c, _d, _e, _f, _g;
5710
5710
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
5711
5711
  return [];
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
+ }
5712
5720
  const fields = [
5713
5721
  'id',
5714
5722
  'name',
@@ -5739,17 +5747,26 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5739
5747
  const products = [];
5740
5748
  const mostRelevantsIds = category.getMostRelevantByShop(shop);
5741
5749
  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: {
5750
+ const { data: mostRelevants } = await this.productRepository.findCatalog({
5751
+ filters: Object.assign({ id: {
5743
5752
  operator: Where.IN,
5744
5753
  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: {
5754
+ }, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})),
5755
+ fields,
5756
+ options: { enableCount: false },
5757
+ orderBy: {
5746
5758
  stock: 'desc',
5747
5759
  shoppingCount: 'desc',
5748
5760
  rate: 'desc',
5749
5761
  name: 'asc',
5750
- } }), shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5751
- if (mostRelevants.length >= mostRelevantsIds.length)
5752
- return this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
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
+ }
5753
5770
  products.push(...mostRelevants);
5754
5771
  }
5755
5772
  const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
@@ -5762,7 +5779,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5762
5779
  rate: 'desc',
5763
5780
  name: 'asc',
5764
5781
  } }), shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5765
- return this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
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;
5766
5786
  }
5767
5787
  async getChildren(parentId, _optionsCache) {
5768
5788
  const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
@@ -5898,6 +5918,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5898
5918
  return filters;
5899
5919
  }
5900
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
+ }
5901
5931
  }
5902
5932
  __decorate([
5903
5933
  Log(),
@@ -5918,6 +5948,7 @@ __decorate([
5918
5948
  __metadata("design:returntype", Promise)
5919
5949
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5920
5950
  __decorate([
5951
+ Log(),
5921
5952
  Log(),
5922
5953
  __metadata("design:type", Function),
5923
5954
  __metadata("design:paramtypes", [Category, String, Object, Object]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.25.0-beta.11",
3
+ "version": "4.25.0-beta.13",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -42,6 +42,7 @@ export declare class CategoryHasuraGraphQLRepository extends CategoryHasuraGraph
42
42
  private updateProducts;
43
43
  private updateMetadata;
44
44
  private updateFilters;
45
+ private saveToCache;
45
46
  private reorganizeMostRelevantsProducts;
46
47
  }
47
48
  export {};