@infrab4a/connect 5.3.0-beta.7 → 5.3.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 +531 -10
- package/index.esm.js +531 -8
- package/package.json +1 -1
- package/src/domain/catalog/models/product-base.d.ts +1 -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 -0
- 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/src/utils/index.d.ts +2 -2
package/index.cjs.js
CHANGED
|
@@ -5851,6 +5851,9 @@ tslib.__decorate([
|
|
|
5851
5851
|
tslib.__metadata("design:type", Product)
|
|
5852
5852
|
], KitProductHasuraGraphQL.prototype, "product", void 0);
|
|
5853
5853
|
|
|
5854
|
+
class ProductCatalogHasuraGraphQL extends Product {
|
|
5855
|
+
}
|
|
5856
|
+
|
|
5854
5857
|
class ProductHasuraGraphQL extends Product {
|
|
5855
5858
|
}
|
|
5856
5859
|
tslib.__decorate([
|
|
@@ -7216,6 +7219,300 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
|
|
|
7216
7219
|
}
|
|
7217
7220
|
}
|
|
7218
7221
|
|
|
7222
|
+
const commonFields$1 = [
|
|
7223
|
+
{
|
|
7224
|
+
id: {
|
|
7225
|
+
columnName: 'id',
|
|
7226
|
+
to: (value) => +value,
|
|
7227
|
+
from: (value) => value.toString(),
|
|
7228
|
+
},
|
|
7229
|
+
},
|
|
7230
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
7231
|
+
{ productId: { columnName: 'main_product_id' } },
|
|
7232
|
+
{ CEST: { columnName: 'cest' } },
|
|
7233
|
+
{ EAN: { columnName: 'ean' } },
|
|
7234
|
+
{ NCM: { columnName: 'ncm' } },
|
|
7235
|
+
'brand',
|
|
7236
|
+
{ costPrice: { columnName: 'cost_price' } },
|
|
7237
|
+
{
|
|
7238
|
+
description: {
|
|
7239
|
+
columnName: 'description',
|
|
7240
|
+
from: (description, data) => ({
|
|
7241
|
+
description,
|
|
7242
|
+
differentials: data.differentials,
|
|
7243
|
+
whoMustUse: data.who_must_use,
|
|
7244
|
+
howToUse: data.how_to_use,
|
|
7245
|
+
brand: data.brand_description,
|
|
7246
|
+
ingredients: data.ingredients,
|
|
7247
|
+
purpose: data.purpose,
|
|
7248
|
+
}),
|
|
7249
|
+
bindFindFilter: (filters) => {
|
|
7250
|
+
return {
|
|
7251
|
+
...(filters?.description && { description: filters.description }),
|
|
7252
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
7253
|
+
...(filters.whoMustUse && {
|
|
7254
|
+
who_must_use: filters.whoMustUse,
|
|
7255
|
+
}),
|
|
7256
|
+
...(filters.howToUse && {
|
|
7257
|
+
how_to_use: filters.howToUse,
|
|
7258
|
+
}),
|
|
7259
|
+
...(filters.brand && {
|
|
7260
|
+
brand_description: filters.brand,
|
|
7261
|
+
}),
|
|
7262
|
+
...(filters.ingredients && {
|
|
7263
|
+
ingredients: filters.ingredients,
|
|
7264
|
+
}),
|
|
7265
|
+
...(filters.purpose && {
|
|
7266
|
+
purpose: filters.purpose,
|
|
7267
|
+
}),
|
|
7268
|
+
};
|
|
7269
|
+
},
|
|
7270
|
+
bindPersistData: (descriptionData) => ({
|
|
7271
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
7272
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
7273
|
+
...(descriptionData.whoMustUse && {
|
|
7274
|
+
who_must_use: descriptionData.whoMustUse,
|
|
7275
|
+
}),
|
|
7276
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
7277
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
7278
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
7279
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
7280
|
+
}),
|
|
7281
|
+
},
|
|
7282
|
+
},
|
|
7283
|
+
{ differentials: { columnName: 'differentials' } },
|
|
7284
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
7285
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
7286
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
7287
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
7288
|
+
{ purpose: { columnName: 'purpose' } },
|
|
7289
|
+
{ hasVariants: { columnName: 'has_variants' } },
|
|
7290
|
+
{
|
|
7291
|
+
images: {
|
|
7292
|
+
columnName: 'images',
|
|
7293
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7294
|
+
},
|
|
7295
|
+
},
|
|
7296
|
+
{
|
|
7297
|
+
miniatures: {
|
|
7298
|
+
columnName: 'miniatures',
|
|
7299
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7300
|
+
},
|
|
7301
|
+
},
|
|
7302
|
+
{
|
|
7303
|
+
imagesCard: {
|
|
7304
|
+
columnName: 'images_card',
|
|
7305
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7306
|
+
},
|
|
7307
|
+
},
|
|
7308
|
+
'name',
|
|
7309
|
+
{
|
|
7310
|
+
price: {
|
|
7311
|
+
columnName: 'price',
|
|
7312
|
+
from: (price, data) => ({
|
|
7313
|
+
price,
|
|
7314
|
+
fullPrice: data.full_price,
|
|
7315
|
+
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
7316
|
+
fullPriceDiscountPercentage: data.full_price_discount_percentage,
|
|
7317
|
+
subscriberPrice: data.subscriber_price,
|
|
7318
|
+
}),
|
|
7319
|
+
bindFindFilter: (filters) => {
|
|
7320
|
+
return {
|
|
7321
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7322
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7323
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7324
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7325
|
+
}),
|
|
7326
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7327
|
+
subscriber_price: filters.subscriberPrice,
|
|
7328
|
+
}),
|
|
7329
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7330
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7331
|
+
}),
|
|
7332
|
+
};
|
|
7333
|
+
},
|
|
7334
|
+
bindPersistData: (priceData) => ({
|
|
7335
|
+
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
7336
|
+
...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
|
|
7337
|
+
...(priceData.subscriberDiscountPercentage >= 0 && {
|
|
7338
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
7339
|
+
}),
|
|
7340
|
+
...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
7341
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
7342
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
7343
|
+
}),
|
|
7344
|
+
}),
|
|
7345
|
+
},
|
|
7346
|
+
},
|
|
7347
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
7348
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
7349
|
+
{ fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
|
|
7350
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
7351
|
+
'published',
|
|
7352
|
+
'outlet',
|
|
7353
|
+
'label',
|
|
7354
|
+
'sku',
|
|
7355
|
+
{
|
|
7356
|
+
stock: {
|
|
7357
|
+
columnName: 'stock',
|
|
7358
|
+
from: (quantity) => ({ quantity }),
|
|
7359
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
7360
|
+
},
|
|
7361
|
+
},
|
|
7362
|
+
{ hasStock: { columnName: 'has_stock' } },
|
|
7363
|
+
'slug',
|
|
7364
|
+
'type',
|
|
7365
|
+
'video',
|
|
7366
|
+
'weight',
|
|
7367
|
+
'gender',
|
|
7368
|
+
{ intGender: { columnName: 'int_gender' } },
|
|
7369
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7370
|
+
{ isKit: { columnName: 'is_kit' } },
|
|
7371
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
7372
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
7373
|
+
{ rate: { columnName: 'rating' } },
|
|
7374
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
7375
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
7376
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
7377
|
+
{
|
|
7378
|
+
category: {
|
|
7379
|
+
columnName: 'category',
|
|
7380
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
7381
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
7382
|
+
},
|
|
7383
|
+
},
|
|
7384
|
+
'group',
|
|
7385
|
+
'validity',
|
|
7386
|
+
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7387
|
+
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7388
|
+
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
7389
|
+
{ showVariants: { columnName: 'show_variants' } },
|
|
7390
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
7391
|
+
];
|
|
7392
|
+
class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7393
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
7394
|
+
super({
|
|
7395
|
+
tableName: 'product_catalog',
|
|
7396
|
+
model: ProductCatalogHasuraGraphQL,
|
|
7397
|
+
endpoint,
|
|
7398
|
+
authOptions,
|
|
7399
|
+
interceptors,
|
|
7400
|
+
fields: commonFields$1,
|
|
7401
|
+
cache,
|
|
7402
|
+
});
|
|
7403
|
+
}
|
|
7404
|
+
async get({ id }, options) {
|
|
7405
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7406
|
+
const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
|
|
7407
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7408
|
+
if (cachedData) {
|
|
7409
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
7410
|
+
return this.model.toInstance(deserialize(cachedData));
|
|
7411
|
+
}
|
|
7412
|
+
}
|
|
7413
|
+
const product = await super
|
|
7414
|
+
.find({
|
|
7415
|
+
filters: {
|
|
7416
|
+
id,
|
|
7417
|
+
},
|
|
7418
|
+
limits: {
|
|
7419
|
+
limit: 1,
|
|
7420
|
+
},
|
|
7421
|
+
})
|
|
7422
|
+
.then((res) => res.data.at(0));
|
|
7423
|
+
if (!product)
|
|
7424
|
+
throw new NotFoundError(`Product not found`);
|
|
7425
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7426
|
+
const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
|
|
7427
|
+
await this.cache.cacheAdapter.set({
|
|
7428
|
+
key: cacheKey,
|
|
7429
|
+
data: serialize(product),
|
|
7430
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7431
|
+
});
|
|
7432
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7433
|
+
}
|
|
7434
|
+
return product;
|
|
7435
|
+
}
|
|
7436
|
+
async getByEAN(EAN, options) {
|
|
7437
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7438
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7439
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7440
|
+
if (cachedData) {
|
|
7441
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
7442
|
+
return this.model.toInstance(deserialize(cachedData));
|
|
7443
|
+
}
|
|
7444
|
+
}
|
|
7445
|
+
const product = await super
|
|
7446
|
+
.find({
|
|
7447
|
+
filters: {
|
|
7448
|
+
EAN,
|
|
7449
|
+
},
|
|
7450
|
+
limits: {
|
|
7451
|
+
limit: 1,
|
|
7452
|
+
},
|
|
7453
|
+
})
|
|
7454
|
+
.then((res) => res.data.at(0));
|
|
7455
|
+
if (!product)
|
|
7456
|
+
return null;
|
|
7457
|
+
RoundProductPricesHelper.roundProductPrices(product);
|
|
7458
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7459
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7460
|
+
await this.cache.cacheAdapter.set({
|
|
7461
|
+
key: cacheKey,
|
|
7462
|
+
data: serialize(product),
|
|
7463
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7464
|
+
});
|
|
7465
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7466
|
+
}
|
|
7467
|
+
return product;
|
|
7468
|
+
}
|
|
7469
|
+
async find(params, optionsParams) {
|
|
7470
|
+
const { filters, fields, ...options } = params || {};
|
|
7471
|
+
const bindFields = fields ||
|
|
7472
|
+
this.fields
|
|
7473
|
+
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
7474
|
+
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
7475
|
+
if (options.options?.minimal?.includes('price'))
|
|
7476
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7477
|
+
if (options.options?.maximum?.includes('price'))
|
|
7478
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7479
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
7480
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
7481
|
+
return super.find({
|
|
7482
|
+
...options,
|
|
7483
|
+
filters: { ...filters },
|
|
7484
|
+
fields: [
|
|
7485
|
+
...bindFields,
|
|
7486
|
+
...(bindFields.includes('price')
|
|
7487
|
+
? [
|
|
7488
|
+
'subscriberPrice',
|
|
7489
|
+
'subscriberDiscountPercentage',
|
|
7490
|
+
'fullPrice',
|
|
7491
|
+
]
|
|
7492
|
+
: []),
|
|
7493
|
+
],
|
|
7494
|
+
}, optionsParams);
|
|
7495
|
+
}
|
|
7496
|
+
async findCatalog(params, mainGender, options) {
|
|
7497
|
+
const result = await this.find({
|
|
7498
|
+
...params,
|
|
7499
|
+
filters: { ...params.filters, published: true },
|
|
7500
|
+
orderBy: {
|
|
7501
|
+
hasStock: 'desc',
|
|
7502
|
+
...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
|
|
7503
|
+
...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
|
|
7504
|
+
},
|
|
7505
|
+
}, options);
|
|
7506
|
+
return result;
|
|
7507
|
+
}
|
|
7508
|
+
}
|
|
7509
|
+
tslib.__decorate([
|
|
7510
|
+
Log(),
|
|
7511
|
+
tslib.__metadata("design:type", Function),
|
|
7512
|
+
tslib.__metadata("design:paramtypes", [Object, Object, Object]),
|
|
7513
|
+
tslib.__metadata("design:returntype", Promise)
|
|
7514
|
+
], ProductCatalogHasuraGraphQLRepository.prototype, "findCatalog", null);
|
|
7515
|
+
|
|
7219
7516
|
class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7220
7517
|
constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
|
|
7221
7518
|
super({
|
|
@@ -7459,6 +7756,8 @@ const commonFields = [
|
|
|
7459
7756
|
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7460
7757
|
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7461
7758
|
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
7759
|
+
{ showVariants: { columnName: 'show_variants' } },
|
|
7760
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
7462
7761
|
];
|
|
7463
7762
|
const fieldsConfiguration$2 = [
|
|
7464
7763
|
...commonFields,
|
|
@@ -7522,9 +7821,61 @@ const fieldsConfiguration$2 = [
|
|
|
7522
7821
|
foreignKeyColumn: { product_id: 'id' },
|
|
7523
7822
|
fields: [
|
|
7524
7823
|
'id',
|
|
7824
|
+
'name',
|
|
7525
7825
|
'ean',
|
|
7526
7826
|
'sku',
|
|
7527
|
-
|
|
7827
|
+
{
|
|
7828
|
+
description: {
|
|
7829
|
+
columnName: 'description',
|
|
7830
|
+
from: (description, data) => ({
|
|
7831
|
+
description,
|
|
7832
|
+
differentials: data.differentials,
|
|
7833
|
+
whoMustUse: data.who_must_use,
|
|
7834
|
+
howToUse: data.how_to_use,
|
|
7835
|
+
brand: data.brand_description,
|
|
7836
|
+
ingredients: data.ingredients,
|
|
7837
|
+
purpose: data.purpose,
|
|
7838
|
+
}),
|
|
7839
|
+
bindFindFilter: (filters) => {
|
|
7840
|
+
return {
|
|
7841
|
+
...(filters?.description && { description: filters.description }),
|
|
7842
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
7843
|
+
...(filters.whoMustUse && {
|
|
7844
|
+
who_must_use: filters.whoMustUse,
|
|
7845
|
+
}),
|
|
7846
|
+
...(filters.howToUse && {
|
|
7847
|
+
how_to_use: filters.howToUse,
|
|
7848
|
+
}),
|
|
7849
|
+
...(filters.brand && {
|
|
7850
|
+
brand_description: filters.brand,
|
|
7851
|
+
}),
|
|
7852
|
+
...(filters.ingredients && {
|
|
7853
|
+
ingredients: filters.ingredients,
|
|
7854
|
+
}),
|
|
7855
|
+
...(filters.purpose && {
|
|
7856
|
+
purpose: filters.purpose,
|
|
7857
|
+
}),
|
|
7858
|
+
};
|
|
7859
|
+
},
|
|
7860
|
+
bindPersistData: (descriptionData) => ({
|
|
7861
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
7862
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
7863
|
+
...(descriptionData.whoMustUse && {
|
|
7864
|
+
who_must_use: descriptionData.whoMustUse,
|
|
7865
|
+
}),
|
|
7866
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
7867
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
7868
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
7869
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
7870
|
+
}),
|
|
7871
|
+
},
|
|
7872
|
+
},
|
|
7873
|
+
{ differentials: { columnName: 'differentials' } },
|
|
7874
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
7875
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
7876
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
7877
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
7878
|
+
{ purpose: { columnName: 'purpose' } },
|
|
7528
7879
|
{
|
|
7529
7880
|
grade: {
|
|
7530
7881
|
columnName: 'grade',
|
|
@@ -7570,6 +7921,10 @@ const fieldsConfiguration$2 = [
|
|
|
7570
7921
|
}),
|
|
7571
7922
|
},
|
|
7572
7923
|
},
|
|
7924
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
7925
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
7926
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
7927
|
+
{ fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
|
|
7573
7928
|
'published',
|
|
7574
7929
|
{
|
|
7575
7930
|
stock: {
|
|
@@ -7598,6 +7953,29 @@ const fieldsConfiguration$2 = [
|
|
|
7598
7953
|
},
|
|
7599
7954
|
{ tagsProfile: { columnName: 'tags_profile' } },
|
|
7600
7955
|
{ tagsCollection: { columnName: 'tags_collection' } },
|
|
7956
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
7957
|
+
{
|
|
7958
|
+
reviews: {
|
|
7959
|
+
columnName: 'reviews',
|
|
7960
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
7961
|
+
fields: [
|
|
7962
|
+
'id',
|
|
7963
|
+
'shop',
|
|
7964
|
+
'rate',
|
|
7965
|
+
'author',
|
|
7966
|
+
'email',
|
|
7967
|
+
'location',
|
|
7968
|
+
'review',
|
|
7969
|
+
'status',
|
|
7970
|
+
'title',
|
|
7971
|
+
{ personId: { columnName: 'person_id' } },
|
|
7972
|
+
'points',
|
|
7973
|
+
{ orderId: { columnName: 'order_id' } },
|
|
7974
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
7975
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
7976
|
+
],
|
|
7977
|
+
},
|
|
7978
|
+
},
|
|
7601
7979
|
],
|
|
7602
7980
|
},
|
|
7603
7981
|
},
|
|
@@ -7663,7 +8041,12 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7663
8041
|
: await super.get(identifiers, options);
|
|
7664
8042
|
if (product.productId)
|
|
7665
8043
|
throw new NotFoundError('Product not found, it is a variant');
|
|
7666
|
-
product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
|
|
8044
|
+
product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
|
|
8045
|
+
if (!product.variants?.length) {
|
|
8046
|
+
for (const [index, variant] of product.variants.entries()) {
|
|
8047
|
+
product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
|
|
8048
|
+
}
|
|
8049
|
+
}
|
|
7667
8050
|
return product;
|
|
7668
8051
|
}
|
|
7669
8052
|
async find(params, optionsParams) {
|
|
@@ -7680,7 +8063,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7680
8063
|
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
7681
8064
|
return super.find({
|
|
7682
8065
|
...options,
|
|
7683
|
-
filters: { ...filters
|
|
8066
|
+
filters: { ...filters },
|
|
7684
8067
|
fields: [
|
|
7685
8068
|
...bindFields,
|
|
7686
8069
|
...(bindFields.includes('price')
|
|
@@ -7705,6 +8088,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7705
8088
|
const result = await this.find({
|
|
7706
8089
|
filters: {
|
|
7707
8090
|
slug,
|
|
8091
|
+
productId: {
|
|
8092
|
+
operator: exports.Where.ISNULL,
|
|
8093
|
+
},
|
|
7708
8094
|
},
|
|
7709
8095
|
fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
|
|
7710
8096
|
options: {
|
|
@@ -7714,6 +8100,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7714
8100
|
if (!result.data.length)
|
|
7715
8101
|
return null;
|
|
7716
8102
|
const product = result?.data?.shift();
|
|
8103
|
+
if (!product.variants?.length) {
|
|
8104
|
+
for (const [index, variant] of product.variants.entries()) {
|
|
8105
|
+
product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
|
|
8106
|
+
}
|
|
8107
|
+
}
|
|
7717
8108
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
7718
8109
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7719
8110
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
@@ -7915,7 +8306,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7915
8306
|
return data?.[0]?.id;
|
|
7916
8307
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7917
8308
|
}
|
|
7918
|
-
async findReviewsByProduct(productId, options) {
|
|
8309
|
+
async findReviewsByProduct(productId, onlyApproved, options) {
|
|
7919
8310
|
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7920
8311
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7921
8312
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
@@ -7928,10 +8319,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7928
8319
|
where: {
|
|
7929
8320
|
value: {
|
|
7930
8321
|
product_id: { _eq: productId },
|
|
8322
|
+
...(onlyApproved && { status: { _eq: true } }),
|
|
7931
8323
|
},
|
|
7932
8324
|
type: 'product_review_bool_exp',
|
|
7933
8325
|
required: true,
|
|
7934
8326
|
},
|
|
8327
|
+
order_by: {
|
|
8328
|
+
type: '[product_review_order_by]',
|
|
8329
|
+
value: [{ createdAt: 'desc' }],
|
|
8330
|
+
required: true,
|
|
8331
|
+
},
|
|
7935
8332
|
});
|
|
7936
8333
|
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
7937
8334
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
@@ -8036,7 +8433,7 @@ tslib.__decorate([
|
|
|
8036
8433
|
tslib.__decorate([
|
|
8037
8434
|
Log(),
|
|
8038
8435
|
tslib.__metadata("design:type", Function),
|
|
8039
|
-
tslib.__metadata("design:paramtypes", [Number, Object]),
|
|
8436
|
+
tslib.__metadata("design:paramtypes", [Number, Boolean, Object]),
|
|
8040
8437
|
tslib.__metadata("design:returntype", Promise)
|
|
8041
8438
|
], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
|
|
8042
8439
|
|
|
@@ -8284,6 +8681,113 @@ const fieldsConfiguration$1 = [
|
|
|
8284
8681
|
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8285
8682
|
},
|
|
8286
8683
|
},
|
|
8684
|
+
'slug',
|
|
8685
|
+
'brand',
|
|
8686
|
+
'name',
|
|
8687
|
+
'sku',
|
|
8688
|
+
{ NCM: { columnName: 'ncm' } },
|
|
8689
|
+
{ CEST: { columnName: 'cest' } },
|
|
8690
|
+
{
|
|
8691
|
+
description: {
|
|
8692
|
+
columnName: 'description',
|
|
8693
|
+
from: (description, data) => ({
|
|
8694
|
+
description,
|
|
8695
|
+
differentials: data.differentials,
|
|
8696
|
+
whoMustUse: data.who_must_use,
|
|
8697
|
+
howToUse: data.how_to_use,
|
|
8698
|
+
brand: data.brand_description,
|
|
8699
|
+
ingredients: data.ingredients,
|
|
8700
|
+
purpose: data.purpose,
|
|
8701
|
+
}),
|
|
8702
|
+
bindFindFilter: (filters) => {
|
|
8703
|
+
return {
|
|
8704
|
+
...(filters?.description && { description: filters.description }),
|
|
8705
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
8706
|
+
...(filters.whoMustUse && {
|
|
8707
|
+
who_must_use: filters.whoMustUse,
|
|
8708
|
+
}),
|
|
8709
|
+
...(filters.howToUse && {
|
|
8710
|
+
how_to_use: filters.howToUse,
|
|
8711
|
+
}),
|
|
8712
|
+
...(filters.brand && {
|
|
8713
|
+
brand_description: filters.brand,
|
|
8714
|
+
}),
|
|
8715
|
+
...(filters.ingredients && {
|
|
8716
|
+
ingredients: filters.ingredients,
|
|
8717
|
+
}),
|
|
8718
|
+
...(filters.purpose && {
|
|
8719
|
+
purpose: filters.purpose,
|
|
8720
|
+
}),
|
|
8721
|
+
};
|
|
8722
|
+
},
|
|
8723
|
+
bindPersistData: (descriptionData) => ({
|
|
8724
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
8725
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
8726
|
+
...(descriptionData.whoMustUse && {
|
|
8727
|
+
who_must_use: descriptionData.whoMustUse,
|
|
8728
|
+
}),
|
|
8729
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
8730
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
8731
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
8732
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
8733
|
+
}),
|
|
8734
|
+
},
|
|
8735
|
+
},
|
|
8736
|
+
{ differentials: { columnName: 'differentials' } },
|
|
8737
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
8738
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
8739
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
8740
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
8741
|
+
{ purpose: { columnName: 'purpose' } },
|
|
8742
|
+
'gender',
|
|
8743
|
+
{ intGender: { columnName: 'int_gender' } },
|
|
8744
|
+
'label',
|
|
8745
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8746
|
+
{ rate: { columnName: 'rating' } },
|
|
8747
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
8748
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
8749
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
8750
|
+
{
|
|
8751
|
+
category: {
|
|
8752
|
+
columnName: 'category',
|
|
8753
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
8754
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
8755
|
+
},
|
|
8756
|
+
},
|
|
8757
|
+
{
|
|
8758
|
+
metadata: {
|
|
8759
|
+
columnName: 'metadata',
|
|
8760
|
+
fields: ['title', 'description'],
|
|
8761
|
+
bindPersistData: (value) => ({
|
|
8762
|
+
metadata: { data: value },
|
|
8763
|
+
}),
|
|
8764
|
+
},
|
|
8765
|
+
},
|
|
8766
|
+
{
|
|
8767
|
+
reviews: {
|
|
8768
|
+
columnName: 'reviews',
|
|
8769
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
8770
|
+
fields: [
|
|
8771
|
+
'id',
|
|
8772
|
+
'shop',
|
|
8773
|
+
'rate',
|
|
8774
|
+
'author',
|
|
8775
|
+
'email',
|
|
8776
|
+
'location',
|
|
8777
|
+
'review',
|
|
8778
|
+
'status',
|
|
8779
|
+
'title',
|
|
8780
|
+
{ personId: { columnName: 'person_id' } },
|
|
8781
|
+
'points',
|
|
8782
|
+
{ orderId: { columnName: 'order_id' } },
|
|
8783
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8784
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8785
|
+
],
|
|
8786
|
+
},
|
|
8787
|
+
},
|
|
8788
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
8789
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8790
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8287
8791
|
];
|
|
8288
8792
|
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8289
8793
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
@@ -8324,18 +8828,37 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8324
8828
|
return data.at(0);
|
|
8325
8829
|
}
|
|
8326
8830
|
async update(params) {
|
|
8327
|
-
const { productId, id: checkId, ...data } = params;
|
|
8831
|
+
const { productId, id: checkId, metadata, ...data } = params;
|
|
8328
8832
|
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
8329
8833
|
if (!dataWithProductId.id) {
|
|
8330
8834
|
throw new NotFoundError('Variant ID is required for update');
|
|
8331
8835
|
}
|
|
8332
8836
|
const id = await this.getId(dataWithProductId.id);
|
|
8333
8837
|
const product = await super.update({ id, ...data });
|
|
8838
|
+
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
8334
8839
|
if (dataWithProductId.productId) {
|
|
8335
8840
|
product.productId = dataWithProductId.productId;
|
|
8336
8841
|
}
|
|
8337
8842
|
return product;
|
|
8338
8843
|
}
|
|
8844
|
+
async updateMetadata(productId, { metadata }) {
|
|
8845
|
+
const plainData = this.paramsToPlain({ metadata });
|
|
8846
|
+
if (!plainData.metadata)
|
|
8847
|
+
return null;
|
|
8848
|
+
await this.mutation('update_product_metadata_by_pk', ['product_id'], {
|
|
8849
|
+
pk_columns: {
|
|
8850
|
+
value: { product_id: productId },
|
|
8851
|
+
type: 'product_metadata_pk_columns_input',
|
|
8852
|
+
required: true,
|
|
8853
|
+
},
|
|
8854
|
+
_set: {
|
|
8855
|
+
value: lodash.omit(metadata, ['product_id']),
|
|
8856
|
+
type: 'product_metadata_set_input',
|
|
8857
|
+
required: true,
|
|
8858
|
+
},
|
|
8859
|
+
});
|
|
8860
|
+
return plainData.metadata;
|
|
8861
|
+
}
|
|
8339
8862
|
async getId(id) {
|
|
8340
8863
|
if (!Number.isNaN(+id))
|
|
8341
8864
|
return id;
|
|
@@ -9715,10 +10238,6 @@ Object.defineProperty(exports, 'formatInTimeZone', {
|
|
|
9715
10238
|
enumerable: true,
|
|
9716
10239
|
get: function () { return dateFnsTz.formatInTimeZone; }
|
|
9717
10240
|
});
|
|
9718
|
-
Object.defineProperty(exports, 'utcToZonedTime', {
|
|
9719
|
-
enumerable: true,
|
|
9720
|
-
get: function () { return dateFnsTz.utcToZonedTime; }
|
|
9721
|
-
});
|
|
9722
10241
|
Object.defineProperty(exports, 'chunk', {
|
|
9723
10242
|
enumerable: true,
|
|
9724
10243
|
get: function () { return lodash.chunk; }
|
|
@@ -9883,6 +10402,8 @@ exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|
|
|
9883
10402
|
exports.PaymentProviderFactory = PaymentProviderFactory;
|
|
9884
10403
|
exports.PaymentTransaction = PaymentTransaction;
|
|
9885
10404
|
exports.Product = Product;
|
|
10405
|
+
exports.ProductCatalogHasuraGraphQL = ProductCatalogHasuraGraphQL;
|
|
10406
|
+
exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
|
|
9886
10407
|
exports.ProductErrors = ProductErrors;
|
|
9887
10408
|
exports.ProductErrorsHasuraGraphQL = ProductErrorsHasuraGraphQL;
|
|
9888
10409
|
exports.ProductErrorsHasuraGraphQLRepository = ProductErrorsHasuraGraphQLRepository;
|