@infrab4a/connect 5.4.0-beta.6 → 5.4.0-beta.8

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
@@ -7384,6 +7384,7 @@ const commonFields$1 = [
7384
7384
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7385
7385
  { daysOfUse: { columnName: 'days_of_use' } },
7386
7386
  { showVariants: { columnName: 'show_variants' } },
7387
+ { variantSlug: { columnName: 'variant_slug' } },
7387
7388
  ];
7388
7389
  class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
7389
7390
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -7410,7 +7411,15 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7410
7411
  .then((res) => res.data.at(0));
7411
7412
  }
7412
7413
  async getByEAN(EAN, options) {
7413
- return super
7414
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7415
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7416
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7417
+ if (cachedData) {
7418
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7419
+ return this.model.toInstance(deserialize(cachedData));
7420
+ }
7421
+ }
7422
+ const product = await super
7414
7423
  .find({
7415
7424
  filters: {
7416
7425
  EAN,
@@ -7420,6 +7429,19 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7420
7429
  },
7421
7430
  })
7422
7431
  .then((res) => res.data.at(0));
7432
+ if (!product)
7433
+ return null;
7434
+ RoundProductPricesHelper.roundProductPrices(product);
7435
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7436
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7437
+ await this.cache.cacheAdapter.set({
7438
+ key: cacheKey,
7439
+ data: serialize(product),
7440
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7441
+ });
7442
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7443
+ }
7444
+ return product;
7423
7445
  }
7424
7446
  async find(params, optionsParams) {
7425
7447
  const { filters, fields, ...options } = params || {};
@@ -7712,6 +7734,7 @@ const commonFields = [
7712
7734
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7713
7735
  { daysOfUse: { columnName: 'days_of_use' } },
7714
7736
  { showVariants: { columnName: 'show_variants' } },
7737
+ { variantSlug: { columnName: 'variant_slug' } },
7715
7738
  ];
7716
7739
  const fieldsConfiguration$2 = [
7717
7740
  ...commonFields,
@@ -7904,6 +7927,28 @@ const fieldsConfiguration$2 = [
7904
7927
  { tagsProfile: { columnName: 'tags_profile' } },
7905
7928
  { tagsCollection: { columnName: 'tags_collection' } },
7906
7929
  { variantSlug: { columnName: 'variant_slug' } },
7930
+ {
7931
+ reviews: {
7932
+ columnName: 'reviews',
7933
+ foreignKeyColumn: { product_id: 'id' },
7934
+ fields: [
7935
+ 'id',
7936
+ 'shop',
7937
+ 'rate',
7938
+ 'author',
7939
+ 'email',
7940
+ 'location',
7941
+ 'review',
7942
+ 'status',
7943
+ 'title',
7944
+ { personId: { columnName: 'person_id' } },
7945
+ 'points',
7946
+ { orderId: { columnName: 'order_id' } },
7947
+ { createdAt: { columnName: 'created_at' } },
7948
+ { updatedAt: { columnName: 'updated_at' } },
7949
+ ],
7950
+ },
7951
+ },
7907
7952
  ],
7908
7953
  },
7909
7954
  },
@@ -7967,10 +8012,14 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7967
8012
  ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7968
8013
  .data?.[0]
7969
8014
  : await super.get(identifiers, options);
7970
- // if (product.productId) throw new NotFoundError('Product not found, it is a variant')
7971
- product.reviews =
7972
- product.reviews ||
7973
- (await this.findReviewsByProduct(product.productId ? +product.productId : +product.id, false, options));
8015
+ if (product.productId)
8016
+ throw new NotFoundError('Product not found, it is a variant');
8017
+ product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
8018
+ if (!product.variants?.length) {
8019
+ for (const [index, variant] of product.variants.entries()) {
8020
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8021
+ }
8022
+ }
7974
8023
  return product;
7975
8024
  }
