@infrab4a/connect 5.4.0-beta.7 → 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
|
@@ -7411,7 +7411,15 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
|
|
|
7411
7411
|
.then((res) => res.data.at(0));
|
|
7412
7412
|
}
|
|
7413
7413
|
async getByEAN(EAN, options) {
|
|
7414
|
-
|
|
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
|
|
7415
7423
|
.find({
|
|
7416
7424
|
filters: {
|
|
7417
7425
|
EAN,
|
|
@@ -7421,6 +7429,19 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
|
|
|
7421
7429
|
},
|
|
7422
7430
|
})
|
|
7423
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;
|
|
7424
7445
|
}
|
|
7425
7446
|
async find(params, optionsParams) {
|
|
7426
7447
|
const { filters, fields, ...options } = params || {};
|
|
@@ -7906,6 +7927,28 @@ const fieldsConfiguration$2 = [
|
|
|
7906
7927
|
{ tagsProfile: { columnName: 'tags_profile' } },
|
|
7907
7928
|
{ tagsCollection: { columnName: 'tags_collection' } },
|
|
7908
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
|
+
},
|
|
7909
7952
|
],
|
|
7910
7953
|
},
|
|
7911
7954
|
},
|
|
@@ -7971,9 +8014,12 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7971
8014
|
: await super.get(identifiers, options);
|
|
7972
8015
|
if (product.productId)
|
|
7973
8016
|
throw new NotFoundError('Product not found, it is a variant');
|
|
7974
|
-
product.reviews =
|
|
7975
|
-
|
|
7976
|
-
|
|
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
|
+
}
|
|
7977
8023
|
return product;
|
|
7978
8024
|
}
|
|
7979
8025
|
async find(params, optionsParams) {
|
|
@@ -7991,8 +8037,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7991
8037
|
return super.find({
|
|
7992
8038
|
...options,
|
|
7993
8039
|
filters: { ...filters },
|
|
7994
|
-
// filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
|
|
7995
|
-
// filters: { ...filters, productId: { operator: Where.ISNULL } },
|
|
7996
8040
|
fields: [
|
|
7997
8041
|
...bindFields,
|
|
7998
8042
|
...(bindFields.includes('price')
|
|
@@ -8029,8 +8073,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8029
8073
|
if (!result.data.length)
|
|
8030
8074
|
return null;
|
|
8031
8075
|
const product = result?.data?.shift();
|
|
8032
|
-
if (!product.
|
|
8033
|
-
|
|
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
|
+
}
|
|
8034
8080
|
}
|
|
8035
8081
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
8036
8082
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
@@ -8251,6 +8297,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8251
8297
|
type: 'product_review_bool_exp',
|
|
8252
8298
|
required: true,
|
|
8253
8299
|
},
|
|
8300
|
+
order_by: {
|
|
8301
|
+
type: '[product_review_order_by]',
|
|
8302
|
+
value: [{ createdAt: 'desc' }],
|
|
8303
|
+
required: true,
|
|
8304
|
+
},
|
|
8254
8305
|
});
|
|
8255
8306
|
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
8256
8307
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
@@ -8678,6 +8729,28 @@ const fieldsConfiguration$1 = [
|
|
|
8678
8729
|
}),
|
|
8679
8730
|
},
|
|
8680
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
|
+
},
|
|
8681
8754
|
{ variantSlug: { columnName: 'variant_slug' } },
|
|
8682
8755
|
{ createdAt: { columnName: 'created_at' } },
|
|
8683
8756
|
{ updatedAt: { columnName: 'updated_at' } },
|
package/index.esm.js
CHANGED
|
@@ -7387,7 +7387,15 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
|
|
|
7387
7387
|
.then((res) => res.data.at(0));
|
|
7388
7388
|
}
|
|
7389
7389
|
async getByEAN(EAN, options) {
|
|
7390
|
-
|
|
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
|
|
7391
7399
|
.find({
|
|
7392
7400
|
filters: {
|
|
7393
7401
|
EAN,
|
|
@@ -7397,6 +7405,19 @@ class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHa
|
|
|
7397
7405
|
},
|
|
7398
7406
|
})
|
|
7399
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;
|
|
7400
7421
|
}
|
|
7401
7422
|
async find(params, optionsParams) {
|
|
7402
7423
|
const { filters, fields, ...options } = params || {};
|
|
@@ -7882,6 +7903,28 @@ const fieldsConfiguration$2 = [
|
|
|
7882
7903
|
{ tagsProfile: { columnName: 'tags_profile' } },
|
|
7883
7904
|
{ tagsCollection: { columnName: 'tags_collection' } },
|
|
7884
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
|
+
},
|
|
7885
7928
|
],
|
|
7886
7929
|
},
|
|
7887
7930
|
},
|
|
@@ -7947,9 +7990,12 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7947
7990
|
: await super.get(identifiers, options);
|
|
7948
7991
|
if (product.productId)
|
|
7949
7992
|
throw new NotFoundError('Product not found, it is a variant');
|
|
7950
|
-
product.reviews =
|
|
7951
|
-
|
|
7952
|
-
|
|
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
|
+
}
|
|
7953
7999
|
return product;
|
|
7954
8000
|
}
|
|
7955
8001
|
async find(params, optionsParams) {
|
|
@@ -7967,8 +8013,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7967
8013
|
return super.find({
|
|
7968
8014
|
...options,
|
|
7969
8015
|
filters: { ...filters },
|
|
7970
|
-
// filters: { ...filters, hasVariants: { operator: Where.EQUALS, value: false } },
|
|
7971
|
-
// filters: { ...filters, productId: { operator: Where.ISNULL } },
|
|
7972
8016
|
fields: [
|
|
7973
8017
|
...bindFields,
|
|
7974
8018
|
...(bindFields.includes('price')
|
|
@@ -8005,8 +8049,10 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8005
8049
|
if (!result.data.length)
|
|
8006
8050
|
return null;
|
|
8007
8051
|
const product = result?.data?.shift();
|
|
8008
|
-
if (!product.
|
|
8009
|
-
|
|
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
|
+
}
|
|
8010
8056
|
}
|
|
8011
8057
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
8012
8058
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
@@ -8227,6 +8273,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8227
8273
|
type: 'product_review_bool_exp',
|
|
8228
8274
|
required: true,
|
|
8229
8275
|
},
|
|
8276
|
+
order_by: {
|
|
8277
|
+
type: '[product_review_order_by]',
|
|
8278
|
+
value: [{ createdAt: 'desc' }],
|
|
8279
|
+
required: true,
|
|
8280
|
+
},
|
|
8230
8281
|
});
|
|
8231
8282
|
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
8232
8283
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
@@ -8654,6 +8705,28 @@ const fieldsConfiguration$1 = [
|
|
|
8654
8705
|
}),
|
|
8655
8706
|
},
|
|
8656
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
|
+
},
|
|
8657
8730
|
{ variantSlug: { columnName: 'variant_slug' } },
|
|
8658
8731
|
{ createdAt: { columnName: 'created_at' } },
|
|
8659
8732
|
{ updatedAt: { columnName: 'updated_at' } },
|
package/package.json
CHANGED
|
@@ -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>;
|