@infrab4a/connect 5.4.0 → 5.5.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.esm.js CHANGED
@@ -845,7 +845,12 @@ class ProductReview extends BaseModel {
845
845
  static get identifiersFields() {
846
846
  return ['id'];
847
847
  }
848
- }
848
+ }
849
+ __decorate([
850
+ Type(resolveClass('Product')),
851
+ __metadata("design:type", Function)
852
+ ], ProductReview.prototype, "product", void 0);
853
+ registerClass('ProductReview', ProductReview);
849
854
 
850
855
  class ProductBase extends BaseModel {
851
856
  get evaluation() {
@@ -5919,6 +5924,9 @@ __decorate([
5919
5924
  __metadata("design:type", Product)
5920
5925
  ], KitProductHasuraGraphQL.prototype, "product", void 0);
5921
5926
 
5927
+ class ProductCatalogHasuraGraphQL extends Product {
5928
+ }
5929
+
5922
5930
  class ProductHasuraGraphQL extends Product {
5923
5931
  }
5924
5932
  __decorate([
@@ -7284,6 +7292,300 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
7284
7292
  }
7285
7293
  }
7286
7294
 
7295
+ const commonFields$1 = [
7296
+ {
7297
+ id: {
7298
+ columnName: 'id',
7299
+ to: (value) => +value,
7300
+ from: (value) => value.toString(),
7301
+ },
7302
+ },
7303
+ { firestoreId: { columnName: 'firestore_id' } },
7304
+ { productId: { columnName: 'main_product_id' } },
7305
+ { CEST: { columnName: 'cest' } },
7306
+ { EAN: { columnName: 'ean' } },
7307
+ { NCM: { columnName: 'ncm' } },
7308
+ 'brand',
7309
+ { costPrice: { columnName: 'cost_price' } },
7310
+ {
7311
+ description: {
7312
+ columnName: 'description',
7313
+ from: (description, data) => ({
7314
+ description,
7315
+ differentials: data.differentials,
7316
+ whoMustUse: data.who_must_use,
7317
+ howToUse: data.how_to_use,
7318
+ brand: data.brand_description,
7319
+ ingredients: data.ingredients,
7320
+ purpose: data.purpose,
7321
+ }),
7322
+ bindFindFilter: (filters) => {
7323
+ return {
7324
+ ...(filters?.description && { description: filters.description }),
7325
+ ...(filters.differentials && { differentials: filters.differentials }),
7326
+ ...(filters.whoMustUse && {
7327
+ who_must_use: filters.whoMustUse,
7328
+ }),
7329
+ ...(filters.howToUse && {
7330
+ how_to_use: filters.howToUse,
7331
+ }),
7332
+ ...(filters.brand && {
7333
+ brand_description: filters.brand,
7334
+ }),
7335
+ ...(filters.ingredients && {
7336
+ ingredients: filters.ingredients,
7337
+ }),
7338
+ ...(filters.purpose && {
7339
+ purpose: filters.purpose,
7340
+ }),
7341
+ };
7342
+ },
7343
+ bindPersistData: (descriptionData) => ({
7344
+ ...(descriptionData?.description && { description: descriptionData.description }),
7345
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7346
+ ...(descriptionData.whoMustUse && {
7347
+ who_must_use: descriptionData.whoMustUse,
7348
+ }),
7349
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7350
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7351
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7352
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7353
+ }),
7354
+ },
7355
+ },
7356
+ { differentials: { columnName: 'differentials' } },
7357
+ { whoMustUse: { columnName: 'who_must_use' } },
7358
+ { howToUse: { columnName: 'how_to_use' } },
7359
+ { brandDescription: { columnName: 'brand_description' } },
7360
+ { ingredients: { columnName: 'ingredients' } },
7361
+ { purpose: { columnName: 'purpose' } },
7362
+ { hasVariants: { columnName: 'has_variants' } },
7363
+ {
7364
+ images: {
7365
+ columnName: 'images',
7366
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7367
+ },
7368
+ },
7369
+ {
7370
+ miniatures: {
7371
+ columnName: 'miniatures',
7372
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7373
+ },
7374
+ },
7375
+ {
7376
+ imagesCard: {
7377
+ columnName: 'images_card',
7378
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7379
+ },
7380
+ },
7381
+ 'name',
7382
+ {
7383
+ price: {
7384
+ columnName: 'price',
7385
+ from: (price, data) => ({
7386
+ price,
7387
+ fullPrice: data.full_price,
7388
+ subscriberDiscountPercentage: data.subscriber_discount_percentage,
7389
+ fullPriceDiscountPercentage: data.full_price_discount_percentage,
7390
+ subscriberPrice: data.subscriber_price,
7391
+ }),
7392
+ bindFindFilter: (filters) => {
7393
+ return {
7394
+ ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7395
+ ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7396
+ ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7397
+ subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7398
+ }),
7399
+ ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7400
+ subscriber_price: filters.subscriberPrice,
7401
+ }),
7402
+ ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7403
+ full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7404
+ }),
7405
+ };
7406
+ },
7407
+ bindPersistData: (priceData) => ({
7408
+ ...(priceData?.price >= 0 && { price: priceData.price }),
7409
+ ...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
7410
+ ...(priceData.subscriberDiscountPercentage >= 0 && {
7411
+ subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
7412
+ }),
7413
+ ...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
7414
+ ...(priceData.fullPriceDiscountPercentage >= 0 && {
7415
+ full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
7416
+ }),
7417
+ }),
7418
+ },
7419
+ },
7420
+ { fullPrice: { columnName: 'full_price' } },
7421
+ { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
7422
+ { fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
7423
+ { subscriberPrice: { columnName: 'subscriber_price' } },
7424
+ 'published',
7425
+ 'outlet',
7426
+ 'label',
7427
+ 'sku',
7428
+ {
7429
+ stock: {
7430
+ columnName: 'stock',
7431
+ from: (quantity) => ({ quantity }),
7432
+ to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
7433
+ },
7434
+ },
7435
+ { hasStock: { columnName: 'has_stock' } },
7436
+ 'slug',
7437
+ 'type',
7438
+ 'video',
7439
+ 'weight',
7440
+ 'gender',
7441
+ { intGender: { columnName: 'int_gender' } },
7442
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
7443
+ { isKit: { columnName: 'is_kit' } },
7444
+ { createdAt: { columnName: 'created_at' } },
7445
+ { updatedAt: { columnName: 'updated_at' } },
7446
+ { rate: { columnName: 'rating' } },
7447
+ { reviewsTotal: { columnName: 'reviews_total' } },
7448
+ { shoppingCount: { columnName: 'shopping_count' } },
7449
+ { categoryId: { columnName: 'category_id' } },
7450
+ {
7451
+ category: {
7452
+ columnName: 'category',
7453
+ foreignKeyColumn: { id: 'categoryId' },
7454
+ fields: ['id', 'name', 'reference', 'slug'],
7455
+ },
7456
+ },
7457
+ 'group',
7458
+ 'validity',
7459
+ { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7460
+ { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7461
+ { daysOfUse: { columnName: 'days_of_use' } },
7462
+ { showVariants: { columnName: 'show_variants' } },
7463
+ { variantSlug: { columnName: 'variant_slug' } },
7464
+ ];
7465
+ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
7466
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
7467
+ super({
7468
+ tableName: 'product_catalog',
7469
+ model: ProductCatalogHasuraGraphQL,
7470
+ endpoint,
7471
+ authOptions,
7472
+ interceptors,
7473
+ fields: commonFields$1,
7474
+ cache,
7475
+ });
7476
+ }
7477
+ async get({ id }, options) {
7478
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7479
+ const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
7480
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7481
+ if (cachedData) {
7482
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7483
+ return this.model.toInstance(deserialize(cachedData));
7484
+ }
7485
+ }
7486
+ const product = await super
7487
+ .find({
7488
+ filters: {
7489
+ id,
7490
+ },
7491
+ limits: {
7492
+ limit: 1,
7493
+ },
7494
+ })
7495
+ .then((res) => res.data.at(0));
7496
+ if (!product)
7497
+ throw new NotFoundError(`Product not found`);
7498
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7499
+ const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
7500
+ await this.cache.cacheAdapter.set({
7501
+ key: cacheKey,
7502
+ data: serialize(product),
7503
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7504
+ });
7505
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7506
+ }
7507
+ return product;
7508
+ }
7509
+ async getByEAN(EAN, options) {
7510
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7511
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7512
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7513
+ if (cachedData) {
7514
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7515
+ return this.model.toInstance(deserialize(cachedData));
7516
+ }
7517
+ }
7518
+ const product = await super
7519
+ .find({
7520
+ filters: {
7521
+ EAN,
7522
+ },
7523
+ limits: {
7524
+ limit: 1,
7525
+ },
7526
+ })
7527
+ .then((res) => res.data.at(0));
7528
+ if (!product)
7529
+ return null;
7530
+ RoundProductPricesHelper.roundProductPrices(product);
7531
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7532
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7533
+ await this.cache.cacheAdapter.set({
7534
+ key: cacheKey,
7535
+ data: serialize(product),
7536
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7537
+ });
7538
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7539
+ }
7540
+ return product;
7541
+ }
7542
+ async find(params, optionsParams) {
7543
+ const { filters, fields, ...options } = params || {};
7544
+ const bindFields = fields ||
7545
+ this.fields
7546
+ .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
7547
+ .filter((field) => field !== 'reviews' && field !== 'categories');
7548
+ if (options.options?.minimal?.includes('price'))
7549
+ options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7550
+ if (options.options?.maximum?.includes('price'))
7551
+ options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
7552
+ options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
7553
+ options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
7554
+ return super.find({
7555
+ ...options,
7556
+ filters: { ...filters },
7557
+ fields: [
7558
+ ...bindFields,
7559
+ ...(bindFields.includes('price')
7560
+ ? [
7561
+ 'subscriberPrice',
7562
+ 'subscriberDiscountPercentage',
7563
+ 'fullPrice',
7564
+ ]
7565
+ : []),
7566
+ ],
7567
+ }, optionsParams);
7568
+ }
7569
+ async findCatalog(params, mainGender, options) {
7570
+ const result = await this.find({
7571
+ ...params,
7572
+ filters: { ...params.filters, published: true },
7573
+ orderBy: {
7574
+ hasStock: 'desc',
7575
+ ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7576
+ ...omit(params.orderBy, ['hasStock', 'intGender']),
7577
+ },
7578
+ }, options);
7579
+ return result;
7580
+ }
7581
+ }
7582
+ __decorate([
7583
+ Log(),
7584
+ __metadata("design:type", Function),
7585
+ __metadata("design:paramtypes", [Object, Object, Object]),
7586
+ __metadata("design:returntype", Promise)
7587
+ ], ProductCatalogHasuraGraphQLRepository.prototype, "findCatalog", null);
7588
+
7287
7589
  class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7288