7976
8025
  async find(params, optionsParams) {
@@ -7988,8 +8037,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7988
8037
  return super.find({
7989
8038
  ...options,
7990
8039
  filters: { ...filters },
7991
- // filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
7992
- // filters: { ...filters, productId: { operator: Where.ISNULL } },
7993
8040
  fields: [
7994
8041
  ...bindFields,
7995
8042
  ...(bindFields.includes('price')
@@ -8026,8 +8073,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8026
8073
  if (!result.data.length)
8027
8074
  return null;
8028
8075
  const product = result?.data?.shift();
8029
- if (!product.reviews.length && product.rate > 0) {
8030
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8076
+ if (!product.variants?.length) {
8077
+ for (const [index, variant] of product.variants.entries()) {
8078
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8079
+ }
8031
8080
  }
8032
8081
  RoundProductPricesHelper.roundProductPrices(product);
8033
8082
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
@@ -8041,18 +8090,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8041
8090
  }
8042
8091
  return product;
8043
8092
  }
8044
- async getBySlugVariantData(product) {
8045
- if (!product.reviews.length && product.rate > 0) {
8046
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8047
- }
8048
- // if (!product.metadata) {
8049
- // product.metadata = await this.findReviewsByProduct(
8050
- // (product.productId ? product.productId : product.id) as number,
8051
- // true,
8052
- // )
8053
- // }
8054
- return product;
8055
- }
8056
8093
  async getByEAN(EAN, options) {
8057
8094
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
8058
8095
  const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
@@ -8260,6 +8297,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8260
8297
  type: 'product_review_bool_exp',
8261
8298
  required: true,
8262
8299
  },
8300
+ order_by: {
8301
+ type: '[product_review_order_by]',
8302
+ value: [{ createdAt: 'desc' }],
8303
+ required: true,
8304
+ },
8263
8305
  });
8264
8306
  const reviews = data?.map((review) => this.bindReviewToModel(review));
8265
8307
  if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
@@ -8687,6 +8729,28 @@ const fieldsConfiguration$1 = [
8687
8729
  }),
8688
8730
  },
8689
8731
  },
8732
+ {
8733
+ reviews: {
8734
+ columnName: 'reviews',
8735
+ foreignKeyColumn: { product_id: 'id' },
8736
+ fields: [
8737
+ 'id',
8738
+ 'shop',
8739
+ 'rate',
8740
+ 'author',
8741
+ 'email',
8742
+ 'location',
8743
+ 'review',
8744
+ 'status',
8745
+ 'title',
8746
+ { personId: { columnName: 'person_id' } },
8747
+ 'points',
8748
+ { orderId: { columnName: 'order_id' } },
8749
+ { createdAt: { columnName: 'created_at' } },
8750
+ { updatedAt: { columnName: 'updated_at' } },
8751
+ ],
8752
+ },
8753
+ },
8690
8754
  { variantSlug: { columnName: 'variant_slug' } },
8691
8755
  { createdAt: { columnName: 'created_at' } },
8692
8756
  { updatedAt: { columnName: 'updated_at' } },
package/index.esm.js CHANGED
@@ -7360,6 +7360,7 @@ const commonFields$1 = [
7360
7360
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7361
7361
  { daysOfUse: { columnName: 'days_of_use' } },
7362
7362
  { showVariants: { columnName: 'show_variants' } },
7363
+ { variantSlug: { columnName: 'variant_slug' } },
7363
7364
  ];
7364
7365
  class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
7365
7366
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -7386,7 +7387,15 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7386
7387
  .then((res) => res.data.at(0));
7387
7388
  }
7388
7389
  async getByEAN(EAN, options) {
7389
- return super
7390
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7391
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7392
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7393
+ if (cachedData) {
7394
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7395
+ return this.model.toInstance(deserialize(cachedData));
7396
+ }
7397
+ }
7398
+ const product = await super
7390
7399
  .find({
7391
7400
  filters: {
7392
7401
  EAN,
@@ -7396,6 +7405,19 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
7396
7405
  },
7397
7406
  })
7398
7407
  .then((res) => res.data.at(0));
7408
+ if (!product)
7409
+ return null;
7410
+ RoundProductPricesHelper.roundProductPrices(product);
7411
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7412
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7413
+ await this.cache.cacheAdapter.set({
7414
+ key: cacheKey,
7415
+ data: serialize(product),
7416
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7417
+ });
7418
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7419
+ }
7420
+ return product;
7399
7421
  }
7400
7422
  async find(params, optionsParams) {
7401
7423
  const { filters, fields, ...options } = params || {};
@@ -7688,6 +7710,7 @@ const commonFields = [
7688
7710
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7689
7711
  { daysOfUse: { columnName: 'days_of_use' } },
7690
7712
  { showVariants: { columnName: 'show_variants' } },
7713
+ { variantSlug: { columnName: 'variant_slug' } },
7691
7714
  ];
7692
7715
  const fieldsConfiguration$2 = [
7693
7716
  ...commonFields,
@@ -7880,6 +7903,28 @@ const fieldsConfiguration$2 = [
7880
7903
  { tagsProfile: { columnName: 'tags_profile' } },
7881
7904
  { tagsCollection: { columnName: 'tags_collection' } },
7882
7905
  { variantSlug: { columnName: 'variant_slug' } },
7906
+ {
7907
+ reviews: {
7908
+ columnName: 'reviews',
7909
+ foreignKeyColumn: { product_id: 'id' },
7910
+ fields: [
7911
+ 'id',
7912
+ 'shop',
7913
+ 'rate',
7914
+ 'author',
7915
+ 'email',
7916
+ 'location',
7917
+ 'review',
7918
+ 'status',
7919
+ 'title',
7920
+ { personId: { columnName: 'person_id' } },
7921
+ 'points',
7922
+ { orderId: { columnName: 'order_id' } },
7923
+ { createdAt: { columnName: 'created_at' } },
7924
+ { updatedAt: { columnName: 'updated_at' } },
7925
+ ],
7926
+ },
7927
+ },
7883
7928
  ],
7884
7929
  },
7885
7930
  },
