@infrab4a/connect 5.4.0-beta.1 → 5.4.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
@@ -871,11 +871,7 @@ class Variant extends ProductBase {
871
871
  static get identifiersFields() {
872
872
  return ['id', 'productId'];
873
873
  }
874
- }
875
- tslib.__decorate([
876
- classTransformer.Type(() => Product),
877
- tslib.__metadata("design:type", Product)
878
- ], Variant.prototype, "product", void 0);
874
+ }
879
875
 
880
876
  class Product extends ProductBase {
881
877
  }
@@ -3396,8 +3392,6 @@ class HasuraQueryBuilderHelper {
3396
3392
  class HasuraRequestHelper {
3397
3393
  static async fetch(params) {
3398
3394
  const { variables, query, endpoint, headers, logger } = params;
3399
- console.warn('variables', variables);
3400
- console.warn('query', query);
3401
3395
  const request = {
3402
3396
  url: endpoint,
3403
3397
  method: 'POST',
@@ -5857,6 +5851,9 @@ tslib.__decorate([
5857
5851
  tslib.__metadata("design:type", Product)
5858
5852
  ], KitProductHasuraGraphQL.prototype, "product", void 0);
5859
5853
 
5854
+ class ProductCatalogHasuraGraphQL extends Product {
5855
+ }
5856
+
5860
5857
  class ProductHasuraGraphQL extends Product {
5861
5858
  }
5862
5859
  tslib.__decorate([
@@ -7377,18 +7374,26 @@ const commonFields$1 = [
7377
7374
  { reviewsTotal: { columnName: 'reviews_total' } },
7378
7375
  { shoppingCount: { columnName: 'shopping_count' } },
7379
7376
  { categoryId: { columnName: 'category_id' } },
7377
+ {
7378
+ category: {
7379
+ columnName: 'category',
7380
+ foreignKeyColumn: { id: 'categoryId' },
7381
+ fields: ['id', 'name', 'reference', 'slug'],
7382
+ },
7383
+ },
7380
7384
  'group',
7381
7385
  'validity',
7382
7386
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7383
7387
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7384
7388
  { daysOfUse: { columnName: 'days_of_use' } },
7385
7389
  { showVariants: { columnName: 'show_variants' } },
7390
+ { variantSlug: { columnName: 'variant_slug' } },
7386
7391
  ];
7387
7392
  class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
7388
7393
  constructor({ endpoint, authOptions, interceptors, cache, }) {
7389
7394
  super({
7390
7395
  tableName: 'product_catalog',
7391
- model: ProductHasuraGraphQL,
7396
+ model: ProductCatalogHasuraGraphQL,
7392
7397
  endpoint,
7393
7398
  authOptions,
7394
7399
  interceptors,
@@ -7396,8 +7401,16 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7396
7401
  cache,
7397
7402
  });
7398
7403
  }
7399
- async get({ id }) {
7400
- return super
7404
+ async get({ id }, options) {
7405
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7406
+ const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
7407
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7408
+ if (cachedData) {
7409
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7410
+ return this.model.toInstance(deserialize(cachedData));
7411
+ }
7412
+ }
7413
+ const product = await super
7401
7414
  .find({
7402
7415
  filters: {
7403
7416
  id,
@@ -7407,9 +7420,29 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7407
7420
  },
7408
7421
  })
7409
7422
  .then((res) => res.data.at(0));
7423
+ if (!product)
7424
+ throw new NotFoundError(`Product not found`);
7425
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7426
+ const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
7427
+ await this.cache.cacheAdapter.set({
7428
+ key: cacheKey,
7429
+ data: serialize(product),
7430
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7431
+ });
7432
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7433
+ }
7434
+ return product;
7410
7435
  }
7411
7436
  async getByEAN(EAN, options) {
7412
- return super
7437
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7438
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7439
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7440
+ if (cachedData) {
7441
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7442
+ return this.model.toInstance(deserialize(cachedData));
7443
+ }
7444
+ }
7445
+ const product = await super
7413
7446
  .find({
7414
7447
  filters: {
7415
7448
  EAN,
@@ -7419,6 +7452,19 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7419
7452
  },
7420
7453
  })
7421
7454
  .then((res) => res.data.at(0));
7455
+ if (!product)
7456
+ return null;
7457
+ RoundProductPricesHelper.roundProductPrices(product);
7458
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7459
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7460
+ await this.cache.cacheAdapter.set({
7461
+ key: cacheKey,
7462
+ data: serialize(product),
7463
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7464
+ });
7465
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7466
+ }
7467
+ return product;
7422
7468
  }
7423
7469
  async find(params, optionsParams) {
7424
7470
  const { filters, fields, ...options } = params || {};
@@ -7711,6 +7757,7 @@ const commonFields = [
7711
7757
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7712
7758
  { daysOfUse: { columnName: 'days_of_use' } },
7713
7759
  { showVariants: { columnName: 'show_variants' } },
7760
+ { variantSlug: { columnName: 'variant_slug' } },
7714
7761
  ];
7715
7762
  const fieldsConfiguration$2 = [
7716
7763
  ...commonFields,
@@ -7902,6 +7949,29 @@ const fieldsConfiguration$2 = [
7902
7949
  },
7903
7950
  { tagsProfile: { columnName: 'tags_profile' } },
7904
7951
  { tagsCollection: { columnName: 'tags_collection' } },
7952
+ { variantSlug: { columnName: 'variant_slug' } },
7953
+ {
7954
+ reviews: {
7955
+ columnName: 'reviews',
7956
+ foreignKeyColumn: { product_id: 'id' },
7957
+ fields: [
7958
+ 'id',
7959
+ 'shop',
7960
+ 'rate',
7961
+ 'author',
7962
+ 'email',
7963
+ 'location',
7964
+ 'review',
7965
+ 'status',
7966
+ 'title',
7967
+ { personId: { columnName: 'person_id' } },
7968
+ 'points',
7969
+ { orderId: { columnName: 'order_id' } },
7970
+ { createdAt: { columnName: 'created_at' } },
7971
+ { updatedAt: { columnName: 'updated_at' } },
7972
+ ],
7973
+ },
7974
+ },
7905
7975
  ],
7906
7976
  },
7907
7977
  },
@@ -7965,10 +8035,14 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7965
8035
  ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7966
8036
  .data?.[0]
7967
8037
  : await super.get(identifiers, options);
7968
- // if (product.productId) throw new NotFoundError('Product not found, it is a variant')
7969
- product.reviews =
7970
- product.reviews ||
7971
- (await this.findReviewsByProduct(product.productId ? +product.productId : +product.id, false, options));
8038
+ if (product.productId)
8039
+ throw new NotFoundError('Product not found, it is a variant');
8040
+ product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
8041
+ if (!product.variants?.length) {
8042
+ for (const [index, variant] of product.variants.entries()) {
8043
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8044
+ }
8045
+ }
7972
8046
  return product;
7973
8047
  }
7974
8048
  async find(params, optionsParams) {
@@ -7986,8 +8060,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7986
8060
  return super.find({
7987
8061
  ...options,
7988
8062
  filters: { ...filters },
7989
- // filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
7990
- // filters: { ...filters, productId: { operator: Where.ISNULL } },
7991
8063
  fields: [
7992
8064
  ...bindFields,
7993
8065
  ...(bindFields.includes('price')
@@ -8012,6 +8084,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8012
8084
  const result = await this.find({
8013
8085
  filters: {
8014
8086
  slug,
8087
+ productId: {
8088
+ operator: exports.Where.ISNULL,
8089
+ },
8015
8090
  },
8016
8091
  fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
8017
8092
  options: {
@@ -8021,12 +8096,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8021
8096
  if (!result.data.length)
8022
8097
  return null;
8023
8098
  const product = result?.data?.shift();
8024
- if (product.productId) ;
8025
- console.warn('product getBySlug', product);
8026
- console.warn('vai entrar', !product.reviews.length && product.rate > 0);
8027
- if (!product.reviews.length && product.rate > 0) {
8028
- console.warn('entrou');
8029
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8099
+ if (!product.variants?.length) {
8100
+ for (const [index, variant] of product.variants.entries()) {
8101
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8102
+ }
8030
8103
  }
8031
8104
  RoundProductPricesHelper.roundProductPrices(product);
8032
8105
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
@@ -8040,18 +8113,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8040
8113
  }
8041
8114
  return product;
8042
8115
  }
8043
- async getBySlugVariantData(product) {
8044
- if (!product.reviews.length && product.rate > 0) {
8045
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8046
- }
8047
- // if (!product.metadata) {
8048
- // product.metadata = await this.findReviewsByProduct(
8049
- // (product.productId ? product.productId : product.id) as number,
8050
- // true,
8051
- // )
8052
- // }
8053
- return product;
8054
- }
8055
8116
  async getByEAN(EAN, options) {
8056
8117
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
8057
8118
  const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
@@ -8259,6 +8320,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8259
8320
  type: 'product_review_bool_exp',
8260
8321
  required: true,
8261
8322
  },
8323
+ order_by: {
8324
+ type: '[product_review_order_by]',
8325
+ value: [{ createdAt: 'desc' }],
8326
+ required: true,
8327
+ },
8262
8328
  });
8263
8329
  const reviews = data?.map((review) => this.bindReviewToModel(review));
8264
8330
  if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
@@ -8677,6 +8743,13 @@ const fieldsConfiguration$1 = [
8677
8743
  { reviewsTotal: { columnName: 'reviews_total' } },
8678
8744
  { shoppingCount: { columnName: 'shopping_count' } },
8679
8745
  { categoryId: { columnName: 'category_id' } },
8746
+ {
8747
+ category: {
8748
+ columnName: 'category',
8749
+ foreignKeyColumn: { id: 'categoryId' },
8750
+ fields: ['id', 'name', 'reference', 'slug'],
8751
+ },
8752
+ },
8680
8753
  {
8681
8754
  metadata: {
8682
8755
  columnName: 'metadata',
@@ -8686,6 +8759,29 @@ const fieldsConfiguration$1 = [
8686
8759
  }),
8687
8760
  },
8688
8761
  },
8762
+ {
8763
+ reviews: {
8764
+ columnName: 'reviews',
8765
+ foreignKeyColumn: { product_id: 'id' },
8766
+ fields: [
8767
+ 'id',
8768
+ 'shop',
8769
+ 'rate',
8770
+ 'author',
8771
+ 'email',
8772
+ 'location',
8773
+ 'review',
8774
+ 'status',
8775
+ 'title',
8776
+ { personId: { columnName: 'person_id' } },
8777
+ 'points',
8778
+ { orderId: { columnName: 'order_id' } },
8779
+ { createdAt: { columnName: 'created_at' } },
8780
+ { updatedAt: { columnName: 'updated_at' } },
8781
+ ],
8782
+ },
8783
+ },
8784
+ { variantSlug: { columnName: 'variant_slug' } },
8689
8785
  { createdAt: { columnName: 'created_at' } },
8690
8786
  { updatedAt: { columnName: 'updated_at' } },
8691
8787
  ];
@@ -10310,6 +10406,7 @@ exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
10310
10406
  exports.PaymentProviderFactory = PaymentProviderFactory;
10311
10407
  exports.PaymentTransaction = PaymentTransaction;
10312
10408
  exports.Product = Product;
10409
+ exports.ProductCatalogHasuraGraphQL = ProductCatalogHasuraGraphQL;
10313
10410
  exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
10314
10411
  exports.ProductErrors = ProductErrors;
10315
10412
  exports.ProductErrorsHasuraGraphQL = ProductErrorsHasuraGraphQL;
package/index.esm.js CHANGED
@@ -847,11 +847,7 @@ class Variant extends ProductBase {
847
847
  static get identifiersFields() {
848
848
  return ['id', 'productId'];
849
849
  }
850
- }
851
- __decorate([
852
- Type(() => Product),
853
- __metadata("design:type", Product)
854
- ], Variant.prototype, "product", void 0);
850
+ }
855
851
 
856
852
  class Product extends ProductBase {
857
853
  }
@@ -3372,8 +3368,6 @@ class HasuraQueryBuilderHelper {
3372
3368
  class HasuraRequestHelper {
3373
3369
  static async fetch(params) {
3374
3370
  const { variables, query, endpoint, headers, logger } = params;
3375
- console.warn('variables', variables);
3376
- console.warn('query', query);
3377
3371
  const request = {
3378
3372
  url: endpoint,
3379
3373
  method: 'POST',
@@ -5833,6 +5827,9 @@ __decorate([
5833
5827
  __metadata("design:type", Product)
5834
5828
  ], KitProductHasuraGraphQL.prototype, "product", void 0);
5835
5829
 
5830
+ class ProductCatalogHasuraGraphQL extends Product {
5831
+ }
5832
+
5836
5833
  class ProductHasuraGraphQL extends Product {
5837
5834
  }
5838
5835
  __decorate([
@@ -7353,18 +7350,26 @@ const commonFields$1 = [
7353
7350
  { reviewsTotal: { columnName: 'reviews_total' } },
7354
7351
  { shoppingCount: { columnName: 'shopping_count' } },
7355
7352
  { categoryId: { columnName: 'category_id' } },
7353
+ {
7354
+ category: {
7355
+ columnName: 'category',
7356
+ foreignKeyColumn: { id: 'categoryId' },
7357
+ fields: ['id', 'name', 'reference', 'slug'],
7358
+ },
7359
+ },
7356
7360
  'group',
7357
7361
  'validity',
7358
7362
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7359
7363
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7360
7364
  { daysOfUse: { columnName: 'days_of_use' } },
7361
7365
  { showVariants: { columnName: 'show_variants' } },
7366
+ { variantSlug: { columnName: 'variant_slug' } },
7362
7367
  ];
7363
7368
  class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
7364
7369
  constructor({ endpoint, authOptions, interceptors, cache, }) {
7365
7370
  super({
7366
7371
  tableName: 'product_catalog',
7367
- model: ProductHasuraGraphQL,
7372
+ model: ProductCatalogHasuraGraphQL,
7368
7373
  endpoint,
7369
7374
  authOptions,
7370
7375
  interceptors,
@@ -7372,8 +7377,16 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7372
7377
  cache,
7373
7378
  });
7374
7379
  }
7375
- async get({ id }) {
7376
- return super
7380
+ async get({ id }, options) {
7381
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7382
+ const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
7383
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7384
+ if (cachedData) {
7385
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7386
+ return this.model.toInstance(deserialize(cachedData));
7387
+ }
7388
+ }
7389
+ const product = await super
7377
7390
  .find({
7378
7391
  filters: {
7379
7392
  id,
@@ -7383,9 +7396,29 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7383
7396
  },
7384
7397
  })
7385
7398
  .then((res) => res.data.at(0));
7399
+ if (!product)
7400
+ throw new NotFoundError(`Product not found`);
7401
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7402
+ const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
7403
+ await this.cache.cacheAdapter.set({
7404
+ key: cacheKey,
7405
+ data: serialize(product),
7406
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7407
+ });
7408
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7409
+ }
7410
+ return product;
7386
7411
  }
7387
7412
  async getByEAN(EAN, options) {
7388
- return super
7413
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7414
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7415
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7416
+ if (cachedData) {
7417
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7418
+ return this.model.toInstance(deserialize(cachedData));
7419
+ }
7420
+ }
7421
+ const product = await super
7389
7422
  .find({
7390
7423
  filters: {
7391
7424
  EAN,
@@ -7395,6 +7428,19 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7395
7428
  },
7396
7429
  })
7397
7430
  .then((res) => res.data.at(0));
7431
+ if (!product)
7432
+ return null;
7433
+ RoundProductPricesHelper.roundProductPrices(product);
7434
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7435
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7436
+ await this.cache.cacheAdapter.set({
7437
+ key: cacheKey,
7438
+ data: serialize(product),
7439
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7440
+ });
7441
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7442
+ }
7443
+ return product;
7398
7444
  }
7399
7445
  async find(params, optionsParams) {
7400
7446
  const { filters, fields, ...options } = params || {};
@@ -7687,6 +7733,7 @@ const commonFields = [
7687
7733
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7688
7734
  { daysOfUse: { columnName: 'days_of_use' } },
7689
7735
  { showVariants: { columnName: 'show_variants' } },
7736
+ { variantSlug: { columnName: 'variant_slug' } },
7690
7737
  ];
7691
7738
  const fieldsConfiguration$2 = [
7692
7739
  ...commonFields,
@@ -7878,6 +7925,29 @@ const fieldsConfiguration$2 = [
7878
7925
  },
7879
7926
  { tagsProfile: { columnName: 'tags_profile' } },
7880
7927
  { tagsCollection: { columnName: 'tags_collection' } },
7928
+ { variantSlug: { columnName: 'variant_slug' } },
7929
+ {
7930
+ reviews: {
7931
+ columnName: 'reviews',
7932
+ foreignKeyColumn: { product_id: 'id' },
7933
+ fields: [
7934
+ 'id',
7935
+ 'shop',
7936
+ 'rate',
7937
+ 'author',
7938
+ 'email',
7939
+ 'location',
7940
+ 'review',
7941
+ 'status',
7942
+ 'title',
7943
+ { personId: { columnName: 'person_id' } },
7944
+ 'points',
7945
+ { orderId: { columnName: 'order_id' } },
7946
+ { createdAt: { columnName: 'created_at' } },
7947
+ { updatedAt: { columnName: 'updated_at' } },
7948
+ ],
7949
+ },
7950
+ },
7881
7951
  ],
7882
7952
  },
7883
7953
  },
@@ -7941,10 +8011,14 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7941
8011
  ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7942
8012
  .data?.[0]
7943
8013
  : await super.get(identifiers, options);
7944
- // if (product.productId) throw new NotFoundError('Product not found, it is a variant')
7945
- product.reviews =
7946
- product.reviews ||
7947
- (await this.findReviewsByProduct(product.productId ? +product.productId : +product.id, false, options));
8014
+ if (product.productId)
8015
+ throw new NotFoundError('Product not found, it is a variant');
8016
+ product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
8017
+ if (!product.variants?.length) {
8018
+ for (const [index, variant] of product.variants.entries()) {
8019
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8020
+ }
8021
+ }
7948
8022
  return product;
7949
8023
  }
7950
8024
  async find(params, optionsParams) {
@@ -7962,8 +8036,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7962
8036
  return super.find({
7963
8037
  ...options,
7964
8038
  filters: { ...filters },
7965
- // filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
7966
- // filters: { ...filters, productId: { operator: Where.ISNULL } },
7967
8039
  fields: [
7968
8040
  ...bindFields,
7969
8041
  ...(bindFields.includes('price')
@@ -7988,6 +8060,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7988
8060
  const result = await this.find({
7989
8061
  filters: {
7990
8062
  slug,
8063
+ productId: {
8064
+ operator: Where.ISNULL,
8065
+ },
7991
8066
  },
7992
8067
  fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
7993
8068
  options: {
@@ -7997,12 +8072,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7997
8072
  if (!result.data.length)
7998
8073
  return null;
7999
8074
  const product = result?.data?.shift();
8000
- if (product.productId) ;
8001
- console.warn('product getBySlug', product);
8002
- console.warn('vai entrar', !product.reviews.length && product.rate > 0);
8003
- if (!product.reviews.length && product.rate > 0) {
8004
- console.warn('entrou');
8005
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8075
+ if (!product.variants?.length) {
8076
+ for (const [index, variant] of product.variants.entries()) {
8077
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8078
+ }
8006
8079
  }
8007
8080
  RoundProductPricesHelper.roundProductPrices(product);
8008
8081
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
@@ -8016,18 +8089,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8016
8089
  }
8017
8090
  return product;
8018
8091
  }
8019
- async getBySlugVariantData(product) {
8020
- if (!product.reviews.length && product.rate > 0) {
8021
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8022
- }
8023
- // if (!product.metadata) {
8024
- // product.metadata = await this.findReviewsByProduct(
8025
- // (product.productId ? product.productId : product.id) as number,
8026
- // true,
8027
- // )
8028
- // }
8029
- return product;
8030
- }
8031
8092
  async getByEAN(EAN, options) {
8032
8093
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
8033
8094
  const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
@@ -8235,6 +8296,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8235
8296
  type: 'product_review_bool_exp',
8236
8297
  required: true,
8237
8298
  },
8299
+ order_by: {
8300
+ type: '[product_review_order_by]',
8301
+ value: [{ createdAt: 'desc' }],
8302
+ required: true,
8303
+ },
8238
8304
  });
8239
8305
  const reviews = data?.map((review) => this.bindReviewToModel(review));
8240
8306
  if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
@@ -8653,6 +8719,13 @@ const fieldsConfiguration$1 = [
8653
8719
  { reviewsTotal: { columnName: 'reviews_total' } },
8654
8720
  { shoppingCount: { columnName: 'shopping_count' } },
8655
8721
  { categoryId: { columnName: 'category_id' } },
8722
+ {
8723
+ category: {
8724
+ columnName: 'category',
8725
+ foreignKeyColumn: { id: 'categoryId' },
8726
+ fields: ['id', 'name', 'reference', 'slug'],
8727
+ },
8728
+ },
8656
8729
  {
8657
8730
  metadata: {
8658
8731
  columnName: 'metadata',
@@ -8662,6 +8735,29 @@ const fieldsConfiguration$1 = [
8662
8735
  }),
8663
8736
  },
8664
8737
  },
8738
+ {
8739
+ reviews: {
8740
+ columnName: 'reviews',
8741
+ foreignKeyColumn: { product_id: 'id' },
8742
+ fields: [
8743
+ 'id',
8744
+ 'shop',
8745
+ 'rate',
8746
+ 'author',
8747
+ 'email',
8748
+ 'location',
8749
+ 'review',
8750
+ 'status',
8751
+ 'title',
8752
+ { personId: { columnName: 'person_id' } },
8753
+ 'points',
8754
+ { orderId: { columnName: 'order_id' } },
8755
+ { createdAt: { columnName: 'created_at' } },
8756
+ { updatedAt: { columnName: 'updated_at' } },
8757
+ ],
8758
+ },
8759
+ },
8760
+ { variantSlug: { columnName: 'variant_slug' } },
8665
8761
  { createdAt: { columnName: 'created_at' } },
8666
8762
  { updatedAt: { columnName: 'updated_at' } },
8667
8763
  ];
@@ -10062,4 +10158,4 @@ class ProductsVertexSearch {
10062
10158
  }
10063
10159
  }
10064
10160
 
10065
- export { AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductCatalogHasuraGraphQLRepository, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, TransactionPaymentMethods, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isDebuggable, isUUID, parseDateTime, registerClass, resolveClass, serialize, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
10161
+ export { AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductCatalogHasuraGraphQL, ProductCatalogHasuraGraphQLRepository, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, TransactionPaymentMethods, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isDebuggable, isUUID, parseDateTime, registerClass, resolveClass, serialize, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "5.4.0-beta.1",
3
+ "version": "5.4.0-beta.11",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -40,6 +40,7 @@ export declare class ProductBase<T extends ProductBase<T, I>, I = ProductIdentif
40
40
  group?: number;
41
41
  validity: boolean;
42
42
  daysOfUse?: number;
43
+ variantSlug?: string;
43
44
  category: Category;
44
45
  kitProducts?: KitProduct[];
45
46
  reviews?: ProductReview[];
@@ -1,10 +1,8 @@
1
- import { Product } from './product';
2
1
  import { ProductBase } from './product-base';
3
2
  import { VariantGrade } from './types';
4
3
  export type ProductVariantIdentifiers = 'id' | 'productId';
5
4
  export declare class Variant extends ProductBase<Variant, ProductVariantIdentifiers> {
6
5
  productId: string;
7
6
  grade?: VariantGrade[];
8
- product?: Product;
9
7
  static get identifiersFields(): ProductVariantIdentifiers[];
10
8
  }
@@ -1,9 +1,13 @@
1
+ import { ProductHasuraGraphQL } from '../../../infra';
1
2
  import { FindRepositoryParams, RepositoryCacheOptions, RepositoryFindResult } from '../../generic';
2
3
  import { Product, ProductGender } from '../models';
3
4
  export interface ProductCatalogRepository {
4
5
  get({ id }: {
5
6
  id: string;
6
7
  }): Promise<Product>;
8
+ find(params?: FindRepositoryParams<ProductHasuraGraphQL>, optionsParams?: {
9
+ cache?: RepositoryCacheOptions;
10
+ }): Promise<RepositoryFindResult<ProductHasuraGraphQL>>;
7
11
  getByEAN(EAN: string, options?: {
8
12
  cache?: RepositoryCacheOptions;
9
13
  }): Promise<Product>;
@@ -11,6 +11,7 @@ export declare class Order extends Checkout {
11
11
  deliveredAt?: string;
12
12
  trackingEvents?: OrderTrackingEvent[];
13
13
  payment: PaymentTransaction;
14
+ pedidov?: number;
14
15
  reshipmentOrderId?: string;
15
16
  isChange?: boolean;
16
17
  isReshipment?: boolean;
@@ -5,7 +5,7 @@ import { FirestoreRepository, FirestoreSubRepository } from '../types';
5
5
  export declare const withHelpers: <TMixinBase extends MixinCtor<any, any[]> = MixinCtor<any, any[]>>(MixinBase: MixinCtor<any, any[]> & TMixinBase) => {
6
6
  new (...args: any[]): {
7
7
  [x: string]: any;
8
- toArray<T extends ModelBaseStructure<T, T["identifiersFields"][number]>>(snapShot: QuerySnapshot<T, import("firebase/firestore").DocumentData> | QueryDocumentSnapshot<T, import("firebase/firestore").DocumentData>[]): T[];
8
+ toArray<T extends ModelBaseStructure<T, T["identifiersFields"][number]>>(snapShot: QuerySnapshot<T> | QueryDocumentSnapshot<T>[]): T[];
9
9
  isSubCollection<T_1 extends ModelBaseStructure<T_1, T_1["identifiersFields"][number]>, E extends ModelBaseStructure<E, E["identifiersFields"][number]>>(repository: FirestoreRepository<T_1> | FirestoreSubRepository<T_1, E>): repository is FirestoreSubRepository<T_1, E>;
10
10
  };
11
11
  } & TMixinBase;
@@ -1,5 +1,6 @@
1
1
  export * from './category-hasura-graphql';
2
2
  export * from './kit-product-hasura-graphql';
3
+ export * from './product-catalog-hasura-graphql';
3
4
  export * from './product-errors-hasura-graphql';
4
5
  export * from './product-hasura-graphql';
5
6
  export * from './variant-hasura-graphql';
@@ -0,0 +1,16 @@
1
+ import { Product } from '../../../domain';
2
+ export declare class ProductCatalogHasuraGraphQL extends Product {
3
+ firestoreId?: string;
4
+ fullPrice?: number;
5
+ subscriberDiscountPercentage?: number;
6
+ subscriberPrice?: number;
7
+ productId?: number;
8
+ differentials?: string;
9
+ whoMustUse?: string;
10
+ howToUse?: string;
11
+ brandDescription?: string;
12
+ categoryId?: number;
13
+ ingredients?: string;
14
+ hasStock?: boolean;
15
+ intGender?: number;
16
+ }
@@ -5,4 +5,11 @@ export declare class VariantHasuraGraphQL extends Variant {
5
5
  subscriberDiscountPercentage?: number;
6
6
  subscriberPrice?: number;
7
7
  hasStock?: boolean;
8
+ differentials?: string;
9
+ whoMustUse?: string;
10
+ howToUse?: string;
11
+ brandDescription?: string;
12
+ categoryId?: number;
13
+ ingredients?: string;
14
+ intGender?: number;
8
15
  }
@@ -1,11 +1,13 @@
1
1
  import { FindRepositoryParams, Product, ProductCatalogRepository, ProductGender, RepositoryCacheOptions, RepositoryFindResult } from '../../../../domain';
2
2
  import { HasuraConstructorParams } from '../../mixins';
3
- import { ProductHasuraGraphQL } from '../../models';
4
- declare const ProductCatalogHasuraGraphQLRepository_base: import("../../../../utils").MixinCtor<import("../../types").GraphQLRepository<ProductHasuraGraphQL> & import("../../../../domain").FindRepository<ProductHasuraGraphQL, FindRepositoryParams<ProductHasuraGraphQL>>, any[]>;
3
+ import { ProductCatalogHasuraGraphQL, ProductHasuraGraphQL } from '../../models';
4
+ declare const ProductCatalogHasuraGraphQLRepository_base: import("../../../../utils").MixinCtor<import("../../types").GraphQLRepository<ProductCatalogHasuraGraphQL> & import("../../../../domain").FindRepository<ProductCatalogHasuraGraphQL, FindRepositoryParams<ProductCatalogHasuraGraphQL>>, any[]>;
5
5
  export declare class ProductCatalogHasuraGraphQLRepository extends ProductCatalogHasuraGraphQLRepository_base implements ProductCatalogRepository {
6
- constructor({ endpoint, authOptions, interceptors, cache, }: Pick<HasuraConstructorParams<ProductHasuraGraphQL>, 'endpoint' | 'authOptions' | 'interceptors' | 'cache'>);
6
+ constructor({ endpoint, authOptions, interceptors, cache, }: Pick<HasuraConstructorParams<ProductCatalogHasuraGraphQL>, 'endpoint' | 'authOptions' | 'interceptors' | 'cache'>);
7
7
  get({ id }: {
8
8
  id: string;
9
+ }, options?: {
10
+ cache?: RepositoryCacheOptions;
9
11
  }): Promise<Product>;
10
12
  getByEAN(EAN: string, options?: {
11
13
  cache?: RepositoryCacheOptions;
@@ -15,7 +15,6 @@ export declare class ProductHasuraGraphQLRepository extends ProductHasuraGraphQL
15
15
  getBySlug(slug: string, options?: {
16
16
  cache?: RepositoryCacheOptions;
17
17
  }): Promise<ProductHasuraGraphQL>;
18
- private getBySlugVariantData;
19
18
  getByEAN(EAN: string, options?: {
20
19
  cache?: RepositoryCacheOptions;
21
20
  }): Promise<ProductHasuraGraphQL>;