7590
  constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
7289
7591
  super({
@@ -7527,6 +7829,8 @@ const commonFields = [
7527
7829
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7528
7830
  { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7529
7831
  { daysOfUse: { columnName: 'days_of_use' } },
7832
+ { showVariants: { columnName: 'show_variants' } },
7833
+ { variantSlug: { columnName: 'variant_slug' } },
7530
7834
  ];
7531
7835
  const fieldsConfiguration$2 = [
7532
7836
  ...commonFields,
@@ -7590,9 +7894,61 @@ const fieldsConfiguration$2 = [
7590
7894
  foreignKeyColumn: { product_id: 'id' },
7591
7895
  fields: [
7592
7896
  'id',
7897
+ 'name',
7593
7898
  'ean',
7594
7899
  'sku',
7595
- 'description',
7900
+ {
7901
+ description: {
7902
+ columnName: 'description',
7903
+ from: (description, data) => ({
7904
+ description,
7905
+ differentials: data.differentials,
7906
+ whoMustUse: data.who_must_use,
7907
+ howToUse: data.how_to_use,
7908
+ brand: data.brand_description,
7909
+ ingredients: data.ingredients,
7910
+ purpose: data.purpose,
7911
+ }),
7912
+ bindFindFilter: (filters) => {
7913
+ return {
7914
+ ...(filters?.description && { description: filters.description }),
7915
+ ...(filters.differentials && { differentials: filters.differentials }),
7916
+ ...(filters.whoMustUse && {
7917
+ who_must_use: filters.whoMustUse,
7918
+ }),
7919
+ ...(filters.howToUse && {
7920
+ how_to_use: filters.howToUse,
7921
+ }),
7922
+ ...(filters.brand && {
7923
+ brand_description: filters.brand,
7924
+ }),
7925
+ ...(filters.ingredients && {
7926
+ ingredients: filters.ingredients,
7927
+ }),
7928
+ ...(filters.purpose && {
7929
+ purpose: filters.purpose,
7930
+ }),
7931
+ };
7932
+ },
7933
+ bindPersistData: (descriptionData) => ({
7934
+ ...(descriptionData?.description && { description: descriptionData.description }),
7935
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
7936
+ ...(descriptionData.whoMustUse && {
7937
+ who_must_use: descriptionData.whoMustUse,
7938
+ }),
7939
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
7940
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
7941
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
7942
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
7943
+ }),
7944
+ },
7945
+ },
7946
+ { differentials: { columnName: 'differentials' } },
7947
+ { whoMustUse: { columnName: 'who_must_use' } },
7948
+ { howToUse: { columnName: 'how_to_use' } },
7949
+ { brandDescription: { columnName: 'brand_description' } },
7950
+ { ingredients: { columnName: 'ingredients' } },
7951
+ { purpose: { columnName: 'purpose' } },
7596
7952
  {
7597
7953
  grade: {
7598
7954
  columnName: 'grade',
@@ -7609,22 +7965,6 @@ const fieldsConfiguration$2 = [
7609
7965
  subscriberPrice: data.subscriber_price,
7610
7966
  fullPriceDiscountPercentage: data.full_price_discount_percentage,
7611
7967
  }),
7612
- bindFindFilter: (sentence) => {
7613
- const filters = Object.values(sentence).shift();
7614
- return {
7615
- ...((filters?.price || filters?.price === 0) && { price: filters.price }),
7616
- ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
7617
- ...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
7618
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
7619
- }),
7620
- ...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
7621
- subscriber_price: filters.subscriberPrice,
7622
- }),
7623
- ...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
7624
- full_price_discount_percentage: filters.fullPriceDiscountPercentage,
7625
- }),
7626
- };
7627
- },
7628
7968
  bindPersistData: (priceData) => ({
7629
7969
  ...((priceData?.price || 0) >= 0 && { price: priceData.price }),
7630
7970
  ...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
@@ -7670,6 +8010,39 @@ const fieldsConfiguration$2 = [
7670
8010
  },
7671
8011
  { tagsProfile: { columnName: 'tags_profile' } },
7672
8012
  { tagsCollection: { columnName: 'tags_collection' } },
8013
+ { variantSlug: { columnName: 'variant_slug' } },
8014
+ {
8015
+ reviews: {
8016
+ columnName: 'reviews',
8017
+ foreignKeyColumn: { product_id: 'id' },
8018
+ fields: [
8019
+ 'id',
8020
+ 'shop',
8021
+ 'rate',
8022
+ 'author',
8023
+ 'email',
8024
+ 'location',
8025
+ 'review',
8026
+ 'status',
8027
+ 'title',
8028
+ { personId: { columnName: 'person_id' } },
8029
+ 'points',
8030
+ { orderId: { columnName: 'order_id' } },
8031
+ { createdAt: { columnName: 'created_at' } },
8032
+ { updatedAt: { columnName: 'updated_at' } },
8033
+ ],
8034
+ },
8035
+ },
8036
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
8037
+ {
8038
+ metadata: {
8039
+ columnName: 'metadata',
8040
+ fields: ['title', 'description'],
8041
+ bindPersistData: (value) => ({
8042
+ metadata: { data: value },
8043
+ }),
8044
+ },
8045
+ },
7673
8046
  ],
7674
8047
  },
7675
8048
  },