@@ -7943,10 +7988,14 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7943
7988
  ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
7944
7989
  .data?.[0]
7945
7990
  : await super.get(identifiers, options);
7946
- // if (product.productId) throw new NotFoundError('Product not found, it is a variant')
7947
- product.reviews =
7948
- product.reviews ||
7949
- (await this.findReviewsByProduct(product.productId ? +product.productId : +product.id, false, options));
7991
+ if (product.productId)
7992
+ throw new NotFoundError('Product not found, it is a variant');
7993
+ product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
7994
+ if (!product.variants?.length) {
7995
+ for (const [index, variant] of product.variants.entries()) {
7996
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
7997
+ }
7998
+ }
7950
7999
  return product;
7951
8000
  }
7952
8001
  async find(params, optionsParams) {
@@ -7964,8 +8013,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7964
8013
  return super.find({
7965
8014
  ...options,
7966
8015
  filters: { ...filters },
7967
- // filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
7968
- // filters: { ...filters, productId: { operator: Where.ISNULL } },
7969
8016
  fields: [
7970
8017
  ...bindFields,
7971
8018
  ...(bindFields.includes('price')
@@ -8002,8 +8049,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8002
8049
  if (!result.data.length)
8003
8050
  return null;
8004
8051
  const product = result?.data?.shift();
8005
- if (!product.reviews.length && product.rate > 0) {
8006
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8052
+ if (!product.variants?.length) {
8053
+ for (const [index, variant] of product.variants.entries()) {
8054
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8055
+ }
8007
8056
  }
8008
8057
  RoundProductPricesHelper.roundProductPrices(product);
8009
8058
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
@@ -8017,18 +8066,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8017
8066
  }
8018
8067
  return product;
8019
8068
  }
8020
- async getBySlugVariantData(product) {
8021
- if (!product.reviews.length && product.rate > 0) {
8022
- product.reviews = await this.findReviewsByProduct((product.productId ? product.productId : product.id), true);
8023
- }
8024
- // if (!product.metadata) {
8025
- // product.metadata = await this.findReviewsByProduct(
8026
- // (product.productId ? product.productId : product.id) as number,
8027
- // true,
8028
- // )
8029
- // }
8030
- return product;
8031
- }
8032
8069
  async getByEAN(EAN, options) {
8033
8070
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
8034
8071
  const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
@@ -8236,6 +8273,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8236
8273
  type: 'product_review_bool_exp',
8237
8274
  required: true,
8238
8275
  },
8276
+ order_by: {
8277
+ type: '[product_review_order_by]',
8278
+ value: [{ createdAt: 'desc' }],
8279
+ required: true,
8280
+ },
8239
8281
  });
8240
8282
  const reviews = data?.map((review) => this.bindReviewToModel(review));
8241
8283
  if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
@@ -8663,6 +8705,28 @@ const fieldsConfiguration$1 = [
8663
8705
  }),
8664
8706
  },
8665
8707
  },
8708
+ {
8709
+ reviews: {
8710
+ columnName: 'reviews',
8711
+ foreignKeyColumn: { product_id: 'id' },
8712
+ fields: [
8713
+ 'id',
8714
+ 'shop',
8715
+ 'rate',
8716
+ 'author',
8717
+ 'email',
8718
+ 'location',
8719
+ 'review',
8720
+ 'status',
8721
+ 'title',
8722
+ { personId: { columnName: 'person_id' } },
8723
+ 'points',
8724
+ { orderId: { columnName: 'order_id' } },
8725
+ { createdAt: { columnName: 'created_at' } },
8726
+ { updatedAt: { columnName: 'updated_at' } },
8727
+ ],
8728
+ },
8729
+ },
8666
8730
  { variantSlug: { columnName: 'variant_slug' } },
8667
8731
  { createdAt: { columnName: 'created_at' } },
8668
8732
  { updatedAt: { columnName: 'updated_at' } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "5.4.0-beta.6",
3
+ "version": "5.4.0-beta.8",
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[];
@@ -4,6 +4,5 @@ export type ProductVariantIdentifiers = 'id' | 'productId';
4
4
  export declare class Variant extends ProductBase<Variant, ProductVariantIdentifiers> {
5
5
  productId: string;
6
6
  grade?: VariantGrade[];
7
- variantSlug?: string;
8
7
  static get identifiersFields(): ProductVariantIdentifiers[];
9
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;
@@ -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>;