@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.cjs.js +592 -24
- package/index.esm.js +591 -25
- package/package.json +1 -1
- package/src/domain/catalog/models/product-base.d.ts +1 -0
- package/src/domain/catalog/models/product-review.d.ts +2 -0
- package/src/domain/catalog/models/product.d.ts +1 -0
- package/src/domain/catalog/repositories/index.d.ts +1 -0
- package/src/domain/catalog/repositories/product-catalog.repository.d.ts +17 -0
- package/src/domain/shopping/models/order.d.ts +1 -1
- package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
- package/src/infra/hasura-graphql/models/index.d.ts +1 -0
- package/src/infra/hasura-graphql/models/product-catalog-hasura-graphql.d.ts +16 -0
- package/src/infra/hasura-graphql/models/variant-hasura-graphql.d.ts +7 -0
- package/src/infra/hasura-graphql/repositories/catalog/index.d.ts +1 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-catalog-hasura-graphql.repository.d.ts +22 -0
- package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +1 -0
package/index.cjs.js
CHANGED
|
@@ -869,7 +869,12 @@ class ProductReview extends BaseModel {
|
|
|
869
869
|
static get identifiersFields() {
|
|
870
870
|
return ['id'];
|
|
871
871
|
}
|
|
872
|
-
}
|
|
872
|
+
}
|
|
873
|
+
tslib.__decorate([
|
|
874
|
+
classTransformer.Type(resolveClass('Product')),
|
|
875
|
+
tslib.__metadata("design:type", Function)
|
|
876
|
+
], ProductReview.prototype, "product", void 0);
|
|
877
|
+
registerClass('ProductReview', ProductReview);
|
|
873
878
|
|
|
874
879
|
class ProductBase extends BaseModel {
|
|
875
880
|
get evaluation() {
|
|
@@ -5943,6 +5948,9 @@ tslib.__decorate([
|
|
|
5943
5948
|
tslib.__metadata("design:type", Product)
|
|
5944
5949
|
], KitProductHasuraGraphQL.prototype, "product", void 0);
|
|
5945
5950
|
|
|
5951
|
+
class ProductCatalogHasuraGraphQL extends Product {
|
|
5952
|
+
}
|
|
5953
|
+
|
|
5946
5954
|
class ProductHasuraGraphQL extends Product {
|
|
5947
5955
|
}
|
|
5948
5956
|
tslib.__decorate([
|
|
@@ -7308,6 +7316,300 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
|
|
|
7308
7316
|
}
|
|
7309
7317
|
}
|
|
7310
7318
|
|
|
7319
|
+
const commonFields$1 = [
|
|
7320
|
+
{
|
|
7321
|
+
id: {
|
|
7322
|
+
columnName: 'id',
|
|
7323
|
+
to: (value) => +value,
|
|
7324
|
+
from: (value) => value.toString(),
|
|
7325
|
+
},
|
|
7326
|
+
},
|
|
7327
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
7328
|
+
{ productId: { columnName: 'main_product_id' } },
|
|
7329
|
+
{ CEST: { columnName: 'cest' } },
|
|
7330
|
+
{ EAN: { columnName: 'ean' } },
|
|
7331
|
+
{ NCM: { columnName: 'ncm' } },
|
|
7332
|
+
'brand',
|
|
7333
|
+
{ costPrice: { columnName: 'cost_price' } },
|
|
7334
|
+
{
|
|
7335
|
+
description: {
|
|
7336
|
+
columnName: 'description',
|
|
7337
|
+
from: (description, data) => ({
|
|
7338
|
+
description,
|
|
7339
|
+
differentials: data.differentials,
|
|
7340
|
+
whoMustUse: data.who_must_use,
|
|
7341
|
+
howToUse: data.how_to_use,
|
|
7342
|
+
brand: data.brand_description,
|
|
7343
|
+
ingredients: data.ingredients,
|
|
7344
|
+
purpose: data.purpose,
|
|
7345
|
+
}),
|
|
7346
|
+
bindFindFilter: (filters) => {
|
|
7347
|
+
return {
|
|
7348
|
+
...(filters?.description && { description: filters.description }),
|
|
7349
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
7350
|
+
...(filters.whoMustUse && {
|
|
7351
|
+
who_must_use: filters.whoMustUse,
|
|
7352
|
+
}),
|
|
7353
|
+
...(filters.howToUse && {
|
|
7354
|
+
how_to_use: filters.howToUse,
|
|
7355
|
+
}),
|
|
7356
|
+
...(filters.brand && {
|
|
7357
|
+
brand_description: filters.brand,
|
|
7358
|
+
}),
|
|
7359
|
+
...(filters.ingredients && {
|
|
7360
|
+
ingredients: filters.ingredients,
|
|
7361
|
+
}),
|
|
7362
|
+
...(filters.purpose && {
|
|
7363
|
+
purpose: filters.purpose,
|
|
7364
|
+
}),
|
|
7365
|
+
};
|
|
7366
|
+
},
|
|
7367
|
+
bindPersistData: (descriptionData) => ({
|
|
7368
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
7369
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
7370
|
+
...(descriptionData.whoMustUse && {
|
|
7371
|
+
who_must_use: descriptionData.whoMustUse,
|
|
7372
|
+
}),
|
|
7373
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
7374
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
7375
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
7376
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
7377
|
+
}),
|
|
7378
|
+
},
|
|
7379
|
+
},
|
|
7380
|
+
{ differentials: { columnName: 'differentials' } },
|
|
7381
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
7382
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
7383
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
7384
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
7385
|
+
{ purpose: { columnName: 'purpose' } },
|
|
7386
|
+
{ hasVariants: { columnName: 'has_variants' } },
|
|
7387
|
+
{
|
|
7388
|
+
images: {
|
|
7389
|
+
columnName: 'images',
|
|
7390
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7391
|
+
},
|
|
7392
|
+
},
|
|
7393
|
+
{
|
|
7394
|
+
miniatures: {
|
|
7395
|
+
columnName: 'miniatures',
|
|
7396
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7397
|
+
},
|
|
7398
|
+
},
|
|
7399
|
+
{
|
|
7400
|
+
imagesCard: {
|
|
7401
|
+
columnName: 'images_card',
|
|
7402
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7403
|
+
},
|
|
7404
|
+
},
|
|
7405
|
+
'name',
|
|
7406
|
+
{
|
|
7407
|
+
price: {
|
|
7408
|
+
columnName: 'price',
|
|
7409
|
+
from: (price, data) => ({
|
|
7410
|
+
price,
|
|
7411
|
+
fullPrice: data.full_price,
|
|
7412
|
+
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
7413
|
+
fullPriceDiscountPercentage: data.full_price_discount_percentage,
|
|
7414
|
+
subscriberPrice: data.subscriber_price,
|
|
7415
|
+
}),
|
|
7416
|
+
bindFindFilter: (filters) => {
|
|
7417
|
+
return {
|
|
7418
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7419
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7420
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7421
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7422
|
+
}),
|
|
7423
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7424
|
+
subscriber_price: filters.subscriberPrice,
|
|
7425
|
+
}),
|
|
7426
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7427
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7428
|
+
}),
|
|
7429
|
+
};
|
|
7430
|
+
},
|
|
7431
|
+
bindPersistData: (priceData) => ({
|
|
7432
|
+
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
7433
|
+
...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
|
|
7434
|
+
...(priceData.subscriberDiscountPercentage >= 0 && {
|
|
7435
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
7436
|
+
}),
|
|
7437
|
+
...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
7438
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
7439
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
7440
|
+
}),
|
|
7441
|
+
}),
|
|
7442
|
+
},
|
|
7443
|
+
},
|
|
7444
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
7445
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
7446
|
+
{ fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
|
|
7447
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
7448
|
+
'published',
|
|
7449
|
+
'outlet',
|
|
7450
|
+
'label',
|
|
7451
|
+
'sku',
|
|
7452
|
+
{
|
|
7453
|
+
stock: {
|
|
7454
|
+
columnName: 'stock',
|
|
7455
|
+
from: (quantity) => ({ quantity }),
|
|
7456
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
7457
|
+
},
|
|
7458
|
+
},
|
|
7459
|
+
{ hasStock: { columnName: 'has_stock' } },
|
|
7460
|
+
'slug',
|
|
7461
|
+
'type',
|
|
7462
|
+
'video',
|
|
7463
|
+
'weight',
|
|
7464
|
+
'gender',
|
|
7465
|
+
{ intGender: { columnName: 'int_gender' } },
|
|
7466
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7467
|
+
{ isKit: { columnName: 'is_kit' } },
|
|
7468
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
7469
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
7470
|
+
{ rate: { columnName: 'rating' } },
|
|
7471
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
7472
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
7473
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
7474
|
+
{
|
|
7475
|
+
category: {
|
|
7476
|
+
columnName: 'category',
|
|
7477
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
7478
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
7479
|
+
},
|
|
7480
|
+
},
|
|
7481
|
+
'group',
|
|
7482
|
+
'validity',
|
|
7483
|
+
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7484
|
+
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7485
|
+
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
7486
|
+
{ showVariants: { columnName: 'show_variants' } },
|
|
7487
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
7488
|
+
];
|
|
7489
|
+
class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7490
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
7491
|
+
super({
|
|
7492
|
+
tableName: 'product_catalog',
|
|
7493
|
+
model: ProductCatalogHasuraGraphQL,
|
|
7494
|
+
endpoint,
|
|
7495
|
+
authOptions,
|
|
7496
|
+
interceptors,
|
|
7497
|
+
fields: commonFields$1,
|
|
7498
|
+
cache,
|
|
7499
|
+
});
|
|
7500
|
+
}
|
|
7501
|
+
async get({ id }, options) {
|
|
7502
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7503
|
+
const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
|
|
7504
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7505
|
+
if (cachedData) {
|
|
7506
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
7507
|
+
return this.model.toInstance(deserialize(cachedData));
|
|
7508
|
+
}
|
|
7509
|
+
}
|
|
7510
|
+
const product = await super
|
|
7511
|
+
.find({
|
|
7512
|
+
filters: {
|
|
7513
|
+
id,
|
|
7514
|
+
},
|
|
7515
|
+
limits: {
|
|
7516
|
+
limit: 1,
|
|
7517
|
+
},
|
|
7518
|
+
})
|
|
7519
|
+
.then((res) => res.data.at(0));
|
|
7520
|
+
if (!product)
|
|
7521
|
+
throw new NotFoundError(`Product not found`);
|
|
7522
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7523
|
+
const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
|
|
7524
|
+
await this.cache.cacheAdapter.set({
|
|
7525
|
+
key: cacheKey,
|
|
7526
|
+
data: serialize(product),
|
|
7527
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7528
|
+
});
|
|
7529
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7530
|
+
}
|
|
7531
|
+
return product;
|
|
7532
|
+
}
|
|
7533
|
+
async getByEAN(EAN, options) {
|
|
7534
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7535
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7536
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7537
|
+
if (cachedData) {
|
|
7538
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
7539
|
+
return this.model.toInstance(deserialize(cachedData));
|
|
7540
|
+
}
|
|
7541
|
+
}
|
|
7542
|
+
const product = await super
|
|
7543
|
+
.find({
|
|
7544
|
+
filters: {
|
|
7545
|
+
EAN,
|
|
7546
|
+
},
|
|
7547
|
+
limits: {
|
|
7548
|
+
limit: 1,
|
|
7549
|
+
},
|
|
7550
|
+
})
|
|
7551
|
+
.then((res) => res.data.at(0));
|
|
7552
|
+
if (!product)
|
|
7553
|
+
return null;
|
|
7554
|
+
RoundProductPricesHelper.roundProductPrices(product);
|
|
7555
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7556
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7557
|
+
await this.cache.cacheAdapter.set({
|
|
7558
|
+
key: cacheKey,
|
|
7559
|
+
data: serialize(product),
|
|
7560
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7561
|
+
});
|
|
7562
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7563
|
+
}
|
|
7564
|
+
return product;
|
|
7565
|
+
}
|
|
7566
|
+
async find(params, optionsParams) {
|
|
7567
|
+
const { filters, fields, ...options } = params || {};
|
|
7568
|
+
const bindFields = fields ||
|
|
7569
|
+
this.fields
|
|
7570
|
+
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
7571
|
+
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
7572
|
+
if (options.options?.minimal?.includes('price'))
|
|
7573
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7574
|
+
if (options.options?.maximum?.includes('price'))
|
|
7575
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7576
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
7577
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
7578
|
+
return super.find({
|
|
7579
|
+
...options,
|
|
7580
|
+
filters: { ...filters },
|
|
7581
|
+
fields: [
|
|
7582
|
+
...bindFields,
|
|
7583
|
+
...(bindFields.includes('price')
|
|
7584
|
+
? [
|
|
7585
|
+
'subscriberPrice',
|
|
7586
|
+
'subscriberDiscountPercentage',
|
|
7587
|
+
'fullPrice',
|
|
7588
|
+
]
|
|
7589
|
+
: []),
|
|
7590
|
+
],
|
|
7591
|
+
}, optionsParams);
|
|
7592
|
+
}
|
|
7593
|
+
async findCatalog(params, mainGender, options) {
|
|
7594
|
+
const result = await this.find({
|
|
7595
|
+
...params,
|
|
7596
|
+
filters: { ...params.filters, published: true },
|
|
7597
|
+
orderBy: {
|
|
7598
|
+
hasStock: 'desc',
|
|
7599
|
+
...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
|
|
7600
|
+
...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
|
|
7601
|
+
},
|
|
7602
|
+
}, options);
|
|
7603
|
+
return result;
|
|
7604
|
+
}
|
|
7605
|
+
}
|
|
7606
|
+
tslib.__decorate([
|
|
7607
|
+
Log(),
|
|
7608
|
+
tslib.__metadata("design:type", Function),
|
|
7609
|
+
tslib.__metadata("design:paramtypes", [Object, Object, Object]),
|
|
7610
|
+
tslib.__metadata("design:returntype", Promise)
|
|
7611
|
+
], ProductCatalogHasuraGraphQLRepository.prototype, "findCatalog", null);
|
|
7612
|
+
|
|
7311
7613
|
class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7312
7614
|
constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
|
|
7313
7615
|
super({
|
|
@@ -7551,6 +7853,8 @@ const commonFields = [
|
|
|
7551
7853
|
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7552
7854
|
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7553
7855
|
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
7856
|
+
{ showVariants: { columnName: 'show_variants' } },
|
|
7857
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
7554
7858
|
];
|
|
7555
7859
|
const fieldsConfiguration$2 = [
|
|
7556
7860
|
...commonFields,
|
|
@@ -7614,9 +7918,61 @@ const fieldsConfiguration$2 = [
|
|
|
7614
7918
|
foreignKeyColumn: { product_id: 'id' },
|
|
7615
7919
|
fields: [
|
|
7616
7920
|
'id',
|
|
7921
|
+
'name',
|
|
7617
7922
|
'ean',
|
|
7618
7923
|
'sku',
|
|
7619
|
-
|
|
7924
|
+
{
|
|
7925
|
+
description: {
|
|
7926
|
+
columnName: 'description',
|
|
7927
|
+
from: (description, data) => ({
|
|
7928
|
+
description,
|
|
7929
|
+
differentials: data.differentials,
|
|
7930
|
+
whoMustUse: data.who_must_use,
|
|
7931
|
+
howToUse: data.how_to_use,
|
|
7932
|
+
brand: data.brand_description,
|
|
7933
|
+
ingredients: data.ingredients,
|
|
7934
|
+
purpose: data.purpose,
|
|
7935
|
+
}),
|
|
7936
|
+
bindFindFilter: (filters) => {
|
|
7937
|
+
return {
|
|
7938
|
+
...(filters?.description && { description: filters.description }),
|
|
7939
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
7940
|
+
...(filters.whoMustUse && {
|
|
7941
|
+
who_must_use: filters.whoMustUse,
|
|
7942
|
+
}),
|
|
7943
|
+
...(filters.howToUse && {
|
|
7944
|
+
how_to_use: filters.howToUse,
|
|
7945
|
+
}),
|
|
7946
|
+
...(filters.brand && {
|
|
7947
|
+
brand_description: filters.brand,
|
|
7948
|
+
}),
|
|
7949
|
+
...(filters.ingredients && {
|
|
7950
|
+
ingredients: filters.ingredients,
|
|
7951
|
+
}),
|
|
7952
|
+
...(filters.purpose && {
|
|
7953
|
+
purpose: filters.purpose,
|
|
7954
|
+
}),
|
|
7955
|
+
};
|
|
7956
|
+
},
|
|
7957
|
+
bindPersistData: (descriptionData) => ({
|
|
7958
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
7959
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
7960
|
+
...(descriptionData.whoMustUse && {
|
|
7961
|
+
who_must_use: descriptionData.whoMustUse,
|
|
7962
|
+
}),
|
|
7963
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
7964
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
7965
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
7966
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
7967
|
+
}),
|
|
7968
|
+
},
|
|
7969
|
+
},
|
|
7970
|
+
{ differentials: { columnName: 'differentials' } },
|
|
7971
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
7972
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
7973
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
7974
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
7975
|
+
{ purpose: { columnName: 'purpose' } },
|
|
7620
7976
|
{
|
|
7621
7977
|
grade: {
|
|
7622
7978
|
columnName: 'grade',
|
|
@@ -7633,22 +7989,6 @@ const fieldsConfiguration$2 = [
|
|
|
7633
7989
|
subscriberPrice: data.subscriber_price,
|
|
7634
7990
|
fullPriceDiscountPercentage: data.full_price_discount_percentage,
|
|
7635
7991
|
}),
|
|
7636
|
-
bindFindFilter: (sentence) => {
|
|
7637
|
-
const filters = Object.values(sentence).shift();
|
|
7638
|
-
return {
|
|
7639
|
-
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7640
|
-
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7641
|
-
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7642
|
-
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7643
|
-
}),
|
|
7644
|
-
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7645
|
-
subscriber_price: filters.subscriberPrice,
|
|
7646
|
-
}),
|
|
7647
|
-
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7648
|
-
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7649
|
-
}),
|
|
7650
|
-
};
|
|
7651
|
-
},
|
|
7652
7992
|
bindPersistData: (priceData) => ({
|
|
7653
7993
|
...((priceData?.price || 0) >= 0 && { price: priceData.price }),
|
|
7654
7994
|
...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
|
|
@@ -7694,6 +8034,39 @@ const fieldsConfiguration$2 = [
|
|
|
7694
8034
|
},
|
|
7695
8035
|
{ tagsProfile: { columnName: 'tags_profile' } },
|
|
7696
8036
|
{ tagsCollection: { columnName: 'tags_collection' } },
|
|
8037
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
8038
|
+
{
|
|
8039
|
+
reviews: {
|
|
8040
|
+
columnName: 'reviews',
|
|
8041
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
8042
|
+
fields: [
|
|
8043
|
+
'id',
|
|
8044
|
+
'shop',
|
|
8045
|
+
'rate',
|
|
8046
|
+
'author',
|
|
8047
|
+
'email',
|
|
8048
|
+
'location',
|
|
8049
|
+
'review',
|
|
8050
|
+
'status',
|
|
8051
|
+
'title',
|
|
8052
|
+
{ personId: { columnName: 'person_id' } },
|
|
8053
|
+
'points',
|
|
8054
|
+
{ orderId: { columnName: 'order_id' } },
|
|
8055
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8056
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8057
|
+
],
|
|
8058
|
+
},
|
|
8059
|
+
},
|
|
8060
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8061
|
+
{
|
|
8062
|
+
metadata: {
|
|
8063
|
+
columnName: 'metadata',
|
|
8064
|
+
fields: ['title', 'description'],
|
|
8065
|
+
bindPersistData: (value) => ({
|
|
8066
|
+
metadata: { data: value },
|
|
8067
|
+
}),
|
|
8068
|
+
},
|
|
8069
|
+
},
|
|
7697
8070
|
],
|
|
7698
8071
|
},
|
|
7699
8072
|
},
|
|
@@ -7759,7 +8132,12 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7759
8132
|
: await super.get(identifiers, options);
|
|
7760
8133
|
if (product.productId)
|
|
7761
8134
|
throw new NotFoundError('Product not found, it is a variant');
|
|
7762
|
-
product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
|
|
8135
|
+
product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
|
|
8136
|
+
if (!product.variants?.length) {
|
|
8137
|
+
for (const [index, variant] of product.variants.entries()) {
|
|
8138
|
+
product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
|
|
8139
|
+
}
|
|
8140
|
+
}
|
|
7763
8141
|
return product;
|
|
7764
8142
|
}
|
|
7765
8143
|
async find(params, optionsParams) {
|
|
@@ -7801,6 +8179,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7801
8179
|
const result = await this.find({
|
|
7802
8180
|
filters: {
|
|
7803
8181
|
slug,
|
|
8182
|
+
productId: {
|
|
8183
|
+
operator: exports.Where.ISNULL,
|
|
8184
|
+
},
|
|
7804
8185
|
},
|
|
7805
8186
|
fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
|
|
7806
8187
|
options: {
|
|
@@ -7810,6 +8191,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7810
8191
|
if (!result.data.length)
|
|
7811
8192
|
return null;
|
|
7812
8193
|
const product = result?.data?.shift();
|
|
8194
|
+
if (!product.variants?.length) {
|
|
8195
|
+
for (const [index, variant] of product.variants.entries()) {
|
|
8196
|
+
product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
|
|
8197
|
+
}
|
|
8198
|
+
}
|
|
7813
8199
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
7814
8200
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7815
8201
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
@@ -7989,7 +8375,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7989
8375
|
const plainData = this.paramsToPlain({ metadata });
|
|
7990
8376
|
if (!plainData.metadata)
|
|
7991
8377
|
return null;
|
|
7992
|
-
|
|
8378
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8379
|
+
const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
|
|
7993
8380
|
pk_columns: {
|
|
7994
8381
|
value: { product_id: productId },
|
|
7995
8382
|
type: 'product_metadata_pk_columns_input',
|
|
@@ -8001,6 +8388,14 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8001
8388
|
required: true,
|
|
8002
8389
|
},
|
|
8003
8390
|
});
|
|
8391
|
+
if (!update_product_metadata_by_pk) {
|
|
8392
|
+
await this.mutation('insert_product_metadata', ['affected_rows'], {
|
|
8393
|
+
objects: {
|
|
8394
|
+
type: '[product_metadata_insert_input!]!',
|
|
8395
|
+
value: [{ product_id: productId, ...metadata }],
|
|
8396
|
+
},
|
|
8397
|
+
});
|
|
8398
|
+
}
|
|
8004
8399
|
return plainData.metadata;
|
|
8005
8400
|
}
|
|
8006
8401
|
async getId(id) {
|
|
@@ -8011,7 +8406,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8011
8406
|
return data?.[0]?.id;
|
|
8012
8407
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
8013
8408
|
}
|
|
8014
|
-
async findReviewsByProduct(productId, options) {
|
|
8409
|
+
async findReviewsByProduct(productId, onlyApproved, options) {
|
|
8015
8410
|
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
8016
8411
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
8017
8412
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
@@ -8024,10 +8419,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8024
8419
|
where: {
|
|
8025
8420
|
value: {
|
|
8026
8421
|
product_id: { _eq: productId },
|
|
8422
|
+
...(onlyApproved && { status: { _eq: true } }),
|
|
8027
8423
|
},
|
|
8028
8424
|
type: 'product_review_bool_exp',
|
|
8029
8425
|
required: true,
|
|
8030
8426
|
},
|
|
8427
|
+
order_by: {
|
|
8428
|
+
type: '[product_review_order_by]',
|
|
8429
|
+
value: [{ createdAt: 'desc' }],
|
|
8430
|
+
required: true,
|
|
8431
|
+
},
|
|
8031
8432
|
});
|
|
8032
8433
|
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
8033
8434
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
@@ -8132,7 +8533,7 @@ tslib.__decorate([
|
|
|
8132
8533
|
tslib.__decorate([
|
|
8133
8534
|
Log(),
|
|
8134
8535
|
tslib.__metadata("design:type", Function),
|
|
8135
|
-
tslib.__metadata("design:paramtypes", [Number, Object]),
|
|
8536
|
+
tslib.__metadata("design:paramtypes", [Number, Boolean, Object]),
|
|
8136
8537
|
tslib.__metadata("design:returntype", Promise)
|
|
8137
8538
|
], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
|
|
8138
8539
|
|
|
@@ -8164,7 +8565,25 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
|
|
|
8164
8565
|
product: {
|
|
8165
8566
|
columnName: 'product',
|
|
8166
8567
|
foreignKeyColumn: { id: 'productId' },
|
|
8167
|
-
fields: [
|
|
8568
|
+
fields: [
|
|
8569
|
+
'id',
|
|
8570
|
+
{
|
|
8571
|
+
productId: {
|
|
8572
|
+
columnName: 'main_product_id',
|
|
8573
|
+
to: (value) => +value,
|
|
8574
|
+
from: (value) => value?.toString(),
|
|
8575
|
+
},
|
|
8576
|
+
},
|
|
8577
|
+
'ean',
|
|
8578
|
+
'sku',
|
|
8579
|
+
'name',
|
|
8580
|
+
'brand',
|
|
8581
|
+
'slug',
|
|
8582
|
+
'images',
|
|
8583
|
+
'grade',
|
|
8584
|
+
'gender',
|
|
8585
|
+
'',
|
|
8586
|
+
],
|
|
8168
8587
|
},
|
|
8169
8588
|
},
|
|
8170
8589
|
],
|
|
@@ -8357,6 +8776,7 @@ const fieldsConfiguration$1 = [
|
|
|
8357
8776
|
},
|
|
8358
8777
|
},
|
|
8359
8778
|
'group',
|
|
8779
|
+
'type',
|
|
8360
8780
|
'validity',
|
|
8361
8781
|
'published',
|
|
8362
8782
|
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
@@ -8380,6 +8800,124 @@ const fieldsConfiguration$1 = [
|
|
|
8380
8800
|
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8381
8801
|
},
|
|
8382
8802
|
},
|
|
8803
|
+
'slug',
|
|
8804
|
+
'brand',
|
|
8805
|
+
'name',
|
|
8806
|
+
'sku',
|
|
8807
|
+
{ NCM: { columnName: 'ncm' } },
|
|
8808
|
+
{ CEST: { columnName: 'cest' } },
|
|
8809
|
+
{
|
|
8810
|
+
description: {
|
|
8811
|
+
columnName: 'description',
|
|
8812
|
+
from: (description, data) => ({
|
|
8813
|
+
description,
|
|
8814
|
+
differentials: data.differentials,
|
|
8815
|
+
whoMustUse: data.who_must_use,
|
|
8816
|
+
howToUse: data.how_to_use,
|
|
8817
|
+
brand: data.brand_description,
|
|
8818
|
+
ingredients: data.ingredients,
|
|
8819
|
+
purpose: data.purpose,
|
|
8820
|
+
}),
|
|
8821
|
+
bindFindFilter: (filters) => {
|
|
8822
|
+
return {
|
|
8823
|
+
...(filters?.description && { description: filters.description }),
|
|
8824
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
8825
|
+
...(filters.whoMustUse && {
|
|
8826
|
+
who_must_use: filters.whoMustUse,
|
|
8827
|
+
}),
|
|
8828
|
+
...(filters.howToUse && {
|
|
8829
|
+
how_to_use: filters.howToUse,
|
|
8830
|
+
}),
|
|
8831
|
+
...(filters.brand && {
|
|
8832
|
+
brand_description: filters.brand,
|
|
8833
|
+
}),
|
|
8834
|
+
...(filters.ingredients && {
|
|
8835
|
+
ingredients: filters.ingredients,
|
|
8836
|
+
}),
|
|
8837
|
+
...(filters.purpose && {
|
|
8838
|
+
purpose: filters.purpose,
|
|
8839
|
+
}),
|
|
8840
|
+
};
|
|
8841
|
+
},
|
|
8842
|
+
bindPersistData: (descriptionData) => ({
|
|
8843
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
8844
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
8845
|
+
...(descriptionData.whoMustUse && {
|
|
8846
|
+
who_must_use: descriptionData.whoMustUse,
|
|
8847
|
+
}),
|
|
8848
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
8849
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
8850
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
8851
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
8852
|
+
}),
|
|
8853
|
+
},
|
|
8854
|
+
},
|
|
8855
|
+
{ differentials: { columnName: 'differentials' } },
|
|
8856
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
8857
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
8858
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
8859
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
8860
|
+
{ purpose: { columnName: 'purpose' } },
|
|
8861
|
+
'gender',
|
|
8862
|
+
{ intGender: { columnName: 'int_gender' } },
|
|
8863
|
+
'label',
|
|
8864
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8865
|
+
{ rate: { columnName: 'rating' } },
|
|
8866
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
8867
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
8868
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
8869
|
+
{
|
|
8870
|
+
category: {
|
|
8871
|
+
columnName: 'category',
|
|
8872
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
8873
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
8874
|
+
},
|
|
8875
|
+
},
|
|
8876
|
+
{
|
|
8877
|
+
categories: {
|
|
8878
|
+
columnName: 'categories',
|
|
8879
|
+
fields: ['category_id'],
|
|
8880
|
+
bindPersistData: (value) => ({
|
|
8881
|
+
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
8882
|
+
}),
|
|
8883
|
+
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
8884
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
8885
|
+
},
|
|
8886
|
+
},
|
|
8887
|
+
{
|
|
8888
|
+
metadata: {
|
|
8889
|
+
columnName: 'metadata',
|
|
8890
|
+
fields: ['title', 'description'],
|
|
8891
|
+
bindPersistData: (value) => ({
|
|
8892
|
+
metadata: { data: value },
|
|
8893
|
+
}),
|
|
8894
|
+
},
|
|
8895
|
+
},
|
|
8896
|
+
{
|
|
8897
|
+
reviews: {
|
|
8898
|
+
columnName: 'reviews',
|
|
8899
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
8900
|
+
fields: [
|
|
8901
|
+
'id',
|
|
8902
|
+
'shop',
|
|
8903
|
+
'rate',
|
|
8904
|
+
'author',
|
|
8905
|
+
'email',
|
|
8906
|
+
'location',
|
|
8907
|
+
'review',
|
|
8908
|
+
'status',
|
|
8909
|
+
'title',
|
|
8910
|
+
{ personId: { columnName: 'person_id' } },
|
|
8911
|
+
'points',
|
|
8912
|
+
{ orderId: { columnName: 'order_id' } },
|
|
8913
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8914
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8915
|
+
],
|
|
8916
|
+
},
|
|
8917
|
+
},
|
|
8918
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
8919
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8920
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8383
8921
|
];
|
|
8384
8922
|
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8385
8923
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
@@ -8420,18 +8958,46 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8420
8958
|
return data.at(0);
|
|
8421
8959
|
}
|
|
8422
8960
|
async update(params) {
|
|
8423
|
-
const { productId, id: checkId, ...data } = params;
|
|
8961
|
+
const { productId, id: checkId, metadata, ...data } = params;
|
|
8424
8962
|
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
8425
8963
|
if (!dataWithProductId.id) {
|
|
8426
8964
|
throw new NotFoundError('Variant ID is required for update');
|
|
8427
8965
|
}
|
|
8428
8966
|
const id = await this.getId(dataWithProductId.id);
|
|
8429
8967
|
const product = await super.update({ id, ...data });
|
|
8968
|
+
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
8430
8969
|
if (dataWithProductId.productId) {
|
|
8431
8970
|
product.productId = dataWithProductId.productId;
|
|
8432
8971
|
}
|
|
8433
8972
|
return product;
|
|
8434
8973
|
}
|
|
8974
|
+
async updateMetadata(productId, { metadata }) {
|
|
8975
|
+
const plainData = this.paramsToPlain({ metadata });
|
|
8976
|
+
if (!plainData.metadata)
|
|
8977
|
+
return null;
|
|
8978
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8979
|
+
const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
|
|
8980
|
+
pk_columns: {
|
|
8981
|
+
value: { product_id: productId },
|
|
8982
|
+
type: 'product_metadata_pk_columns_input',
|
|
8983
|
+
required: true,
|
|
8984
|
+
},
|
|
8985
|
+
_set: {
|
|
8986
|
+
value: lodash.omit(metadata, ['product_id']),
|
|
8987
|
+
type: 'product_metadata_set_input',
|
|
8988
|
+
required: true,
|
|
8989
|
+
},
|
|
8990
|
+
});
|
|
8991
|
+
if (!update_product_metadata_by_pk) {
|
|
8992
|
+
await this.mutation('insert_product_metadata', ['affected_rows'], {
|
|
8993
|
+
objects: {
|
|
8994
|
+
type: '[product_metadata_insert_input!]!',
|
|
8995
|
+
value: [{ product_id: productId, ...metadata }],
|
|
8996
|
+
},
|
|
8997
|
+
});
|
|
8998
|
+
}
|
|
8999
|
+
return plainData.metadata;
|
|
9000
|
+
}
|
|
8435
9001
|
async getId(id) {
|
|
8436
9002
|
if (!Number.isNaN(+id))
|
|
8437
9003
|
return id;
|
|
@@ -10425,6 +10991,8 @@ exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|
|
|
10425
10991
|
exports.PaymentProviderFactory = PaymentProviderFactory;
|
|
10426
10992
|
exports.PaymentTransaction = PaymentTransaction;
|
|
10427
10993
|
exports.Product = Product;
|
|
10994
|
+
exports.ProductCatalogHasuraGraphQL = ProductCatalogHasuraGraphQL;
|
|
10995
|
+
exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
|
|
10428
10996
|
exports.ProductErrors = ProductErrors;
|
|
10429
10997
|
exports.ProductErrorsHasuraGraphQL = ProductErrorsHasuraGraphQL;
|
|
10430
10998
|
exports.ProductErrorsHasuraGraphQLRepository = ProductErrorsHasuraGraphQLRepository;
|