@@ -7735,7 +8108,12 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7735
8108
  : await super.get(identifiers, options);
7736
8109
  if (product.productId)
7737
8110
  throw new NotFoundError('Product not found, it is a variant');
7738
- product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
8111
+ product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
8112
+ if (!product.variants?.length) {
8113
+ for (const [index, variant] of product.variants.entries()) {
8114
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8115
+ }
8116
+ }
7739
8117
  return product;
7740
8118
  }
7741
8119
  async find(params, optionsParams) {
@@ -7777,6 +8155,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7777
8155
  const result = await this.find({
7778
8156
  filters: {
7779
8157
  slug,
8158
+ productId: {
8159
+ operator: Where.ISNULL,
8160
+ },
7780
8161
  },
7781
8162
  fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
7782
8163
  options: {
@@ -7786,6 +8167,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7786
8167
  if (!result.data.length)
7787
8168
  return null;
7788
8169
  const product = result?.data?.shift();
8170
+ if (!product.variants?.length) {
8171
+ for (const [index, variant] of product.variants.entries()) {
8172
+ product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
8173
+ }
8174
+ }
7789
8175
  RoundProductPricesHelper.roundProductPrices(product);
7790
8176
  if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7791
8177
  const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
@@ -7965,7 +8351,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7965
8351
  const plainData = this.paramsToPlain({ metadata });
7966
8352
  if (!plainData.metadata)
7967
8353
  return null;
7968
- await this.mutation('update_product_metadata_by_pk', ['product_id'], {
8354
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8355
+ const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
7969
8356
  pk_columns: {
7970
8357
  value: { product_id: productId },
7971
8358
  type: 'product_metadata_pk_columns_input',
@@ -7977,6 +8364,14 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7977
8364
  required: true,
7978
8365
  },
7979
8366
  });
8367
+ if (!update_product_metadata_by_pk) {
8368
+ await this.mutation('insert_product_metadata', ['affected_rows'], {
8369
+ objects: {
8370
+ type: '[product_metadata_insert_input!]!',
8371
+ value: [{ product_id: productId, ...metadata }],
8372
+ },
8373
+ });
8374
+ }
7980
8375
  return plainData.metadata;
7981
8376
  }
7982
8377
  async getId(id) {
@@ -7987,7 +8382,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7987
8382
  return data?.[0]?.id;
7988
8383
  throw new NotFoundError(`Product with id ${id} not found`);
7989
8384
  }
7990
- async findReviewsByProduct(productId, options) {
8385
+ async findReviewsByProduct(productId, onlyApproved, options) {
7991
8386
  if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7992
8387
  const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
7993
8388
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
@@ -8000,10 +8395,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8000
8395
  where: {
8001
8396
  value: {
8002
8397
  product_id: { _eq: productId },
8398
+ ...(onlyApproved && { status: { _eq: true } }),
8003
8399
  },
8004
8400
  type: 'product_review_bool_exp',
8005
8401
  required: true,
8006
8402
  },
8403
+ order_by: {
8404
+ type: '[product_review_order_by]',
8405
+ value: [{ createdAt: 'desc' }],
8406
+ required: true,
8407
+ },
8007
8408
  });
8008
8409
  const reviews = data?.map((review) => this.bindReviewToModel(review));
8009
8410
  if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
@@ -8108,7 +8509,7 @@ __decorate([
8108
8509
  __decorate([
8109
8510
  Log(),
8110
8511
  __metadata("design:type", Function),
8111
- __metadata("design:paramtypes", [Number, Object]),
8512
+ __metadata("design:paramtypes", [Number, Boolean, Object]),
8112
8513
  __metadata("design:returntype", Promise)
8113
8514
  ], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
8114
8515
 
@@ -8140,7 +8541,25 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
8140
8541
  product: {
8141
8542
  columnName: 'product',
8142
8543
  foreignKeyColumn: { id: 'productId' },
8143
- fields: ['id', 'ean', 'sku', 'name', 'brand', 'slug', 'images', 'grade', 'gender'],
8544
+ fields: [
8545
+ 'id',
8546
+ {
8547
+ productId: {
8548
+ columnName: 'main_product_id',
8549
+ to: (value) => +value,
8550
+ from: (value) => value?.toString(),
8551
+ },
8552
+ },
8553
+ 'ean',
8554
+ 'sku',
8555
+ 'name',
8556
+ 'brand',
8557
+ 'slug',
8558
+ 'images',
8559
+ 'grade',
8560
+ 'gender',
8561
+ '',
8562
+ ],
8144
8563
  },
8145
8564
  },
8146
8565
  ],
@@ -8333,6 +8752,7 @@ const fieldsConfiguration$1 = [
8333
8752
  },
8334
8753
  },
8335
8754
  'group',
8755
+ 'type',
8336
8756
  'validity',
8337
8757
  'published',
8338
8758
  { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
@@ -8356,6 +8776,124 @@ const fieldsConfiguration$1 = [
8356
8776
  to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8357
8777
  },
8358
8778
  },
8779
+ 'slug',
8780
+ 'brand',
8781
+ 'name',
8782
+ 'sku',
8783
+ { NCM: { columnName: 'ncm' } },
8784
+ { CEST: { columnName: 'cest' } },
8785
+ {
8786
+ description: {
8787
+ columnName: 'description',
8788
+ from: (description, data) => ({
8789
+ description,
8790
+ differentials: data.differentials,
8791
+ whoMustUse: data.who_must_use,
8792
+ howToUse: data.how_to_use,
8793
+ brand: data.brand_description,
8794
+ ingredients: data.ingredients,
8795
+ purpose: data.purpose,
8796
+ }),
8797
+ bindFindFilter: (filters) => {
8798
+ return {
8799
+ ...(filters?.description && { description: filters.description }),
8800
+ ...(filters.differentials && { differentials: filters.differentials }),
8801
+ ...(filters.whoMustUse && {
8802
+ who_must_use: filters.whoMustUse,
8803
+ }),
8804
+ ...(filters.howToUse && {
8805
+ how_to_use: filters.howToUse,
8806
+ }),
8807
+ ...(filters.brand && {
8808
+ brand_description: filters.brand,
8809
+ }),
8810
+ ...(filters.ingredients && {
8811
+ ingredients: filters.ingredients,
8812
+ }),
8813
+ ...(filters.purpose && {
8814
+ purpose: filters.purpose,
8815
+ }),
8816
+ };
8817
+ },
8818
+ bindPersistData: (descriptionData) => ({
8819
+ ...(descriptionData?.description && { description: descriptionData.description }),
8820
+ ...(descriptionData.differentials && { differentials: descriptionData.differentials }),
8821
+ ...(descriptionData.whoMustUse && {
8822
+ who_must_use: descriptionData.whoMustUse,
8823
+ }),
8824
+ ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
8825
+ ...(descriptionData.brand && { brand_description: descriptionData.brand }),
8826
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
8827
+ ...(descriptionData.purpose && { purpose: descriptionData.purpose }),
8828
+ }),
8829
+ },
8830
+ },
8831
+ { differentials: { columnName: 'differentials' } },
8832
+ { whoMustUse: { columnName: 'who_must_use' } },
8833
+ { howToUse: { columnName: 'how_to_use' } },
8834
+ { brandDescription: { columnName: 'brand_description' } },
8835
+ { ingredients: { columnName: 'ingredients' } },
8836
+ { purpose: { columnName: 'purpose' } },
8837
+ 'gender',
8838
+ { intGender: { columnName: 'int_gender' } },
8839
+ 'label',
8840
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
8841
+ { rate: { columnName: 'rating' } },
8842
+ { reviewsTotal: { columnName: 'reviews_total' } },
8843
+ { shoppingCount: { columnName: 'shopping_count' } },
8844
+ { categoryId: { columnName: 'category_id' } },
8845
+ {
8846
+ category: {
8847
+ columnName: 'category',
8848
+ foreignKeyColumn: { id: 'categoryId' },
8849
+ fields: ['id', 'name', 'reference', 'slug'],
8850
+ },
8851
+ },
8852
+ {
8853
+ categories: {
8854
+ columnName: 'categories',
8855
+ fields: ['category_id'],
8856
+ bindPersistData: (value) => ({
8857
+ categories: { data: value.map((category) => ({ category_id: +category })) },
8858
+ }),
8859
+ to: (categories) => categories.map((categoryId) => +categoryId),
8860
+ from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
8861
+ },
8862
+ },
8863
+ {
8864
+ metadata: {
8865
+ columnName: 'metadata',
8866
+ fields: ['title', 'description'],
8867
+ bindPersistData: (value) => ({
8868
+ metadata: { data: value },
8869
+ }),
8870
+ },
8871
+ },
8872
+ {
8873
+ reviews: {
8874
+ columnName: 'reviews',
8875
+ foreignKeyColumn: { product_id: 'id' },
8876
+ fields: [
8877
+ 'id',
8878
+ 'shop',
8879
+ 'rate',
8880
+ 'author',
8881
+ 'email',
8882
+ 'location',
8883
+ 'review',
8884
+ 'status',
8885
+ 'title',
8886
+ { personId: { columnName: 'person_id' } },
8887
+ 'points',
8888
+ { orderId: { columnName: 'order_id' } },
8889
+ { createdAt: { columnName: 'created_at' } },
8890
+ { updatedAt: { columnName: 'updated_at' } },
8891
+ ],
8892
+ },
8893
+ },
8894
+ { variantSlug: { columnName: 'variant_slug' } },
8895
+ { createdAt: { columnName: 'created_at' } },
8896
+ { updatedAt: { columnName: 'updated_at' } },
8359
8897
  ];
8360
8898
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
8361
8899
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -8396,18 +8934,46 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8396
8934
  return data.at(0);
8397
8935
  }
8398
8936
  async update(params) {
8399
- const { productId, id: checkId, ...data } = params;
8937
+ const { productId, id: checkId, metadata, ...data } = params;
8400
8938
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
8401
8939
  if (!dataWithProductId.id) {
8402
8940
  throw new NotFoundError('Variant ID is required for update');
8403
8941
  }
8404
8942
  const id = await this.getId(dataWithProductId.id);
8405
8943
  const product = await super.update({ id, ...data });
8944
+ product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
8406
8945
  if (dataWithProductId.productId) {
8407
8946
  product.productId = dataWithProductId.productId;
8408
8947
  }
8409
8948
  return product;
8410
8949
  }
8950
+ async updateMetadata(productId, { metadata }) {
8951
+ const plainData = this.paramsToPlain({ metadata });
8952
+ if (!plainData.metadata)
8953
+ return null;
8954
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8955
+ const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
8956
+ pk_columns: {
8957
+ value: { product_id: productId },
8958
+ type: 'product_metadata_pk_columns_input',
8959
+ required: true,
8960
+ },
8961
+ _set: {
8962
+ value: omit(metadata, ['product_id']),
8963
+ type: 'product_metadata_set_input',
8964
+ required: true,
8965
+ },
8966
+ });
8967
+ if (!update_product_metadata_by_pk) {
8968
+ await this.mutation('insert_product_metadata', ['affected_rows'], {
8969
+ objects: {
8970
+ type: '[product_metadata_insert_input!]!',
8971
+ value: [{ product_id: productId, ...metadata }],
8972
+ },
8973
+ });
8974
+ }
8975
+ return plainData.metadata;
8976
+ }
8411
8977
  async getId(id) {
8412
8978
  if (!Number.isNaN(+id))
8413
8979
  return id;
@@ -10177,4 +10743,4 @@ class ProductsVertexSearch {
10177
10743
  }
10178
10744
  }
10179
10745
 
10180
- 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, BrandCategory, BrandCategoryFirestoreRepository, 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, MercadoPagoBankSlipAxiosAdapter, MercadoPagoCardAxiosAdapter, MercadoPagoPaymentMethodFactory, MercadoPagoPixAxiosAdapter, MercadoPagoRequestHelper, MercadoPagoResponseHelper, MercadoPagoStatusDetailEnum, MercadoPagoStatusEnum, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderPaymentStatus, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, 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 };
10746
+ 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, BrandCategory, BrandCategoryFirestoreRepository, 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, MercadoPagoBankSlipAxiosAdapter, MercadoPagoCardAxiosAdapter, MercadoPagoPaymentMethodFactory, MercadoPagoPixAxiosAdapter, MercadoPagoRequestHelper, MercadoPagoResponseHelper, MercadoPagoStatusDetailEnum, MercadoPagoStatusEnum, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderPaymentStatus, 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 };