@infrab4a/connect 5.3.0-beta.3 → 5.3.0-beta.30
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 +2985 -447
- package/index.esm.js +2950 -450
- package/package.json +3 -2
- package/src/domain/catalog/models/category-brand.d.ts +17 -0
- package/src/domain/catalog/models/category.d.ts +12 -0
- package/src/domain/catalog/models/enums/shops.enum.d.ts +2 -0
- package/src/domain/catalog/models/index.d.ts +4 -0
- package/src/domain/catalog/models/product-base.d.ts +10 -0
- package/src/domain/catalog/models/product-group.d.ts +12 -0
- package/src/domain/catalog/models/product-price-log.d.ts +25 -0
- package/src/domain/catalog/models/product-review.d.ts +2 -0
- package/src/domain/catalog/models/product-stock-entry.d.ts +16 -0
- package/src/domain/catalog/models/product.d.ts +1 -0
- package/src/domain/catalog/models/types/brands-shop-menu.type.d.ts +13 -0
- package/src/domain/catalog/models/types/index.d.ts +2 -0
- package/src/domain/catalog/models/types/product-competitors-price.d.ts +6 -0
- package/src/domain/catalog/repositories/category-brand.repository.d.ts +4 -0
- package/src/domain/catalog/repositories/category-product.repository.d.ts +2 -0
- package/src/domain/catalog/repositories/category.repository.d.ts +1 -0
- package/src/domain/catalog/repositories/index.d.ts +5 -0
- package/src/domain/catalog/repositories/product-catalog.repository.d.ts +17 -0
- package/src/domain/catalog/repositories/product-group.repository.d.ts +4 -0
- package/src/domain/catalog/repositories/product-price-log.repository.d.ts +4 -0
- package/src/domain/catalog/repositories/product-stock-entry.repository.d.ts +4 -0
- package/src/domain/shop-settings/enums/shop-page-name.enum.d.ts +2 -1
- package/src/domain/shop-settings/models/home.d.ts +2 -1
- package/src/domain/shop-settings/models/index.d.ts +2 -1
- package/src/domain/shop-settings/models/shop-configs.d.ts +18 -0
- package/src/domain/shop-settings/models/{shop-settings.d.ts → shop-page-settings.d.ts} +4 -1
- package/src/domain/shop-settings/models/types/index.d.ts +3 -0
- package/src/domain/shop-settings/models/types/limit-orders.type.d.ts +7 -0
- package/src/domain/shop-settings/models/types/shipping-thresholds.type.d.ts +17 -0
- package/src/domain/shop-settings/models/types/shop-error-messages.type.d.ts +10 -0
- package/src/domain/shop-settings/models/types/shop-page-section.type.d.ts +140 -0
- package/src/domain/shop-settings/repositories/index.d.ts +1 -0
- package/src/domain/shop-settings/repositories/shop-configs.repository.d.ts +4 -0
- package/src/domain/shop-settings/repositories/shop-settings.repository.d.ts +1 -1
- package/src/domain/shopping/enums/index.d.ts +3 -0
- package/src/domain/shopping/enums/order-payment-status.enum.d.ts +10 -0
- package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +24 -0
- package/src/domain/shopping/enums/payment-providers.enum.d.ts +2 -1
- package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +5 -0
- package/src/domain/shopping/factories/index.d.ts +1 -0
- package/src/domain/shopping/factories/mercado-pago-payment-method.factory.d.ts +11 -0
- package/src/domain/shopping/factories/payment-provider.factory.d.ts +2 -0
- package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +10 -2
- package/src/domain/shopping/models/enums/index.d.ts +3 -0
- package/src/domain/shopping/models/enums/order-status.enum.d.ts +2 -1
- package/src/domain/shopping/models/enums/shopping-recurrence-cycle.enum.d.ts +5 -0
- package/src/domain/shopping/models/enums/shopping-recurrence-edition-status.enum.d.ts +11 -0
- package/src/domain/shopping/models/enums/shopping-recurrence-status.enum.d.ts +7 -0
- package/src/domain/shopping/models/index.d.ts +1 -0
- package/src/domain/shopping/models/line-item.d.ts +1 -0
- package/src/domain/shopping/models/order-blocked.d.ts +5 -0
- package/src/domain/shopping/models/order.d.ts +19 -0
- package/src/domain/shopping/models/payment-transaction.d.ts +19 -2
- package/src/domain/shopping/models/payment.d.ts +3 -1
- package/src/domain/shopping/models/recurrence/index.d.ts +3 -0
- package/src/domain/shopping/models/recurrence/shopping-recurrence-edition.d.ts +18 -0
- package/src/domain/shopping/models/recurrence/shopping-recurrence-error-log.d.ts +9 -0
- package/src/domain/shopping/models/recurrence/shopping-recurrence.d.ts +45 -0
- package/src/domain/shopping/models/shipping-method.d.ts +2 -0
- package/src/domain/shopping/models/types/index.d.ts +1 -0
- package/src/domain/shopping/models/types/line-item-recurrence.type.d.ts +2 -0
- package/src/domain/shopping/repositories/index.d.ts +1 -0
- package/src/domain/shopping/repositories/order-blocked.repository.d.ts +5 -0
- package/src/domain/shopping/repositories/recurrence/index.d.ts +3 -0
- package/src/domain/shopping/repositories/recurrence/shopping-recurrence-edition.repository.d.ts +4 -0
- package/src/domain/shopping/repositories/recurrence/shopping-recurrence-error-log.repository.d.ts +4 -0
- package/src/domain/shopping/repositories/recurrence/shopping-recurrence.repository.d.ts +9 -0
- package/src/domain/shopping/services/antifraud-card.service.d.ts +2 -0
- package/src/domain/shopping/types/card-info.type.d.ts +1 -0
- package/src/domain/shopping/types/checkout-paylod-request.type.d.ts +2 -7
- package/src/domain/shopping/types/create-recurrency-payload.type.d.ts +8 -0
- package/src/domain/shopping/types/index.d.ts +4 -0
- package/src/domain/shopping/types/mercado-pago-card.type.d.ts +14 -0
- package/src/domain/shopping/types/mercado-pago-credentials.type.d.ts +5 -0
- package/src/domain/shopping/types/pagarme-card.type.d.ts +9 -3
- package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +4 -0
- package/src/domain/shopping/types/pagarme-credentials.type.d.ts +9 -3
- package/src/domain/shopping/types/payment-card-info.type.d.ts +6 -1
- package/src/domain/users/models/user-payment-method.d.ts +2 -0
- package/src/domain/users/models/user.d.ts +1 -0
- package/src/errors/enum/error.enum.d.ts +14 -0
- package/src/errors/enum/index.d.ts +1 -0
- package/src/errors/fraud-validation.error.d.ts +1 -1
- package/src/errors/index.d.ts +2 -0
- package/src/errors/invalid-checkout.error.d.ts +7 -0
- package/src/errors/not-found.error.d.ts +1 -0
- package/src/errors/payment.error.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/catalog/category-brand-firestore.repository.d.ts +7 -0
- package/src/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +1 -0
- package/src/infra/firebase/firestore/repositories/catalog/index.d.ts +1 -0
- package/src/infra/firebase/firestore/repositories/shop-settings/index.d.ts +1 -0
- package/src/infra/firebase/firestore/repositories/shop-settings/shop-configs-firestore.repository.d.ts +7 -0
- package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +3 -0
- package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +1 -0
- package/src/infra/firebase/firestore/repositories/shopping/shopping-recurrence-edition-firestore.repository.d.ts +7 -0
- package/src/infra/firebase/firestore/repositories/shopping/shopping-recurrence-error-log-firestore.repository.d.ts +7 -0
- package/src/infra/firebase/firestore/repositories/shopping/shopping-recurrence-firestore.repository.d.ts +10 -0
- package/src/infra/hasura-graphql/models/index.d.ts +2 -0
- package/src/infra/hasura-graphql/models/product-catalog-hasura-graphql.d.ts +16 -0
- package/src/infra/hasura-graphql/models/product-stock-entry-hasura-graphql.d.ts +3 -0
- package/src/infra/hasura-graphql/models/variant-hasura-graphql.d.ts +7 -0
- package/src/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +1 -0
- package/src/infra/hasura-graphql/repositories/catalog/category-product-hasura-graphql.repository.d.ts +2 -0
- package/src/infra/hasura-graphql/repositories/catalog/index.d.ts +4 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-catalog-hasura-graphql.repository.d.ts +22 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-group-hasura-graphql.repository.d.ts +7 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-price-log-hasura-graphql.repository.d.ts +7 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-stock-entry-hasura-graphql.repository.d.ts +8 -0
- package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +1 -0
- package/src/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +1 -0
- package/src/infra/index.d.ts +1 -0
- package/src/infra/mercado-pago/adapters/index.d.ts +3 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-base-axios.d.ts +11 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-boleto-payment-axios.adapter.d.ts +8 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-card-payment-axios.adapter.d.ts +22 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-pix-payment-axios.adapter.d.ts +8 -0
- package/src/infra/mercado-pago/enums/index.d.ts +2 -0
- package/src/infra/mercado-pago/enums/mercado-pago-status-detail.enum.d.ts +33 -0
- package/src/infra/mercado-pago/enums/mercado-pago-status.enum.d.ts +10 -0
- package/src/infra/mercado-pago/helpers/index.d.ts +3 -0
- package/src/infra/mercado-pago/helpers/mercado-pago-errors.helper.d.ts +3 -0
- package/src/infra/mercado-pago/helpers/mercado-pago-request.helper.d.ts +60 -0
- package/src/infra/mercado-pago/helpers/mercado-pago-response.helper.d.ts +10 -0
- package/src/infra/mercado-pago/index.d.ts +4 -0
- package/src/infra/mercado-pago/types/index.d.ts +3 -0
- package/src/infra/mercado-pago/types/mercado-pago-request.type.d.ts +1 -0
- package/src/infra/mercado-pago/types/mercado-pago-response.type.d.ts +211 -0
- package/src/infra/mercado-pago/types/mercado-pago-status-detail.type.d.ts +2 -0
- package/src/infra/mercado-pago/types/mercado-pago-status.type.d.ts +2 -0
- package/src/infra/pagarme/adapters/helpers/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-blocked-order.helper.d.ts +7 -2
- package/src/infra/pagarme/adapters/helpers/pagarme-errors.helper.d.ts +3 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +13 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +10 -0
- package/src/infra/pagarme/adapters/index.d.ts +2 -3
- package/src/infra/pagarme/adapters/v4/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/{pagarme-bank-slip-payment-axios.adapter.d.ts → v4/pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
- package/src/infra/pagarme/adapters/{pagarme-card-payment-axios.adapter.d.ts → v4/pagarme-card-payment-axios.adapter.d.ts} +7 -6
- package/src/infra/pagarme/adapters/{pagarme-pix-payment-axios.adapter.d.ts → v4/pagarme-pix-payment-axios.adapter.d.ts} +4 -4
- package/src/infra/pagarme/adapters/v5/index.d.ts +4 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-base-axios.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +25 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/index.d.ts +1 -0
- package/src/infra/pagarme/types/index.d.ts +1 -0
- package/src/infra/pagarme/types/v5/index.d.ts +4 -0
- package/src/infra/pagarme/types/v5/pagarmev5-customer.type.d.ts +19 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +91 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +241 -0
- package/src/infra/pagarme/types/v5/pagarmev5-postback-response.type.d.ts +11 -0
- package/src/utils/index.d.ts +3 -2
package/index.cjs.js
CHANGED
|
@@ -6,6 +6,7 @@ require('reflect-metadata');
|
|
|
6
6
|
var tslib = require('tslib');
|
|
7
7
|
var classTransformer = require('class-transformer');
|
|
8
8
|
var dateFns = require('date-fns');
|
|
9
|
+
var dateFnsTz = require('date-fns-tz');
|
|
9
10
|
var lodash = require('lodash');
|
|
10
11
|
var debug = require('debug');
|
|
11
12
|
var serializeJavascript = require('serialize-javascript');
|
|
@@ -61,6 +62,18 @@ exports.OrderBlockedType = void 0;
|
|
|
61
62
|
OrderBlockedType["Boleto"] = "Boleto";
|
|
62
63
|
})(exports.OrderBlockedType || (exports.OrderBlockedType = {}));
|
|
63
64
|
|
|
65
|
+
exports.OrderPaymentStatus = void 0;
|
|
66
|
+
(function (OrderPaymentStatus) {
|
|
67
|
+
OrderPaymentStatus["Em processamento"] = "processing";
|
|
68
|
+
OrderPaymentStatus["Autorizada"] = "authorized";
|
|
69
|
+
OrderPaymentStatus["Pago"] = "paid";
|
|
70
|
+
OrderPaymentStatus["Estornada"] = "refunded";
|
|
71
|
+
OrderPaymentStatus["Aguardando pagamento"] = "waiting_payment";
|
|
72
|
+
OrderPaymentStatus["Aguardando estorno"] = "pending_refund";
|
|
73
|
+
OrderPaymentStatus["Recusada/N\u00E3o autorizada"] = "refused";
|
|
74
|
+
OrderPaymentStatus["Chargedback"] = "chargedback";
|
|
75
|
+
})(exports.OrderPaymentStatus || (exports.OrderPaymentStatus = {}));
|
|
76
|
+
|
|
64
77
|
exports.PagarmePaymentStatus = void 0;
|
|
65
78
|
(function (PagarmePaymentStatus) {
|
|
66
79
|
PagarmePaymentStatus["Em processamento"] = "processing";
|
|
@@ -73,6 +86,33 @@ exports.PagarmePaymentStatus = void 0;
|
|
|
73
86
|
PagarmePaymentStatus["Chargedback"] = "chargedback";
|
|
74
87
|
})(exports.PagarmePaymentStatus || (exports.PagarmePaymentStatus = {}));
|
|
75
88
|
|
|
89
|
+
exports.PagarMeV5PaymentStatus = void 0;
|
|
90
|
+
(function (PagarMeV5PaymentStatus) {
|
|
91
|
+
PagarMeV5PaymentStatus["Em processamento"] = "processing";
|
|
92
|
+
PagarMeV5PaymentStatus["Gerado"] = "generated";
|
|
93
|
+
PagarMeV5PaymentStatus["Visualizado"] = "viewed";
|
|
94
|
+
PagarMeV5PaymentStatus["Pago a menor"] = "underpaid";
|
|
95
|
+
PagarMeV5PaymentStatus["Pago a maior"] = "overpaid";
|
|
96
|
+
PagarMeV5PaymentStatus["Aguardando pagamento"] = "waiting_payment";
|
|
97
|
+
PagarMeV5PaymentStatus["Pago"] = "paid";
|
|
98
|
+
PagarMeV5PaymentStatus["Aguardando estorno"] = "pending_refund";
|
|
99
|
+
PagarMeV5PaymentStatus["Autorizada pendente de captura"] = "authorized_pending_capture";
|
|
100
|
+
PagarMeV5PaymentStatus["N\u00E3o autorizada"] = "not_authorized";
|
|
101
|
+
PagarMeV5PaymentStatus["Capturada"] = "captured";
|
|
102
|
+
PagarMeV5PaymentStatus["Aguardando captura"] = "waiting_capture";
|
|
103
|
+
PagarMeV5PaymentStatus["Com erro"] = "with_error";
|
|
104
|
+
PagarMeV5PaymentStatus["Estornado"] = "refunded";
|
|
105
|
+
PagarMeV5PaymentStatus["Cancelado"] = "voided";
|
|
106
|
+
PagarMeV5PaymentStatus["Falha"] = "failed";
|
|
107
|
+
})(exports.PagarMeV5PaymentStatus || (exports.PagarMeV5PaymentStatus = {}));
|
|
108
|
+
exports.PagarMeV5OrderStatus = void 0;
|
|
109
|
+
(function (PagarMeV5OrderStatus) {
|
|
110
|
+
PagarMeV5OrderStatus["Pendente"] = "pending";
|
|
111
|
+
PagarMeV5OrderStatus["Pago"] = "paid";
|
|
112
|
+
PagarMeV5OrderStatus["Cancelado"] = "canceled";
|
|
113
|
+
PagarMeV5OrderStatus["Falha"] = "failed";
|
|
114
|
+
})(exports.PagarMeV5OrderStatus || (exports.PagarMeV5OrderStatus = {}));
|
|
115
|
+
|
|
76
116
|
exports.PaymentMethods = void 0;
|
|
77
117
|
(function (PaymentMethods) {
|
|
78
118
|
PaymentMethods["CARD"] = "card";
|
|
@@ -86,8 +126,16 @@ exports.PaymentProviders = void 0;
|
|
|
86
126
|
PaymentProviders["PAGARME"] = "pagarMe";
|
|
87
127
|
PaymentProviders["ADYEN"] = "adyen";
|
|
88
128
|
PaymentProviders["GLAMPOINTS"] = "glampoints";
|
|
129
|
+
PaymentProviders["MERCADOPAGO"] = "mercadoPago";
|
|
89
130
|
})(exports.PaymentProviders || (exports.PaymentProviders = {}));
|
|
90
131
|
|
|
132
|
+
exports.TransactionPaymentMethods = void 0;
|
|
133
|
+
(function (TransactionPaymentMethods) {
|
|
134
|
+
TransactionPaymentMethods["CARD"] = "credit_card";
|
|
135
|
+
TransactionPaymentMethods["BANKSLIP"] = "boleto";
|
|
136
|
+
TransactionPaymentMethods["PIX"] = "pix";
|
|
137
|
+
})(exports.TransactionPaymentMethods || (exports.TransactionPaymentMethods = {}));
|
|
138
|
+
|
|
91
139
|
class BasePaymentMethodFactory {
|
|
92
140
|
constructor(methods) {
|
|
93
141
|
this.methods = methods;
|
|
@@ -112,6 +160,9 @@ class AntifraudProviderFactory {
|
|
|
112
160
|
class GlampointsPaymentMethodFactory extends BasePaymentMethodFactory {
|
|
113
161
|
}
|
|
114
162
|
|
|
163
|
+
class MercadoPagoPaymentMethodFactory extends BasePaymentMethodFactory {
|
|
164
|
+
}
|
|
165
|
+
|
|
115
166
|
class PagarmePaymentMethodFactory extends BasePaymentMethodFactory {
|
|
116
167
|
}
|
|
117
168
|
|
|
@@ -664,6 +715,8 @@ exports.Shops = void 0;
|
|
|
664
715
|
Shops["MENSMARKET"] = "mensmarket";
|
|
665
716
|
Shops["GLAMSHOP"] = "Glamshop";
|
|
666
717
|
Shops["GLAMPOINTS"] = "Glampoints";
|
|
718
|
+
Shops["GLAMBEAUTY"] = "Glambeauty";
|
|
719
|
+
Shops["ELLA"] = "ella";
|
|
667
720
|
Shops["ALL"] = "ALL";
|
|
668
721
|
})(exports.Shops || (exports.Shops = {}));
|
|
669
722
|
|
|
@@ -698,12 +751,36 @@ class Category extends BaseModel {
|
|
|
698
751
|
image: null,
|
|
699
752
|
};
|
|
700
753
|
}
|
|
754
|
+
get glamBeautyImages() {
|
|
755
|
+
return this.images?.[exports.Shops.GLAMBEAUTY]
|
|
756
|
+
? this.images[exports.Shops.GLAMBEAUTY]
|
|
757
|
+
: {
|
|
758
|
+
brandBanner: null,
|
|
759
|
+
brandBannerMobile: null,
|
|
760
|
+
image: null,
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
get ellaImages() {
|
|
764
|
+
return this.images?.[exports.Shops.ELLA]
|
|
765
|
+
? this.images[exports.Shops.ELLA]
|
|
766
|
+
: {
|
|
767
|
+
brandBanner: null,
|
|
768
|
+
brandBannerMobile: null,
|
|
769
|
+
image: null,
|
|
770
|
+
};
|
|
771
|
+
}
|
|
701
772
|
get glamMetadata() {
|
|
702
773
|
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.GLAMSHOP);
|
|
703
774
|
}
|
|
704
775
|
get mensMetadata() {
|
|
705
776
|
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.MENSMARKET);
|
|
706
777
|
}
|
|
778
|
+
get glamBeautyMetadata() {
|
|
779
|
+
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.GLAMBEAUTY);
|
|
780
|
+
}
|
|
781
|
+
get ellaMetadata() {
|
|
782
|
+
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.ELLA);
|
|
783
|
+
}
|
|
707
784
|
getMostRelevantByShop(shop) {
|
|
708
785
|
return this.mostRelevants?.[shop] || [];
|
|
709
786
|
}
|
|
@@ -722,6 +799,30 @@ tslib.__decorate([
|
|
|
722
799
|
], Category.prototype, "filters", void 0);
|
|
723
800
|
registerClass('Category', Category);
|
|
724
801
|
|
|
802
|
+
class BrandCategory extends BaseModel {
|
|
803
|
+
get glamImages() {
|
|
804
|
+
return this.images?.[exports.Shops.GLAMSHOP]
|
|
805
|
+
? this.images[exports.Shops.GLAMSHOP]
|
|
806
|
+
: {
|
|
807
|
+
brandBanner: null,
|
|
808
|
+
brandBannerMobile: null,
|
|
809
|
+
image: null,
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
get mensImages() {
|
|
813
|
+
return this.images?.[exports.Shops.MENSMARKET]
|
|
814
|
+
? this.images[exports.Shops.MENSMARKET]
|
|
815
|
+
: {
|
|
816
|
+
brandBanner: null,
|
|
817
|
+
brandBannerMobile: null,
|
|
818
|
+
image: null,
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
static get identifiersFields() {
|
|
822
|
+
return ['id'];
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
725
826
|
class CategoryCollectionChildren extends BaseModel {
|
|
726
827
|
static get identifiersFields() {
|
|
727
828
|
return ['collectionId', 'categoryId'];
|
|
@@ -795,6 +896,11 @@ class ProductReview extends BaseModel {
|
|
|
795
896
|
return ['id'];
|
|
796
897
|
}
|
|
797
898
|
}
|
|
899
|
+
tslib.__decorate([
|
|
900
|
+
classTransformer.Type(resolveClass('Product')),
|
|
901
|
+
tslib.__metadata("design:type", Function)
|
|
902
|
+
], ProductReview.prototype, "product", void 0);
|
|
903
|
+
registerClass('ProductReview', ProductReview);
|
|
798
904
|
|
|
799
905
|
class ProductBase extends BaseModel {
|
|
800
906
|
get evaluation() {
|
|
@@ -859,28 +965,6 @@ tslib.__decorate([
|
|
|
859
965
|
tslib.__metadata("design:type", Object)
|
|
860
966
|
], ProductErrors.prototype, "product", void 0);
|
|
861
967
|
|
|
862
|
-
class ProductStockNotification extends BaseModel {
|
|
863
|
-
static get identifiersFields() {
|
|
864
|
-
return ['id'];
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
class Wishlist extends Category {
|
|
869
|
-
static get identifiersFields() {
|
|
870
|
-
return ['id'];
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
class Buy2Win extends BaseModel {
|
|
875
|
-
static get identifiersFields() {
|
|
876
|
-
return ['id'];
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
tslib.__decorate([
|
|
880
|
-
classTransformer.Type(() => Category),
|
|
881
|
-
tslib.__metadata("design:type", Array)
|
|
882
|
-
], Buy2Win.prototype, "categories", void 0);
|
|
883
|
-
|
|
884
968
|
exports.Where = void 0;
|
|
885
969
|
(function (Where) {
|
|
886
970
|
Where["EQUALS"] = "==";
|
|
@@ -907,6 +991,46 @@ exports.UpdateOptionActions = void 0;
|
|
|
907
991
|
UpdateOptionActions["NULL"] = "null";
|
|
908
992
|
})(exports.UpdateOptionActions || (exports.UpdateOptionActions = {}));
|
|
909
993
|
|
|
994
|
+
class ProductGroup extends BaseModel {
|
|
995
|
+
static get identifiersFields() {
|
|
996
|
+
return ['id'];
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
class ProductPriceLog extends BaseModel {
|
|
1001
|
+
static get identifiersFields() {
|
|
1002
|
+
return ['id'];
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
class ProductStockEntry extends BaseModel {
|
|
1007
|
+
static get identifiersFields() {
|
|
1008
|
+
return ['id'];
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
class ProductStockNotification extends BaseModel {
|
|
1013
|
+
static get identifiersFields() {
|
|
1014
|
+
return ['id'];
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
class Wishlist extends Category {
|
|
1019
|
+
static get identifiersFields() {
|
|
1020
|
+
return ['id'];
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
class Buy2Win extends BaseModel {
|
|
1025
|
+
static get identifiersFields() {
|
|
1026
|
+
return ['id'];
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
tslib.__decorate([
|
|
1030
|
+
classTransformer.Type(() => Category),
|
|
1031
|
+
tslib.__metadata("design:type", Array)
|
|
1032
|
+
], Buy2Win.prototype, "categories", void 0);
|
|
1033
|
+
|
|
910
1034
|
class CampaignDashboard extends BaseModel {
|
|
911
1035
|
static get identifiersFields() {
|
|
912
1036
|
return ['id'];
|
|
@@ -1593,8 +1717,38 @@ exports.OrderStatus = void 0;
|
|
|
1593
1717
|
OrderStatus["ENTREGUE"] = "Entregue";
|
|
1594
1718
|
OrderStatus["CANCELADO"] = "Cancelado";
|
|
1595
1719
|
OrderStatus["PENDENTE_REENVIO"] = "Pendente reenvio";
|
|
1720
|
+
OrderStatus["AGUARDANDO_STOCK_REENVIO"] = "Aguardando stock para reenvio";
|
|
1596
1721
|
})(exports.OrderStatus || (exports.OrderStatus = {}));
|
|
1597
1722
|
|
|
1723
|
+
exports.ShoppingRecurrenceCycle = void 0;
|
|
1724
|
+
(function (ShoppingRecurrenceCycle) {
|
|
1725
|
+
ShoppingRecurrenceCycle[ShoppingRecurrenceCycle["MONTHLY"] = 1] = "MONTHLY";
|
|
1726
|
+
ShoppingRecurrenceCycle[ShoppingRecurrenceCycle["BIMONTHLY"] = 2] = "BIMONTHLY";
|
|
1727
|
+
ShoppingRecurrenceCycle[ShoppingRecurrenceCycle["QUARTERLY"] = 3] = "QUARTERLY";
|
|
1728
|
+
})(exports.ShoppingRecurrenceCycle || (exports.ShoppingRecurrenceCycle = {}));
|
|
1729
|
+
|
|
1730
|
+
exports.ShoppingRecurrenceEditionStatus = void 0;
|
|
1731
|
+
(function (ShoppingRecurrenceEditionStatus) {
|
|
1732
|
+
ShoppingRecurrenceEditionStatus["SCHEDULED"] = "scheduled";
|
|
1733
|
+
ShoppingRecurrenceEditionStatus["PAUSED"] = "paused";
|
|
1734
|
+
ShoppingRecurrenceEditionStatus["SKIPPED"] = "skipped";
|
|
1735
|
+
ShoppingRecurrenceEditionStatus["PROCESSING"] = "processing";
|
|
1736
|
+
ShoppingRecurrenceEditionStatus["FINISHED"] = "finished";
|
|
1737
|
+
ShoppingRecurrenceEditionStatus["PAYMENT_FAIL"] = "payment_fail";
|
|
1738
|
+
ShoppingRecurrenceEditionStatus["AWAITING_PAYMENT"] = "awaiting_payment";
|
|
1739
|
+
ShoppingRecurrenceEditionStatus["STOCK_VALIDATION"] = "stock_validation";
|
|
1740
|
+
ShoppingRecurrenceEditionStatus["CANCELLED"] = "cancelled";
|
|
1741
|
+
})(exports.ShoppingRecurrenceEditionStatus || (exports.ShoppingRecurrenceEditionStatus = {}));
|
|
1742
|
+
|
|
1743
|
+
exports.ShoppingRecurrenceStatus = void 0;
|
|
1744
|
+
(function (ShoppingRecurrenceStatus) {
|
|
1745
|
+
ShoppingRecurrenceStatus["ACTIVE"] = "active";
|
|
1746
|
+
ShoppingRecurrenceStatus["PAUSED"] = "paused";
|
|
1747
|
+
ShoppingRecurrenceStatus["CANCELLED"] = "cancelled";
|
|
1748
|
+
ShoppingRecurrenceStatus["PAYMENT_FAILED"] = "payment_failed";
|
|
1749
|
+
ShoppingRecurrenceStatus["WAITING_STOCK"] = "waiting_stock";
|
|
1750
|
+
})(exports.ShoppingRecurrenceStatus || (exports.ShoppingRecurrenceStatus = {}));
|
|
1751
|
+
|
|
1598
1752
|
class Order extends Checkout {
|
|
1599
1753
|
}
|
|
1600
1754
|
tslib.__decorate([
|
|
@@ -1608,6 +1762,44 @@ class OrderBlocked extends BaseModel {
|
|
|
1608
1762
|
}
|
|
1609
1763
|
}
|
|
1610
1764
|
|
|
1765
|
+
class ShoppingRecurrence extends BaseModel {
|
|
1766
|
+
static get identifiersFields() {
|
|
1767
|
+
return ['id'];
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
tslib.__decorate([
|
|
1771
|
+
classTransformer.Type(() => User),
|
|
1772
|
+
tslib.__metadata("design:type", User)
|
|
1773
|
+
], ShoppingRecurrence.prototype, "user", void 0);
|
|
1774
|
+
tslib.__decorate([
|
|
1775
|
+
classTransformer.Type(() => UserAddress),
|
|
1776
|
+
tslib.__metadata("design:type", UserAddress)
|
|
1777
|
+
], ShoppingRecurrence.prototype, "shippingAddress", void 0);
|
|
1778
|
+
tslib.__decorate([
|
|
1779
|
+
classTransformer.Type(() => UserAddress),
|
|
1780
|
+
tslib.__metadata("design:type", UserAddress)
|
|
1781
|
+
], ShoppingRecurrence.prototype, "billingAddress", void 0);
|
|
1782
|
+
tslib.__decorate([
|
|
1783
|
+
classTransformer.Type(() => ShippingMethod),
|
|
1784
|
+
tslib.__metadata("design:type", ShippingMethod)
|
|
1785
|
+
], ShoppingRecurrence.prototype, "shipping", void 0);
|
|
1786
|
+
tslib.__decorate([
|
|
1787
|
+
classTransformer.Type(() => Coupon),
|
|
1788
|
+
tslib.__metadata("design:type", Coupon)
|
|
1789
|
+
], ShoppingRecurrence.prototype, "coupon", void 0);
|
|
1790
|
+
|
|
1791
|
+
class ShoppingRecurrenceEdition extends BaseModel {
|
|
1792
|
+
static get identifiersFields() {
|
|
1793
|
+
return ['id'];
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
class ShoppingRecurrenceErrorLog extends BaseModel {
|
|
1798
|
+
static get identifiersFields() {
|
|
1799
|
+
return ['id'];
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1611
1803
|
class CheckoutSubscription extends BaseModel {
|
|
1612
1804
|
static get identifiersFields() {
|
|
1613
1805
|
return ['id'];
|
|
@@ -1630,11 +1822,27 @@ tslib.__decorate([
|
|
|
1630
1822
|
tslib.__metadata("design:type", Coupon)
|
|
1631
1823
|
], CheckoutSubscription.prototype, "coupon", void 0);
|
|
1632
1824
|
|
|
1825
|
+
exports.ErrorsCode = void 0;
|
|
1826
|
+
(function (ErrorsCode) {
|
|
1827
|
+
ErrorsCode["genericError"] = "generic-error";
|
|
1828
|
+
ErrorsCode["businessError"] = "business-error";
|
|
1829
|
+
ErrorsCode["invalidCheckoutError"] = "invalid-checkout";
|
|
1830
|
+
ErrorsCode["stockLimit"] = "stock-limit";
|
|
1831
|
+
ErrorsCode["stockOut"] = "stock-out";
|
|
1832
|
+
ErrorsCode["notFound"] = "not-found";
|
|
1833
|
+
ErrorsCode["fraudPreventionInternal"] = "fraud-prevention-internal";
|
|
1834
|
+
ErrorsCode["fraudPreventionExternal"] = "fraud-prevention-external";
|
|
1835
|
+
ErrorsCode["invalidCardError"] = "invalid-card-error";
|
|
1836
|
+
ErrorsCode["insufficientFundsError"] = "insufficient-funds-error";
|
|
1837
|
+
ErrorsCode["paymentNotAuthorizedError"] = "payment-not-authorized-error";
|
|
1838
|
+
ErrorsCode["paymentError"] = "payment-error";
|
|
1839
|
+
})(exports.ErrorsCode || (exports.ErrorsCode = {}));
|
|
1840
|
+
|
|
1633
1841
|
class BusinessError extends tsCustomError.CustomError {
|
|
1634
|
-
constructor(message, additionalData, type
|
|
1842
|
+
constructor(message, additionalData, type) {
|
|
1635
1843
|
super(message);
|
|
1636
1844
|
this.additionalData = additionalData;
|
|
1637
|
-
this.type = type;
|
|
1845
|
+
this.type = type || exports.ErrorsCode.businessError;
|
|
1638
1846
|
}
|
|
1639
1847
|
}
|
|
1640
1848
|
|
|
@@ -1645,10 +1853,10 @@ class DuplicatedResultsError extends tsCustomError.CustomError {
|
|
|
1645
1853
|
}
|
|
1646
1854
|
|
|
1647
1855
|
class FraudValidationError extends tsCustomError.CustomError {
|
|
1648
|
-
constructor(message, additionalData) {
|
|
1856
|
+
constructor(message, type, additionalData) {
|
|
1649
1857
|
super(message);
|
|
1650
1858
|
this.additionalData = additionalData;
|
|
1651
|
-
this.type =
|
|
1859
|
+
this.type = type;
|
|
1652
1860
|
}
|
|
1653
1861
|
}
|
|
1654
1862
|
|
|
@@ -1658,17 +1866,26 @@ class InvalidArgumentError extends tsCustomError.CustomError {
|
|
|
1658
1866
|
}
|
|
1659
1867
|
}
|
|
1660
1868
|
|
|
1869
|
+
class InvalidCheckoutError extends tsCustomError.CustomError {
|
|
1870
|
+
constructor(message, additionalData) {
|
|
1871
|
+
super(message);
|
|
1872
|
+
this.additionalData = additionalData;
|
|
1873
|
+
this.type = exports.ErrorsCode.invalidCheckoutError;
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1661
1877
|
class NotFoundError extends tsCustomError.CustomError {
|
|
1662
1878
|
constructor(message) {
|
|
1663
1879
|
super(message);
|
|
1880
|
+
this.type = exports.ErrorsCode.notFound;
|
|
1664
1881
|
}
|
|
1665
1882
|
}
|
|
1666
1883
|
|
|
1667
1884
|
class PaymentError extends tsCustomError.CustomError {
|
|
1668
|
-
constructor(message, additionalData) {
|
|
1885
|
+
constructor(message, type, additionalData) {
|
|
1669
1886
|
super(message);
|
|
1670
1887
|
this.additionalData = additionalData;
|
|
1671
|
-
this.type =
|
|
1888
|
+
this.type = type;
|
|
1672
1889
|
}
|
|
1673
1890
|
}
|
|
1674
1891
|
|
|
@@ -1683,14 +1900,14 @@ class RequiredArgumentError extends tsCustomError.CustomError {
|
|
|
1683
1900
|
class StockLimitError extends BusinessError {
|
|
1684
1901
|
constructor(message, additionalData) {
|
|
1685
1902
|
super(message, additionalData);
|
|
1686
|
-
this.type =
|
|
1903
|
+
this.type = exports.ErrorsCode.stockLimit;
|
|
1687
1904
|
}
|
|
1688
1905
|
}
|
|
1689
1906
|
|
|
1690
1907
|
class StockOutError extends BusinessError {
|
|
1691
1908
|
constructor(message, additionalData) {
|
|
1692
1909
|
super(message, additionalData);
|
|
1693
|
-
this.type =
|
|
1910
|
+
this.type = exports.ErrorsCode.stockOut;
|
|
1694
1911
|
}
|
|
1695
1912
|
}
|
|
1696
1913
|
|
|
@@ -1707,7 +1924,7 @@ class AntifraudBankSlipService {
|
|
|
1707
1924
|
type: 'Boleto',
|
|
1708
1925
|
limiteRange: 'day',
|
|
1709
1926
|
});
|
|
1710
|
-
throw new FraudValidationError('Boleto não autorizado para cliente não assinante', {
|
|
1927
|
+
throw new FraudValidationError('Boleto não autorizado para cliente não assinante', exports.ErrorsCode.fraudPreventionInternal, {
|
|
1711
1928
|
checkoutId: checkout.id,
|
|
1712
1929
|
userEmail: checkout.user.email,
|
|
1713
1930
|
info: {
|
|
@@ -1725,19 +1942,58 @@ class AntifraudCardService {
|
|
|
1725
1942
|
constructor(orderRepository, orderBlockedRepository) {
|
|
1726
1943
|
this.orderRepository = orderRepository;
|
|
1727
1944
|
this.orderBlockedRepository = orderBlockedRepository;
|
|
1728
|
-
this.LIMIT_ORDERS_DAY =
|
|
1729
|
-
this.LIMIT_ORDERS_WEEK =
|
|
1730
|
-
this.LIMIT_BLOCKED_ORDERS_DAY = 5;
|
|
1945
|
+
this.LIMIT_ORDERS_DAY = null;
|
|
1946
|
+
this.LIMIT_ORDERS_WEEK = null;
|
|
1731
1947
|
}
|
|
1732
1948
|
async validate(checkout, card) {
|
|
1949
|
+
this.setLimitsByUserType(checkout.user.isSubscriber);
|
|
1733
1950
|
await this.validateBlockedOrderAttempts(checkout, card);
|
|
1734
1951
|
await this.validateDayAndWeekOrderLimits(checkout, card);
|
|
1735
1952
|
return true;
|
|
1736
1953
|
}
|
|
1954
|
+
setLimitsByUserType(isSubscriber) {
|
|
1955
|
+
this.LIMIT_ORDERS_DAY = {
|
|
1956
|
+
subscriber: {
|
|
1957
|
+
cpf: 4,
|
|
1958
|
+
email: 4,
|
|
1959
|
+
phone: 4,
|
|
1960
|
+
card: 4,
|
|
1961
|
+
zip: 4,
|
|
1962
|
+
},
|
|
1963
|
+
nonSubscriber: {
|
|
1964
|
+
cpf: 2,
|
|
1965
|
+
email: 2,
|
|
1966
|
+
phone: 2,
|
|
1967
|
+
card: 2,
|
|
1968
|
+
zip: 2,
|
|
1969
|
+
},
|
|
1970
|
+
};
|
|
1971
|
+
this.LIMIT_ORDERS_WEEK = {
|
|
1972
|
+
subscriber: {
|
|
1973
|
+
cpf: 12,
|
|
1974
|
+
email: 12,
|
|
1975
|
+
phone: 12,
|
|
1976
|
+
card: 12,
|
|
1977
|
+
zip: Infinity,
|
|
1978
|
+
},
|
|
1979
|
+
nonSubscriber: {
|
|
1980
|
+
cpf: 7,
|
|
1981
|
+
email: 7,
|
|
1982
|
+
phone: 7,
|
|
1983
|
+
card: 7,
|
|
1984
|
+
zip: Infinity,
|
|
1985
|
+
},
|
|
1986
|
+
};
|
|
1987
|
+
this.LIMIT_BLOCKED_ORDERS_DAY = isSubscriber ? 7 : 5;
|
|
1988
|
+
}
|
|
1989
|
+
getLimitsByUserType(type, isSubscriber) {
|
|
1990
|
+
const limits = type === 'day' ? this.LIMIT_ORDERS_DAY : this.LIMIT_ORDERS_WEEK;
|
|
1991
|
+
return isSubscriber ? limits['subscriber'] : limits['nonSubscriber'];
|
|
1992
|
+
}
|
|
1737
1993
|
async validateBlockedOrderAttempts(checkout, card) {
|
|
1738
1994
|
const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
|
|
1739
1995
|
if (!isValid) {
|
|
1740
|
-
throw new FraudValidationError(
|
|
1996
|
+
throw new FraudValidationError(`Cliente com mais de ${this.LIMIT_BLOCKED_ORDERS_DAY} compras negadas/bloqueadas no dia`, exports.ErrorsCode.fraudPreventionInternal, {
|
|
1741
1997
|
checkoutId: checkout.id,
|
|
1742
1998
|
userEmail: checkout.user.email,
|
|
1743
1999
|
info: {
|
|
@@ -1751,7 +2007,7 @@ class AntifraudCardService {
|
|
|
1751
2007
|
async validateDayAndWeekOrderLimits(checkout, card) {
|
|
1752
2008
|
const isValid = await this.verifyDayAndWeekOrders(checkout, card);
|
|
1753
2009
|
if (!isValid) {
|
|
1754
|
-
throw new FraudValidationError('Cliente tentando comprar mais
|
|
2010
|
+
throw new FraudValidationError('Cliente tentando comprar mais do que o permitido no dia/semana', exports.ErrorsCode.fraudPreventionInternal, {
|
|
1755
2011
|
checkoutId: checkout.id,
|
|
1756
2012
|
userEmail: checkout.user.email,
|
|
1757
2013
|
info: {
|
|
@@ -1770,7 +2026,7 @@ class AntifraudCardService {
|
|
|
1770
2026
|
await this.createBlockedOrderRecord({
|
|
1771
2027
|
checkout,
|
|
1772
2028
|
card,
|
|
1773
|
-
reason:
|
|
2029
|
+
reason: `More than ${this.LIMIT_BLOCKED_ORDERS_DAY} attempts have failed`,
|
|
1774
2030
|
key: 'Failed attempts',
|
|
1775
2031
|
period: 'day',
|
|
1776
2032
|
});
|
|
@@ -1779,15 +2035,17 @@ class AntifraudCardService {
|
|
|
1779
2035
|
return true;
|
|
1780
2036
|
}
|
|
1781
2037
|
getTodayDateRange() {
|
|
1782
|
-
const
|
|
1783
|
-
const
|
|
1784
|
-
|
|
2038
|
+
const timeZone = 'America/Sao_Paulo';
|
|
2039
|
+
const today = dateFnsTz.utcToZonedTime(new Date(), timeZone);
|
|
2040
|
+
const day = dateFns.startOfDay(today);
|
|
2041
|
+
const endOfDay = dateFns.endOfDay(today);
|
|
2042
|
+
return { day: dateFns.addHours(day, 3), endOfDay: dateFns.addHours(endOfDay, 3) };
|
|
1785
2043
|
}
|
|
1786
2044
|
async getBlockedOrdersByMultipleCriteria(checkout, dateRange) {
|
|
1787
2045
|
const { day, endOfDay } = dateRange;
|
|
1788
2046
|
const dateFilter = [
|
|
1789
|
-
{ operator: exports.Where.GTE, value:
|
|
1790
|
-
{ operator: exports.Where.LTE, value:
|
|
2047
|
+
{ operator: exports.Where.GTE, value: day },
|
|
2048
|
+
{ operator: exports.Where.LTE, value: endOfDay },
|
|
1791
2049
|
];
|
|
1792
2050
|
const [ordersBlockedWithCpf, ordersBlockedWithEmail, ordersBlockedWithCep, ordersBlockedWithPhone] = await Promise.all([
|
|
1793
2051
|
this.getBlockedOrdersByCpf(checkout.user?.cpf, dateFilter),
|
|
@@ -1889,26 +2147,28 @@ class AntifraudCardService {
|
|
|
1889
2147
|
}
|
|
1890
2148
|
async validateDayOrderLimits(checkout, params) {
|
|
1891
2149
|
const ordersPerDay = await this.validateOrdersByRange(params, this.getDateRange('day'));
|
|
2150
|
+
const limits = this.getLimitsByUserType('day', checkout.user.isSubscriber);
|
|
1892
2151
|
return this.checkOrderLimitsAndBlock({
|
|
1893
2152
|
checkout,
|
|
1894
2153
|
orderCounts: ordersPerDay,
|
|
1895
|
-
limit:
|
|
2154
|
+
limit: limits,
|
|
1896
2155
|
period: 'day',
|
|
1897
2156
|
});
|
|
1898
2157
|
}
|
|
1899
2158
|
async validateWeekOrderLimits(checkout, params) {
|
|
1900
2159
|
const ordersPerWeek = await this.validateOrdersByRange(params, this.getDateRange('week'));
|
|
2160
|
+
const limits = this.getLimitsByUserType('week', checkout.user.isSubscriber);
|
|
1901
2161
|
return this.checkOrderLimitsAndBlock({
|
|
1902
2162
|
checkout,
|
|
1903
2163
|
orderCounts: ordersPerWeek,
|
|
1904
|
-
limit:
|
|
2164
|
+
limit: limits,
|
|
1905
2165
|
period: 'week',
|
|
1906
2166
|
});
|
|
1907
2167
|
}
|
|
1908
2168
|
async checkOrderLimitsAndBlock(params) {
|
|
1909
2169
|
const { checkout, orderCounts, limit, period } = params;
|
|
1910
2170
|
for (const key in orderCounts) {
|
|
1911
|
-
if (orderCounts[key] >= limit) {
|
|
2171
|
+
if (orderCounts[key] >= limit[key]) {
|
|
1912
2172
|
await this.createBlockedOrderRecord({
|
|
1913
2173
|
checkout,
|
|
1914
2174
|
card: null,
|
|
@@ -2174,6 +2434,7 @@ exports.ShopPageName = void 0;
|
|
|
2174
2434
|
ShopPageName["LP_GLAMQUEENS"] = "LP_GLAMQUEENS";
|
|
2175
2435
|
ShopPageName["LP_INVITE"] = "LP_INVITE";
|
|
2176
2436
|
ShopPageName["LP_LIVELO"] = "LP_LIVELO";
|
|
2437
|
+
ShopPageName["GLAM_NEW_HOME"] = "GLAM_NEW_HOME";
|
|
2177
2438
|
})(exports.ShopPageName || (exports.ShopPageName = {}));
|
|
2178
2439
|
|
|
2179
2440
|
class BeautyQuestionsHelper {
|
|
@@ -2239,16 +2500,100 @@ class Home extends BaseModel {
|
|
|
2239
2500
|
}
|
|
2240
2501
|
}
|
|
2241
2502
|
|
|
2503
|
+
class ShopConfigs extends BaseModel {
|
|
2504
|
+
static get identifiersFields() {
|
|
2505
|
+
return ['id'];
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2242
2509
|
class ShopMenu extends BaseModel {
|
|
2243
2510
|
static get identifiersFields() {
|
|
2244
2511
|
return ['id'];
|
|
2245
2512
|
}
|
|
2246
2513
|
}
|
|
2247
2514
|
|
|
2515
|
+
var ShopPageSectionType;
|
|
2516
|
+
(function (ShopPageSectionType) {
|
|
2517
|
+
ShopPageSectionType["LIVE"] = "LIVE";
|
|
2518
|
+
ShopPageSectionType["CAROUSEL"] = "CAROUSEL";
|
|
2519
|
+
ShopPageSectionType["BANNER"] = "BANNER";
|
|
2520
|
+
ShopPageSectionType["INFOBARS"] = "INFOBARS";
|
|
2521
|
+
ShopPageSectionType["HIGHLIGHTS"] = "HIGHLIGHTS";
|
|
2522
|
+
ShopPageSectionType["SUBSCRIBER_INFO"] = "SUBSCRIBER_INFO";
|
|
2523
|
+
ShopPageSectionType["COLLECTION"] = "COLLECTION";
|
|
2524
|
+
ShopPageSectionType["BEAUTY_PROFILE_COLLECTION"] = "BEAUTY_PROFILE_COLLECTION";
|
|
2525
|
+
ShopPageSectionType["PLANS"] = "PLANS";
|
|
2526
|
+
ShopPageSectionType["SINGLE_PLAN"] = "SINGLE_PLAN";
|
|
2527
|
+
ShopPageSectionType["BRANDS"] = "BRANDS";
|
|
2528
|
+
ShopPageSectionType["NEWSLETTER"] = "NEWSLETTER";
|
|
2529
|
+
})(ShopPageSectionType || (ShopPageSectionType = {}));
|
|
2530
|
+
|
|
2531
|
+
/* eslint-disable max-lines-per-function */
|
|
2248
2532
|
class ShopSettings extends BaseModel {
|
|
2249
2533
|
static get identifiersFields() {
|
|
2250
2534
|
return ['id'];
|
|
2251
2535
|
}
|
|
2536
|
+
getPageSections(displayRules) {
|
|
2537
|
+
const now = new Date();
|
|
2538
|
+
return (Array.isArray(this.sections) ? this.sections : [])
|
|
2539
|
+
.map((section) => {
|
|
2540
|
+
// Filtra banners dentro de carrousel
|
|
2541
|
+
if (section.type === ShopPageSectionType.CAROUSEL && Array.isArray(section.banners)) {
|
|
2542
|
+
const filteredBanners = section.banners.filter((banner) => {
|
|
2543
|
+
// Filtra por displayRules
|
|
2544
|
+
const rulesMatch = banner.displayRules.length
|
|
2545
|
+
? banner.displayRules.some((rule) => Object.keys(rule).every((key) => rule[key] === displayRules[key]))
|
|
2546
|
+
: true;
|
|
2547
|
+
// Filtra por publishDate e expirationDate
|
|
2548
|
+
const publishOk = !banner.publishDate || now >= new Date(banner.publishDate);
|
|
2549
|
+
const expireOk = !banner.expirationDate || now <= new Date(banner.expirationDate);
|
|
2550
|
+
return rulesMatch && publishOk && expireOk;
|
|
2551
|
+
});
|
|
2552
|
+
return { ...section, banners: filteredBanners };
|
|
2553
|
+
}
|
|
2554
|
+
// Filtra highlights
|
|
2555
|
+
if (section.type === ShopPageSectionType.HIGHLIGHTS && Array.isArray(section.highlights)) {
|
|
2556
|
+
const filteredHighlights = section.highlights.filter((highlight) => {
|
|
2557
|
+
// Filtra por displayRules
|
|
2558
|
+
const rulesMatch = highlight.displayRules.length
|
|
2559
|
+
? highlight.displayRules.some((rule) => Object.keys(rule).every((key) => rule[key] === displayRules[key]))
|
|
2560
|
+
: true;
|
|
2561
|
+
return rulesMatch;
|
|
2562
|
+
});
|
|
2563
|
+
const sortedHighlights = !displayRules.beautyProfile
|
|
2564
|
+
? filteredHighlights.sort((a, b) => (a.starred === b.starred ? 0 : a.starred ? -1 : 1))
|
|
2565
|
+
: filteredHighlights;
|
|
2566
|
+
return { ...section, highlights: sortedHighlights };
|
|
2567
|
+
}
|
|
2568
|
+
// Filtra collections
|
|
2569
|
+
if (section.type === ShopPageSectionType.COLLECTION) {
|
|
2570
|
+
const rulesMatch = section.displayRules.length
|
|
2571
|
+
? section.displayRules.some((rule) => Object.keys(rule).every((key) => rule[key] === displayRules[key]))
|
|
2572
|
+
: true;
|
|
2573
|
+
const publishOk = !section.publishDate || now >= new Date(section.publishDate);
|
|
2574
|
+
const expireOk = !section.expirationDate || now <= new Date(section.expirationDate);
|
|
2575
|
+
return rulesMatch && publishOk && expireOk ? section : null;
|
|
2576
|
+
}
|
|
2577
|
+
// Filtra banners
|
|
2578
|
+
if (section.type === ShopPageSectionType.BANNER) {
|
|
2579
|
+
const rulesMatch = section.displayRules.length
|
|
2580
|
+
? section.displayRules.some((rule) => Object.keys(rule).every((key) => rule[key] === displayRules[key]))
|
|
2581
|
+
: true;
|
|
2582
|
+
const publishOk = !section.publishDate || now >= new Date(section.publishDate);
|
|
2583
|
+
const expireOk = !section.expirationDate || now <= new Date(section.expirationDate);
|
|
2584
|
+
return rulesMatch && publishOk && expireOk ? section : null;
|
|
2585
|
+
}
|
|
2586
|
+
if (section.type === ShopPageSectionType.LIVE) {
|
|
2587
|
+
return section.active ? section : null;
|
|
2588
|
+
}
|
|
2589
|
+
if (section.type === ShopPageSectionType.PLANS || section.type === ShopPageSectionType.SINGLE_PLAN) {
|
|
2590
|
+
return displayRules.notSubscriber ? section : null;
|
|
2591
|
+
}
|
|
2592
|
+
// Demais seções retornam normalmente
|
|
2593
|
+
return section;
|
|
2594
|
+
})
|
|
2595
|
+
.filter(Boolean);
|
|
2596
|
+
}
|
|
2252
2597
|
}
|
|
2253
2598
|
|
|
2254
2599
|
class AdyenBlockedOrderHelper {
|
|
@@ -2260,14 +2605,14 @@ class AdyenBlockedOrderHelper {
|
|
|
2260
2605
|
limiteRange: 'day',
|
|
2261
2606
|
card: params.card,
|
|
2262
2607
|
});
|
|
2263
|
-
throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', {
|
|
2608
|
+
throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', exports.ErrorsCode.paymentError, {
|
|
2264
2609
|
checkoutId: params.checkout.id,
|
|
2265
2610
|
userEmail: params.checkout.user.email,
|
|
2266
2611
|
info: params.adyenResponse,
|
|
2267
2612
|
});
|
|
2268
2613
|
}
|
|
2269
2614
|
static createPaymentError(checkout, errorInfo) {
|
|
2270
|
-
return new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', {
|
|
2615
|
+
return new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', exports.ErrorsCode.paymentError, {
|
|
2271
2616
|
checkoutId: checkout.id,
|
|
2272
2617
|
userEmail: checkout.user.email,
|
|
2273
2618
|
info: errorInfo,
|
|
@@ -4726,6 +5071,17 @@ const withCrudFirestore = (MixinBase) => {
|
|
|
4726
5071
|
};
|
|
4727
5072
|
};
|
|
4728
5073
|
|
|
5074
|
+
class BrandCategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5075
|
+
constructor({ firestore, interceptors, }) {
|
|
5076
|
+
super({
|
|
5077
|
+
firestore,
|
|
5078
|
+
collectionName: 'brandsCategory',
|
|
5079
|
+
model: BrandCategory,
|
|
5080
|
+
interceptors,
|
|
5081
|
+
});
|
|
5082
|
+
}
|
|
5083
|
+
}
|
|
5084
|
+
|
|
4729
5085
|
class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4730
5086
|
constructor({ firestore, interceptors }) {
|
|
4731
5087
|
super({
|
|
@@ -4801,6 +5157,9 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
4801
5157
|
isChild(_id, _parentId) {
|
|
4802
5158
|
return;
|
|
4803
5159
|
}
|
|
5160
|
+
async getBrandsWithProducts() {
|
|
5161
|
+
return;
|
|
5162
|
+
}
|
|
4804
5163
|
}
|
|
4805
5164
|
tslib.__decorate([
|
|
4806
5165
|
Log(),
|
|
@@ -5014,6 +5373,18 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
5014
5373
|
}
|
|
5015
5374
|
}
|
|
5016
5375
|
|
|
5376
|
+
class ShopConfigsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5377
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5378
|
+
super({
|
|
5379
|
+
firestore,
|
|
5380
|
+
collectionName: 'shopConfigs',
|
|
5381
|
+
model: ShopConfigs,
|
|
5382
|
+
interceptors,
|
|
5383
|
+
cache,
|
|
5384
|
+
});
|
|
5385
|
+
}
|
|
5386
|
+
}
|
|
5387
|
+
|
|
5017
5388
|
class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5018
5389
|
constructor({ firestore, interceptors, cache, }) {
|
|
5019
5390
|
super({
|
|
@@ -5207,6 +5578,7 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
|
|
|
5207
5578
|
card,
|
|
5208
5579
|
checkout,
|
|
5209
5580
|
date: new Date(),
|
|
5581
|
+
gatewayInfo: params.gatewayInfo || {},
|
|
5210
5582
|
}));
|
|
5211
5583
|
}
|
|
5212
5584
|
formatZip(zip) {
|
|
@@ -5228,6 +5600,74 @@ class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
5228
5600
|
}
|
|
5229
5601
|
}
|
|
5230
5602
|
|
|
5603
|
+
class ShoppingRecurrenceEditionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5604
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5605
|
+
super({
|
|
5606
|
+
firestore,
|
|
5607
|
+
collectionName: 'shoppingRecurrenceEditions',
|
|
5608
|
+
model: ShoppingRecurrenceEdition,
|
|
5609
|
+
interceptors,
|
|
5610
|
+
cache,
|
|
5611
|
+
});
|
|
5612
|
+
}
|
|
5613
|
+
}
|
|
5614
|
+
|
|
5615
|
+
class ShoppingRecurrenceErrorLogFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5616
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5617
|
+
super({
|
|
5618
|
+
firestore,
|
|
5619
|
+
collectionName: 'shoppingRecurrenceErrorLogs',
|
|
5620
|
+
model: ShoppingRecurrenceErrorLog,
|
|
5621
|
+
interceptors,
|
|
5622
|
+
cache,
|
|
5623
|
+
});
|
|
5624
|
+
}
|
|
5625
|
+
}
|
|
5626
|
+
|
|
5627
|
+
class ShoppingRecurrenceFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5628
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
5629
|
+
super({
|
|
5630
|
+
firestore,
|
|
5631
|
+
collectionName: 'shoppingRecurrences',
|
|
5632
|
+
model: ShoppingRecurrence,
|
|
5633
|
+
interceptors,
|
|
5634
|
+
cache,
|
|
5635
|
+
});
|
|
5636
|
+
}
|
|
5637
|
+
async findByUserId(userId) {
|
|
5638
|
+
const result = await this.find({
|
|
5639
|
+
filters: {
|
|
5640
|
+
user: {
|
|
5641
|
+
id: userId,
|
|
5642
|
+
},
|
|
5643
|
+
},
|
|
5644
|
+
});
|
|
5645
|
+
return result.data;
|
|
5646
|
+
}
|
|
5647
|
+
async findByUserIdAndStatus(userId, status) {
|
|
5648
|
+
const result = await this.find({
|
|
5649
|
+
filters: {
|
|
5650
|
+
user: {
|
|
5651
|
+
id: userId,
|
|
5652
|
+
},
|
|
5653
|
+
status,
|
|
5654
|
+
},
|
|
5655
|
+
});
|
|
5656
|
+
return result.data;
|
|
5657
|
+
}
|
|
5658
|
+
async findByUserAndShop(userId, shop) {
|
|
5659
|
+
const result = await this.find({
|
|
5660
|
+
filters: {
|
|
5661
|
+
user: {
|
|
5662
|
+
id: userId,
|
|
5663
|
+
},
|
|
5664
|
+
shop,
|
|
5665
|
+
},
|
|
5666
|
+
});
|
|
5667
|
+
return result.data;
|
|
5668
|
+
}
|
|
5669
|
+
}
|
|
5670
|
+
|
|
5231
5671
|
class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
5232
5672
|
constructor({ firestore, interceptors, cache, }) {
|
|
5233
5673
|
super({
|
|
@@ -5811,6 +6251,9 @@ tslib.__decorate([
|
|
|
5811
6251
|
tslib.__metadata("design:type", Product)
|
|
5812
6252
|
], KitProductHasuraGraphQL.prototype, "product", void 0);
|
|
5813
6253
|
|
|
6254
|
+
class ProductCatalogHasuraGraphQL extends Product {
|
|
6255
|
+
}
|
|
6256
|
+
|
|
5814
6257
|
class ProductHasuraGraphQL extends Product {
|
|
5815
6258
|
}
|
|
5816
6259
|
tslib.__decorate([
|
|
@@ -5828,6 +6271,9 @@ tslib.__decorate([
|
|
|
5828
6271
|
tslib.__metadata("design:type", Object)
|
|
5829
6272
|
], ProductErrorsHasuraGraphQL.prototype, "product", void 0);
|
|
5830
6273
|
|
|
6274
|
+
class ProductStockEntryHasuraGraphQL extends ProductStockEntry {
|
|
6275
|
+
}
|
|
6276
|
+
|
|
5831
6277
|
class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
5832
6278
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
5833
6279
|
super({
|
|
@@ -6714,6 +7160,8 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6714
7160
|
mostRelevants: mostRelevants || {
|
|
6715
7161
|
[exports.Shops.GLAMSHOP]: null,
|
|
6716
7162
|
[exports.Shops.MENSMARKET]: null,
|
|
7163
|
+
[exports.Shops.GLAMBEAUTY]: null,
|
|
7164
|
+
[exports.Shops.ELLA]: null,
|
|
6717
7165
|
},
|
|
6718
7166
|
images: images || {
|
|
6719
7167
|
[exports.Shops.GLAMSHOP]: {
|
|
@@ -6726,6 +7174,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6726
7174
|
brandBannerMobile: null,
|
|
6727
7175
|
image: null,
|
|
6728
7176
|
},
|
|
7177
|
+
[exports.Shops.GLAMBEAUTY]: {
|
|
7178
|
+
brandBanner: null,
|
|
7179
|
+
brandBannerMobile: null,
|
|
7180
|
+
image: null,
|
|
7181
|
+
},
|
|
7182
|
+
[exports.Shops.ELLA]: {
|
|
7183
|
+
brandBanner: null,
|
|
7184
|
+
brandBannerMobile: null,
|
|
7185
|
+
image: null,
|
|
7186
|
+
},
|
|
6729
7187
|
},
|
|
6730
7188
|
});
|
|
6731
7189
|
}
|
|
@@ -6899,6 +7357,19 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6899
7357
|
categoryFilterRepository: this.categoryFilterRepository,
|
|
6900
7358
|
});
|
|
6901
7359
|
}
|
|
7360
|
+
async getBrandsWithProducts() {
|
|
7361
|
+
const fields = ['id', 'name', 'slug', 'brand_category', 'published', 'images'];
|
|
7362
|
+
const { brands_with_products_query: data, } = await this.query('brands_with_products_query', fields);
|
|
7363
|
+
return data.map((brand) => Category.toInstance({
|
|
7364
|
+
id: brand.id,
|
|
7365
|
+
name: brand.name,
|
|
7366
|
+
slug: brand.slug,
|
|
7367
|
+
brandCategory: brand.brand_category,
|
|
7368
|
+
shops: brand.shops,
|
|
7369
|
+
published: brand.published,
|
|
7370
|
+
images: brand.images,
|
|
7371
|
+
}));
|
|
7372
|
+
}
|
|
6902
7373
|
}
|
|
6903
7374
|
tslib.__decorate([
|
|
6904
7375
|
Log(),
|
|
@@ -7013,10 +7484,30 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
|
|
|
7013
7484
|
},
|
|
7014
7485
|
});
|
|
7015
7486
|
}
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7487
|
+
async removeProductFromAllCategories(productId) {
|
|
7488
|
+
this.logger = DebugHelper.from(this, 'removeProductFromAllCategories');
|
|
7489
|
+
await this.mutation('delete_category_product', ['affected_rows'], {
|
|
7490
|
+
where: {
|
|
7491
|
+
type: 'category_product_bool_exp',
|
|
7492
|
+
required: true,
|
|
7493
|
+
value: { product_id: { _eq: productId } },
|
|
7494
|
+
},
|
|
7495
|
+
});
|
|
7496
|
+
}
|
|
7497
|
+
async removeCategoryFromAllProducts(categoryId) {
|
|
7498
|
+
this.logger = DebugHelper.from(this, 'removeCategoryFromAllProducts');
|
|
7499
|
+
await this.mutation('delete_category_product', ['affected_rows'], {
|
|
7500
|
+
where: {
|
|
7501
|
+
type: 'category_product_bool_exp',
|
|
7502
|
+
required: true,
|
|
7503
|
+
value: { category_id: { _eq: categoryId } },
|
|
7504
|
+
},
|
|
7505
|
+
});
|
|
7506
|
+
}
|
|
7507
|
+
}
|
|
7508
|
+
|
|
7509
|
+
const fieldsConfiguration$3 = [
|
|
7510
|
+
'id',
|
|
7020
7511
|
'title',
|
|
7021
7512
|
'description',
|
|
7022
7513
|
'slug',
|
|
@@ -7163,83 +7654,7 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
|
|
|
7163
7654
|
}
|
|
7164
7655
|
}
|
|
7165
7656
|
|
|
7166
|
-
|
|
7167
|
-
constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
|
|
7168
|
-
super({
|
|
7169
|
-
tableName: 'product_errors',
|
|
7170
|
-
model: ProductErrorsHasuraGraphQL,
|
|
7171
|
-
endpoint,
|
|
7172
|
-
authOptions,
|
|
7173
|
-
interceptors,
|
|
7174
|
-
cache,
|
|
7175
|
-
fields: [
|
|
7176
|
-
{
|
|
7177
|
-
productId: {
|
|
7178
|
-
columnName: 'product_id',
|
|
7179
|
-
to: (value) => +value,
|
|
7180
|
-
from: (value) => value.toString(),
|
|
7181
|
-
},
|
|
7182
|
-
},
|
|
7183
|
-
'source',
|
|
7184
|
-
'error',
|
|
7185
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
7186
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
7187
|
-
{
|
|
7188
|
-
product: {
|
|
7189
|
-
columnName: 'product',
|
|
7190
|
-
foreignKeyColumn: { id: 'productId' },
|
|
7191
|
-
fields: [
|
|
7192
|
-
{ id: { columnName: 'id', from: (value) => value.toString() } },
|
|
7193
|
-
{ productId: { columnName: 'main_product_id' } },
|
|
7194
|
-
'name',
|
|
7195
|
-
'published',
|
|
7196
|
-
'group',
|
|
7197
|
-
'validity',
|
|
7198
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
7199
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
7200
|
-
],
|
|
7201
|
-
},
|
|
7202
|
-
},
|
|
7203
|
-
],
|
|
7204
|
-
});
|
|
7205
|
-
this.productRepository = productRepository;
|
|
7206
|
-
}
|
|
7207
|
-
async get(params) {
|
|
7208
|
-
const result = await super.get(params);
|
|
7209
|
-
if (result instanceof VariantHasuraGraphQL) {
|
|
7210
|
-
const product = await this.productRepository.get({ id: result.productId.toString() });
|
|
7211
|
-
result.product.name = product.name;
|
|
7212
|
-
result.product.group = product.group;
|
|
7213
|
-
}
|
|
7214
|
-
return result;
|
|
7215
|
-
}
|
|
7216
|
-
async find(params) {
|
|
7217
|
-
const result = await super.find(params);
|
|
7218
|
-
const variantsWithNoData = result.data.filter((item) => item.product instanceof VariantHasuraGraphQL &&
|
|
7219
|
-
(lodash.isEmpty(item.product.name) || lodash.isEmpty(item.product.group) || lodash.isEmpty(item.product)));
|
|
7220
|
-
if (variantsWithNoData.length > 0) {
|
|
7221
|
-
const { data: products } = await this.productRepository.find({
|
|
7222
|
-
filters: {
|
|
7223
|
-
id: {
|
|
7224
|
-
operator: exports.Where.IN,
|
|
7225
|
-
value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
|
|
7226
|
-
},
|
|
7227
|
-
},
|
|
7228
|
-
});
|
|
7229
|
-
products.forEach((product) => {
|
|
7230
|
-
result.data
|
|
7231
|
-
.filter((variant) => variant.product.productId?.toString() === product.id.toString())
|
|
7232
|
-
.forEach((variant) => {
|
|
7233
|
-
variant.product.name = product.name;
|
|
7234
|
-
variant.product.group = product.group;
|
|
7235
|
-
});
|
|
7236
|
-
});
|
|
7237
|
-
}
|
|
7238
|
-
return result;
|
|
7239
|
-
}
|
|
7240
|
-
}
|
|
7241
|
-
|
|
7242
|
-
const commonFields = [
|
|
7657
|
+
const commonFields$1 = [
|
|
7243
7658
|
{
|
|
7244
7659
|
id: {
|
|
7245
7660
|
columnName: 'id',
|
|
@@ -7319,6 +7734,12 @@ const commonFields = [
|
|
|
7319
7734
|
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7320
7735
|
},
|
|
7321
7736
|
},
|
|
7737
|
+
{
|
|
7738
|
+
imagesCard: {
|
|
7739
|
+
columnName: 'images_card',
|
|
7740
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7741
|
+
},
|
|
7742
|
+
},
|
|
7322
7743
|
'name',
|
|
7323
7744
|
{
|
|
7324
7745
|
price: {
|
|
@@ -7380,7 +7801,6 @@ const commonFields = [
|
|
|
7380
7801
|
'weight',
|
|
7381
7802
|
'gender',
|
|
7382
7803
|
{ intGender: { columnName: 'int_gender' } },
|
|
7383
|
-
// { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7384
7804
|
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7385
7805
|
{ isKit: { columnName: 'is_kit' } },
|
|
7386
7806
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -7397,187 +7817,746 @@ const commonFields = [
|
|
|
7397
7817
|
},
|
|
7398
7818
|
},
|
|
7399
7819
|
'group',
|
|
7820
|
+
{ groupId: { columnName: 'group_id' } },
|
|
7400
7821
|
'validity',
|
|
7401
7822
|
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7402
7823
|
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7403
7824
|
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
7825
|
+
{ showVariants: { columnName: 'show_variants' } },
|
|
7826
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
7404
7827
|
];
|
|
7405
|
-
|
|
7406
|
-
...commonFields,
|
|
7407
|
-
{
|
|
7408
|
-
categories: {
|
|
7409
|
-
columnName: 'categories',
|
|
7410
|
-
fields: ['category_id'],
|
|
7411
|
-
bindPersistData: (value) => ({
|
|
7412
|
-
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
7413
|
-
}),
|
|
7414
|
-
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
7415
|
-
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
7416
|
-
},
|
|
7417
|
-
},
|
|
7418
|
-
{
|
|
7419
|
-
kitProducts: {
|
|
7420
|
-
columnName: 'kit_products',
|
|
7421
|
-
foreignKeyColumn: { productId: 'id' },
|
|
7422
|
-
fields: [
|
|
7423
|
-
{ productId: { columnName: 'product_id' } },
|
|
7424
|
-
{ kitProductId: { columnName: 'kit_product_id' } },
|
|
7425
|
-
'quantity',
|
|
7426
|
-
{ product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
|
|
7427
|
-
],
|
|
7428
|
-
},
|
|
7429
|
-
},
|
|
7430
|
-
{
|
|
7431
|
-
reviews: {
|
|
7432
|
-
columnName: 'reviews',
|
|
7433
|
-
foreignKeyColumn: { product_id: 'id' },
|
|
7434
|
-
fields: [
|
|
7435
|
-
'id',
|
|
7436
|
-
'shop',
|
|
7437
|
-
'rate',
|
|
7438
|
-
'author',
|
|
7439
|
-
'email',
|
|
7440
|
-
'location',
|
|
7441
|
-
'review',
|
|
7442
|
-
'status',
|
|
7443
|
-
'title',
|
|
7444
|
-
{ personId: { columnName: 'person_id' } },
|
|
7445
|
-
'points',
|
|
7446
|
-
{ orderId: { columnName: 'order_id' } },
|
|
7447
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
7448
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
7449
|
-
],
|
|
7450
|
-
},
|
|
7451
|
-
},
|
|
7452
|
-
{
|
|
7453
|
-
metadata: {
|
|
7454
|
-
columnName: 'metadata',
|
|
7455
|
-
fields: ['title', 'description'],
|
|
7456
|
-
bindPersistData: (value) => ({
|
|
7457
|
-
metadata: { data: value },
|
|
7458
|
-
}),
|
|
7459
|
-
},
|
|
7460
|
-
},
|
|
7461
|
-
{
|
|
7462
|
-
variants: {
|
|
7463
|
-
columnName: 'variants',
|
|
7464
|
-
foreignKeyColumn: { product_id: 'id' },
|
|
7465
|
-
fields: [
|
|
7466
|
-
'id',
|
|
7467
|
-
'ean',
|
|
7468
|
-
'grade',
|
|
7469
|
-
'price',
|
|
7470
|
-
'published',
|
|
7471
|
-
'stock',
|
|
7472
|
-
{ tagsCollection: { columnName: 'tags_collection' } },
|
|
7473
|
-
{ tagsProfile: { columnName: 'tags_profile' } },
|
|
7474
|
-
],
|
|
7475
|
-
},
|
|
7476
|
-
},
|
|
7477
|
-
];
|
|
7478
|
-
class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7479
|
-
get reviewsFields() {
|
|
7480
|
-
return [
|
|
7481
|
-
'id',
|
|
7482
|
-
'shop',
|
|
7483
|
-
'rate',
|
|
7484
|
-
'author',
|
|
7485
|
-
'email',
|
|
7486
|
-
'location',
|
|
7487
|
-
'review',
|
|
7488
|
-
'status',
|
|
7489
|
-
'title',
|
|
7490
|
-
{ personId: { columnName: 'person_id' } },
|
|
7491
|
-
'points',
|
|
7492
|
-
{ orderId: { columnName: 'order_id' } },
|
|
7493
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
7494
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
7495
|
-
];
|
|
7496
|
-
}
|
|
7828
|
+
class ProductCatalogHasuraGraphQLRepository extends withFindHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7497
7829
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
7498
7830
|
super({
|
|
7499
|
-
tableName: '
|
|
7500
|
-
model:
|
|
7831
|
+
tableName: 'product_catalog',
|
|
7832
|
+
model: ProductCatalogHasuraGraphQL,
|
|
7501
7833
|
endpoint,
|
|
7502
7834
|
authOptions,
|
|
7503
7835
|
interceptors,
|
|
7504
|
-
fields:
|
|
7836
|
+
fields: commonFields$1,
|
|
7505
7837
|
cache,
|
|
7506
7838
|
});
|
|
7507
|
-
this.bindReviewToModel = (plain) => ProductReview.toInstance({
|
|
7508
|
-
...is(lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
|
|
7509
|
-
createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
|
|
7510
|
-
updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
|
|
7511
|
-
personId: plain.person_id,
|
|
7512
|
-
orderId: plain.order_id,
|
|
7513
|
-
});
|
|
7514
|
-
this.bindReviewToHasura = (review) => ({
|
|
7515
|
-
...is(lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
|
|
7516
|
-
person_id: review.personId,
|
|
7517
|
-
order_id: review.orderId,
|
|
7518
|
-
});
|
|
7519
|
-
}
|
|
7520
|
-
async create(params) {
|
|
7521
|
-
const { metadata, ...data } = params;
|
|
7522
|
-
const product = await super.create(lodash.omit({ ...data, metadata: metadata || { description: null, title: null } }, ['reviews']));
|
|
7523
|
-
try {
|
|
7524
|
-
product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
|
|
7525
|
-
}
|
|
7526
|
-
catch (error) {
|
|
7527
|
-
await this.delete({ id: product.id });
|
|
7528
|
-
throw error;
|
|
7529
|
-
}
|
|
7530
|
-
return product;
|
|
7531
|
-
}
|
|
7532
|
-
async get(identifiers, options) {
|
|
7533
|
-
const product = Number.isNaN(+identifiers.id)
|
|
7534
|
-
? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
|
|
7535
|
-
.data?.[0]
|
|
7536
|
-
: await super.get(identifiers, options);
|
|
7537
|
-
if (product.productId)
|
|
7538
|
-
throw new NotFoundError('Product not found, it is a variant');
|
|
7539
|
-
product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
|
|
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, productId: { operator: exports.Where.ISNULL } },
|
|
7557
|
-
fields: [
|
|
7558
|
-
...bindFields,
|
|
7559
|
-
...(bindFields.includes('price')
|
|
7560
|
-
? [
|
|
7561
|
-
'subscriberPrice',
|
|
7562
|
-
'subscriberDiscountPercentage',
|
|
7563
|
-
'fullPrice',
|
|
7564
|
-
]
|
|
7565
|
-
: []),
|
|
7566
|
-
],
|
|
7567
|
-
}, optionsParams);
|
|
7568
7839
|
}
|
|
7569
|
-
async
|
|
7840
|
+
async get({ id }, options) {
|
|
7570
7841
|
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7571
|
-
const cacheKey = `${this.model.name.toLowerCase()}:
|
|
7842
|
+
const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
|
|
7572
7843
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7573
7844
|
if (cachedData) {
|
|
7574
7845
|
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
7575
7846
|
return this.model.toInstance(deserialize(cachedData));
|
|
7576
7847
|
}
|
|
7577
7848
|
}
|
|
7578
|
-
const
|
|
7849
|
+
const product = await super
|
|
7850
|
+
.find({
|
|
7851
|
+
filters: {
|
|
7852
|
+
id,
|
|
7853
|
+
},
|
|
7854
|
+
limits: {
|
|
7855
|
+
limit: 1,
|
|
7856
|
+
},
|
|
7857
|
+
})
|
|
7858
|
+
.then((res) => res.data.at(0));
|
|
7859
|
+
if (!product)
|
|
7860
|
+
throw new NotFoundError(`Product not found`);
|
|
7861
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7862
|
+
const cacheKey = `${this.model.name.toLowerCase()}:id:${id}`;
|
|
7863
|
+
await this.cache.cacheAdapter.set({
|
|
7864
|
+
key: cacheKey,
|
|
7865
|
+
data: serialize(product),
|
|
7866
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7867
|
+
});
|
|
7868
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7869
|
+
}
|
|
7870
|
+
return product;
|
|
7871
|
+
}
|
|
7872
|
+
async getByEAN(EAN, options) {
|
|
7873
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7874
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7875
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7876
|
+
if (cachedData) {
|
|
7877
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
7878
|
+
return this.model.toInstance(deserialize(cachedData));
|
|
7879
|
+
}
|
|
7880
|
+
}
|
|
7881
|
+
const product = await super
|
|
7882
|
+
.find({
|
|
7883
|
+
filters: {
|
|
7884
|
+
EAN,
|
|
7885
|
+
},
|
|
7886
|
+
limits: {
|
|
7887
|
+
limit: 1,
|
|
7888
|
+
},
|
|
7889
|
+
})
|
|
7890
|
+
.then((res) => res.data.at(0));
|
|
7891
|
+
if (!product)
|
|
7892
|
+
return null;
|
|
7893
|
+
RoundProductPricesHelper.roundProductPrices(product);
|
|
7894
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7895
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7896
|
+
await this.cache.cacheAdapter.set({
|
|
7897
|
+
key: cacheKey,
|
|
7898
|
+
data: serialize(product),
|
|
7899
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7900
|
+
});
|
|
7901
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7902
|
+
}
|
|
7903
|
+
return product;
|
|
7904
|
+
}
|
|
7905
|
+
async find(params, optionsParams) {
|
|
7906
|
+
const { filters, fields, ...options } = params || {};
|
|
7907
|
+
const bindFields = fields ||
|
|
7908
|
+
this.fields
|
|
7909
|
+
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
7910
|
+
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
7911
|
+
if (options.options?.minimal?.includes('price'))
|
|
7912
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7913
|
+
if (options.options?.maximum?.includes('price'))
|
|
7914
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7915
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
7916
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
7917
|
+
return super.find({
|
|
7918
|
+
...options,
|
|
7919
|
+
filters: { ...filters },
|
|
7920
|
+
fields: [
|
|
7921
|
+
...bindFields,
|
|
7922
|
+
...(bindFields.includes('price')
|
|
7923
|
+
? [
|
|
7924
|
+
'subscriberPrice',
|
|
7925
|
+
'subscriberDiscountPercentage',
|
|
7926
|
+
'fullPrice',
|
|
7927
|
+
]
|
|
7928
|
+
: []),
|
|
7929
|
+
],
|
|
7930
|
+
}, optionsParams);
|
|
7931
|
+
}
|
|
7932
|
+
async findCatalog(params, mainGender, options) {
|
|
7933
|
+
const result = await this.find({
|
|
7934
|
+
...params,
|
|
7935
|
+
filters: { ...params.filters, published: true },
|
|
7936
|
+
orderBy: {
|
|
7937
|
+
hasStock: 'desc',
|
|
7938
|
+
...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
|
|
7939
|
+
...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
|
|
7940
|
+
},
|
|
7941
|
+
}, options);
|
|
7942
|
+
return result;
|
|
7943
|
+
}
|
|
7944
|
+
}
|
|
7945
|
+
tslib.__decorate([
|
|
7946
|
+
Log(),
|
|
7947
|
+
tslib.__metadata("design:type", Function),
|
|
7948
|
+
tslib.__metadata("design:paramtypes", [Object, Object, Object]),
|
|
7949
|
+
tslib.__metadata("design:returntype", Promise)
|
|
7950
|
+
], ProductCatalogHasuraGraphQLRepository.prototype, "findCatalog", null);
|
|
7951
|
+
|
|
7952
|
+
class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7953
|
+
constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
|
|
7954
|
+
super({
|
|
7955
|
+
tableName: 'product_errors',
|
|
7956
|
+
model: ProductErrorsHasuraGraphQL,
|
|
7957
|
+
endpoint,
|
|
7958
|
+
authOptions,
|
|
7959
|
+
interceptors,
|
|
7960
|
+
cache,
|
|
7961
|
+
fields: [
|
|
7962
|
+
{
|
|
7963
|
+
productId: {
|
|
7964
|
+
columnName: 'product_id',
|
|
7965
|
+
to: (value) => +value,
|
|
7966
|
+
from: (value) => value.toString(),
|
|
7967
|
+
},
|
|
7968
|
+
},
|
|
7969
|
+
'source',
|
|
7970
|
+
'error',
|
|
7971
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
7972
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
7973
|
+
{
|
|
7974
|
+
product: {
|
|
7975
|
+
columnName: 'product',
|
|
7976
|
+
foreignKeyColumn: { id: 'productId' },
|
|
7977
|
+
fields: [
|
|
7978
|
+
{ id: { columnName: 'id', from: (value) => value.toString() } },
|
|
7979
|
+
{ productId: { columnName: 'main_product_id' } },
|
|
7980
|
+
'name',
|
|
7981
|
+
'published',
|
|
7982
|
+
'group',
|
|
7983
|
+
'validity',
|
|
7984
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
7985
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
7986
|
+
],
|
|
7987
|
+
},
|
|
7988
|
+
},
|
|
7989
|
+
],
|
|
7990
|
+
});
|
|
7991
|
+
this.productRepository = productRepository;
|
|
7992
|
+
}
|
|
7993
|
+
async get(params) {
|
|
7994
|
+
const result = await super.get(params);
|
|
7995
|
+
if (result instanceof VariantHasuraGraphQL) {
|
|
7996
|
+
const product = await this.productRepository.get({ id: result.productId.toString() });
|
|
7997
|
+
result.product.name = product.name;
|
|
7998
|
+
result.product.group = product.group;
|
|
7999
|
+
}
|
|
8000
|
+
return result;
|
|
8001
|
+
}
|
|
8002
|
+
async find(params) {
|
|
8003
|
+
const result = await super.find(params);
|
|
8004
|
+
const variantsWithNoData = result.data.filter((item) => item.product instanceof VariantHasuraGraphQL &&
|
|
8005
|
+
(lodash.isEmpty(item.product.name) || lodash.isEmpty(item.product.group) || lodash.isEmpty(item.product)));
|
|
8006
|
+
if (variantsWithNoData.length > 0) {
|
|
8007
|
+
const { data: products } = await this.productRepository.find({
|
|
8008
|
+
filters: {
|
|
8009
|
+
id: {
|
|
8010
|
+
operator: exports.Where.IN,
|
|
8011
|
+
value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
|
|
8012
|
+
},
|
|
8013
|
+
},
|
|
8014
|
+
});
|
|
8015
|
+
products.forEach((product) => {
|
|
8016
|
+
result.data
|
|
8017
|
+
.filter((variant) => variant.product.productId?.toString() === product.id.toString())
|
|
8018
|
+
.forEach((variant) => {
|
|
8019
|
+
variant.product.name = product.name;
|
|
8020
|
+
variant.product.group = product.group;
|
|
8021
|
+
});
|
|
8022
|
+
});
|
|
8023
|
+
}
|
|
8024
|
+
return result;
|
|
8025
|
+
}
|
|
8026
|
+
}
|
|
8027
|
+
|
|
8028
|
+
class ProductGroupHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8029
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
8030
|
+
super({
|
|
8031
|
+
tableName: 'group',
|
|
8032
|
+
model: ProductGroup,
|
|
8033
|
+
endpoint,
|
|
8034
|
+
authOptions,
|
|
8035
|
+
interceptors,
|
|
8036
|
+
fields: [
|
|
8037
|
+
{
|
|
8038
|
+
id: {
|
|
8039
|
+
columnName: 'id',
|
|
8040
|
+
to: (value) => +value,
|
|
8041
|
+
from: (value) => value.toString(),
|
|
8042
|
+
},
|
|
8043
|
+
},
|
|
8044
|
+
'name',
|
|
8045
|
+
'description',
|
|
8046
|
+
{ markupMin: { columnName: 'markup_min' } },
|
|
8047
|
+
{ markupWithoutCompetitor: { columnName: 'markup_without_competitor' } },
|
|
8048
|
+
{ discountCompetitor: { columnName: 'discount_competitor' } },
|
|
8049
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
8050
|
+
{ dynamicPrecification: { columnName: 'dynamic_precification' } },
|
|
8051
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8052
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8053
|
+
],
|
|
8054
|
+
cache,
|
|
8055
|
+
});
|
|
8056
|
+
}
|
|
8057
|
+
}
|
|
8058
|
+
|
|
8059
|
+
const commonFields = [
|
|
8060
|
+
{
|
|
8061
|
+
id: {
|
|
8062
|
+
columnName: 'id',
|
|
8063
|
+
to: (value) => +value,
|
|
8064
|
+
from: (value) => value.toString(),
|
|
8065
|
+
},
|
|
8066
|
+
},
|
|
8067
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
8068
|
+
{ productId: { columnName: 'main_product_id' } },
|
|
8069
|
+
{ CEST: { columnName: 'cest' } },
|
|
8070
|
+
{ EAN: { columnName: 'ean' } },
|
|
8071
|
+
{ NCM: { columnName: 'ncm' } },
|
|
8072
|
+
'brand',
|
|
8073
|
+
{ costPrice: { columnName: 'cost_price' } },
|
|
8074
|
+
{
|
|
8075
|
+
description: {
|
|
8076
|
+
columnName: 'description',
|
|
8077
|
+
from: (description, data) => ({
|
|
8078
|
+
description,
|
|
8079
|
+
differentials: data.differentials,
|
|
8080
|
+
whoMustUse: data.who_must_use,
|
|
8081
|
+
howToUse: data.how_to_use,
|
|
8082
|
+
brand: data.brand_description,
|
|
8083
|
+
ingredients: data.ingredients,
|
|
8084
|
+
purpose: data.purpose,
|
|
8085
|
+
}),
|
|
8086
|
+
bindFindFilter: (filters) => {
|
|
8087
|
+
return {
|
|
8088
|
+
...(filters?.description && { description: filters.description }),
|
|
8089
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
8090
|
+
...(filters.whoMustUse && {
|
|
8091
|
+
who_must_use: filters.whoMustUse,
|
|
8092
|
+
}),
|
|
8093
|
+
...(filters.howToUse && {
|
|
8094
|
+
how_to_use: filters.howToUse,
|
|
8095
|
+
}),
|
|
8096
|
+
...(filters.brand && {
|
|
8097
|
+
brand_description: filters.brand,
|
|
8098
|
+
}),
|
|
8099
|
+
...(filters.ingredients && {
|
|
8100
|
+
ingredients: filters.ingredients,
|
|
8101
|
+
}),
|
|
8102
|
+
...(filters.purpose && {
|
|
8103
|
+
purpose: filters.purpose,
|
|
8104
|
+
}),
|
|
8105
|
+
};
|
|
8106
|
+
},
|
|
8107
|
+
bindPersistData: (descriptionData) => ({
|
|
8108
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
8109
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
8110
|
+
...(descriptionData.whoMustUse && {
|
|
8111
|
+
who_must_use: descriptionData.whoMustUse,
|
|
8112
|
+
}),
|
|
8113
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
8114
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
8115
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
8116
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
8117
|
+
}),
|
|
8118
|
+
},
|
|
8119
|
+
},
|
|
8120
|
+
{ differentials: { columnName: 'differentials' } },
|
|
8121
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
8122
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
8123
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
8124
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
8125
|
+
{ purpose: { columnName: 'purpose' } },
|
|
8126
|
+
{ hasVariants: { columnName: 'has_variants' } },
|
|
8127
|
+
{
|
|
8128
|
+
images: {
|
|
8129
|
+
columnName: 'images',
|
|
8130
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8131
|
+
},
|
|
8132
|
+
},
|
|
8133
|
+
{
|
|
8134
|
+
miniatures: {
|
|
8135
|
+
columnName: 'miniatures',
|
|
8136
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8137
|
+
},
|
|
8138
|
+
},
|
|
8139
|
+
{
|
|
8140
|
+
imagesCard: {
|
|
8141
|
+
columnName: 'images_card',
|
|
8142
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8143
|
+
},
|
|
8144
|
+
},
|
|
8145
|
+
'name',
|
|
8146
|
+
{
|
|
8147
|
+
price: {
|
|
8148
|
+
columnName: 'price',
|
|
8149
|
+
from: (price, data) => ({
|
|
8150
|
+
price,
|
|
8151
|
+
fullPrice: data.full_price,
|
|
8152
|
+
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
8153
|
+
fullPriceDiscountPercentage: data.full_price_discount_percentage,
|
|
8154
|
+
subscriberPrice: data.subscriber_price,
|
|
8155
|
+
}),
|
|
8156
|
+
bindFindFilter: (filters) => {
|
|
8157
|
+
return {
|
|
8158
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
8159
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
8160
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
8161
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
8162
|
+
}),
|
|
8163
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
8164
|
+
subscriber_price: filters.subscriberPrice,
|
|
8165
|
+
}),
|
|
8166
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
8167
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
8168
|
+
}),
|
|
8169
|
+
};
|
|
8170
|
+
},
|
|
8171
|
+
bindPersistData: (priceData) => ({
|
|
8172
|
+
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
8173
|
+
...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
|
|
8174
|
+
...(priceData.subscriberDiscountPercentage >= 0 && {
|
|
8175
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
8176
|
+
}),
|
|
8177
|
+
...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
8178
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
8179
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
8180
|
+
}),
|
|
8181
|
+
}),
|
|
8182
|
+
},
|
|
8183
|
+
},
|
|
8184
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
8185
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
8186
|
+
{ fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
|
|
8187
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
8188
|
+
'published',
|
|
8189
|
+
'outlet',
|
|
8190
|
+
'label',
|
|
8191
|
+
'sku',
|
|
8192
|
+
{
|
|
8193
|
+
stock: {
|
|
8194
|
+
columnName: 'stock',
|
|
8195
|
+
from: (quantity) => ({ quantity }),
|
|
8196
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
8197
|
+
},
|
|
8198
|
+
},
|
|
8199
|
+
{ hasStock: { columnName: 'has_stock' } },
|
|
8200
|
+
'slug',
|
|
8201
|
+
'type',
|
|
8202
|
+
'video',
|
|
8203
|
+
'weight',
|
|
8204
|
+
'gender',
|
|
8205
|
+
{ intGender: { columnName: 'int_gender' } },
|
|
8206
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8207
|
+
{ isKit: { columnName: 'is_kit' } },
|
|
8208
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8209
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8210
|
+
{ rate: { columnName: 'rating' } },
|
|
8211
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
8212
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
8213
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
8214
|
+
{
|
|
8215
|
+
category: {
|
|
8216
|
+
columnName: 'category',
|
|
8217
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
8218
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
8219
|
+
},
|
|
8220
|
+
},
|
|
8221
|
+
'group',
|
|
8222
|
+
{ groupId: { columnName: 'group_id' } },
|
|
8223
|
+
'validity',
|
|
8224
|
+
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8225
|
+
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8226
|
+
{ tagsSupply: { columnName: 'tags_supply', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8227
|
+
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
8228
|
+
{ showVariants: { columnName: 'show_variants' } },
|
|
8229
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
8230
|
+
{ caixariaMinima: { columnName: 'caixaria_minima', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8231
|
+
'suppliers',
|
|
8232
|
+
'curve',
|
|
8233
|
+
];
|
|
8234
|
+
const fieldsConfiguration$2 = [
|
|
8235
|
+
...commonFields,
|
|
8236
|
+
{
|
|
8237
|
+
categories: {
|
|
8238
|
+
columnName: 'categories',
|
|
8239
|
+
fields: ['category_id'],
|
|
8240
|
+
bindPersistData: (value) => ({
|
|
8241
|
+
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
8242
|
+
}),
|
|
8243
|
+
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
8244
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
8245
|
+
},
|
|
8246
|
+
},
|
|
8247
|
+
{
|
|
8248
|
+
kitProducts: {
|
|
8249
|
+
columnName: 'kit_products',
|
|
8250
|
+
foreignKeyColumn: { productId: 'id' },
|
|
8251
|
+
fields: [
|
|
8252
|
+
{ productId: { columnName: 'product_id' } },
|
|
8253
|
+
{ kitProductId: { columnName: 'kit_product_id' } },
|
|
8254
|
+
'quantity',
|
|
8255
|
+
{ product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
|
|
8256
|
+
],
|
|
8257
|
+
},
|
|
8258
|
+
},
|
|
8259
|
+
{
|
|
8260
|
+
reviews: {
|
|
8261
|
+
columnName: 'reviews',
|
|
8262
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
8263
|
+
fields: [
|
|
8264
|
+
'id',
|
|
8265
|
+
'shop',
|
|
8266
|
+
'rate',
|
|
8267
|
+
'author',
|
|
8268
|
+
'email',
|
|
8269
|
+
'location',
|
|
8270
|
+
'review',
|
|
8271
|
+
'status',
|
|
8272
|
+
'title',
|
|
8273
|
+
{ personId: { columnName: 'person_id' } },
|
|
8274
|
+
'points',
|
|
8275
|
+
{ orderId: { columnName: 'order_id' } },
|
|
8276
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8277
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8278
|
+
],
|
|
8279
|
+
},
|
|
8280
|
+
},
|
|
8281
|
+
{
|
|
8282
|
+
metadata: {
|
|
8283
|
+
columnName: 'metadata',
|
|
8284
|
+
fields: ['title', 'description'],
|
|
8285
|
+
bindPersistData: (value) => ({
|
|
8286
|
+
metadata: { data: value },
|
|
8287
|
+
}),
|
|
8288
|
+
},
|
|
8289
|
+
},
|
|
8290
|
+
{
|
|
8291
|
+
variants: {
|
|
8292
|
+
columnName: 'variants',
|
|
8293
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
8294
|
+
fields: [
|
|
8295
|
+
'id',
|
|
8296
|
+
'name',
|
|
8297
|
+
'ean',
|
|
8298
|
+
'sku',
|
|
8299
|
+
{
|
|
8300
|
+
description: {
|
|
8301
|
+
columnName: 'description',
|
|
8302
|
+
from: (description, data) => ({
|
|
8303
|
+
description,
|
|
8304
|
+
differentials: data.differentials,
|
|
8305
|
+
whoMustUse: data.who_must_use,
|
|
8306
|
+
howToUse: data.how_to_use,
|
|
8307
|
+
brand: data.brand_description,
|
|
8308
|
+
ingredients: data.ingredients,
|
|
8309
|
+
purpose: data.purpose,
|
|
8310
|
+
}),
|
|
8311
|
+
bindFindFilter: (filters) => {
|
|
8312
|
+
return {
|
|
8313
|
+
...(filters?.description && { description: filters.description }),
|
|
8314
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
8315
|
+
...(filters.whoMustUse && {
|
|
8316
|
+
who_must_use: filters.whoMustUse,
|
|
8317
|
+
}),
|
|
8318
|
+
...(filters.howToUse && {
|
|
8319
|
+
how_to_use: filters.howToUse,
|
|
8320
|
+
}),
|
|
8321
|
+
...(filters.brand && {
|
|
8322
|
+
brand_description: filters.brand,
|
|
8323
|
+
}),
|
|
8324
|
+
...(filters.ingredients && {
|
|
8325
|
+
ingredients: filters.ingredients,
|
|
8326
|
+
}),
|
|
8327
|
+
...(filters.purpose && {
|
|
8328
|
+
purpose: filters.purpose,
|
|
8329
|
+
}),
|
|
8330
|
+
};
|
|
8331
|
+
},
|
|
8332
|
+
bindPersistData: (descriptionData) => ({
|
|
8333
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
8334
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
8335
|
+
...(descriptionData.whoMustUse && {
|
|
8336
|
+
who_must_use: descriptionData.whoMustUse,
|
|
8337
|
+
}),
|
|
8338
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
8339
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
8340
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
8341
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
8342
|
+
}),
|
|
8343
|
+
},
|
|
8344
|
+
},
|
|
8345
|
+
{ differentials: { columnName: 'differentials' } },
|
|
8346
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
8347
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
8348
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
8349
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
8350
|
+
{ purpose: { columnName: 'purpose' } },
|
|
8351
|
+
{
|
|
8352
|
+
grade: {
|
|
8353
|
+
columnName: 'grade',
|
|
8354
|
+
type: HasuraGraphQLColumnType.Jsonb,
|
|
8355
|
+
},
|
|
8356
|
+
},
|
|
8357
|
+
{
|
|
8358
|
+
price: {
|
|
8359
|
+
columnName: 'price',
|
|
8360
|
+
from: (price, data) => ({
|
|
8361
|
+
price,
|
|
8362
|
+
fullPrice: data.full_price,
|
|
8363
|
+
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
8364
|
+
subscriberPrice: data.subscriber_price,
|
|
8365
|
+
fullPriceDiscountPercentage: data.full_price_discount_percentage,
|
|
8366
|
+
}),
|
|
8367
|
+
bindPersistData: (priceData) => ({
|
|
8368
|
+
...((priceData?.price || 0) >= 0 && { price: priceData.price }),
|
|
8369
|
+
...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
|
|
8370
|
+
...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
|
|
8371
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
8372
|
+
}),
|
|
8373
|
+
...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
8374
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
8375
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
8376
|
+
}),
|
|
8377
|
+
}),
|
|
8378
|
+
},
|
|
8379
|
+
},
|
|
8380
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
8381
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
8382
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
8383
|
+
{ fullPriceDiscountPercentage: { columnName: 'full_price_discount_percentage' } },
|
|
8384
|
+
'published',
|
|
8385
|
+
{
|
|
8386
|
+
stock: {
|
|
8387
|
+
columnName: 'stock',
|
|
8388
|
+
from: (quantity) => ({ quantity }),
|
|
8389
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
8390
|
+
},
|
|
8391
|
+
},
|
|
8392
|
+
{
|
|
8393
|
+
images: {
|
|
8394
|
+
columnName: 'images',
|
|
8395
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8396
|
+
},
|
|
8397
|
+
},
|
|
8398
|
+
{
|
|
8399
|
+
miniatures: {
|
|
8400
|
+
columnName: 'miniatures',
|
|
8401
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8402
|
+
},
|
|
8403
|
+
},
|
|
8404
|
+
{
|
|
8405
|
+
imagesCard: {
|
|
8406
|
+
columnName: 'images_card',
|
|
8407
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
8408
|
+
},
|
|
8409
|
+
},
|
|
8410
|
+
{ tagsProfile: { columnName: 'tags_profile' } },
|
|
8411
|
+
{ tagsCollection: { columnName: 'tags_collection' } },
|
|
8412
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
8413
|
+
{
|
|
8414
|
+
reviews: {
|
|
8415
|
+
columnName: 'reviews',
|
|
8416
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
8417
|
+
fields: [
|
|
8418
|
+
'id',
|
|
8419
|
+
'shop',
|
|
8420
|
+
'rate',
|
|
8421
|
+
'author',
|
|
8422
|
+
'email',
|
|
8423
|
+
'location',
|
|
8424
|
+
'review',
|
|
8425
|
+
'status',
|
|
8426
|
+
'title',
|
|
8427
|
+
{ personId: { columnName: 'person_id' } },
|
|
8428
|
+
'points',
|
|
8429
|
+
{ orderId: { columnName: 'order_id' } },
|
|
8430
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8431
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8432
|
+
],
|
|
8433
|
+
},
|
|
8434
|
+
},
|
|
8435
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8436
|
+
{
|
|
8437
|
+
metadata: {
|
|
8438
|
+
columnName: 'metadata',
|
|
8439
|
+
fields: ['title', 'description'],
|
|
8440
|
+
bindPersistData: (value) => ({
|
|
8441
|
+
metadata: { data: value },
|
|
8442
|
+
}),
|
|
8443
|
+
},
|
|
8444
|
+
},
|
|
8445
|
+
],
|
|
8446
|
+
},
|
|
8447
|
+
},
|
|
8448
|
+
];
|
|
8449
|
+
class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8450
|
+
get reviewsFields() {
|
|
8451
|
+
return [
|
|
8452
|
+
'id',
|
|
8453
|
+
'shop',
|
|
8454
|
+
'rate',
|
|
8455
|
+
'author',
|
|
8456
|
+
'email',
|
|
8457
|
+
'location',
|
|
8458
|
+
'review',
|
|
8459
|
+
'status',
|
|
8460
|
+
'title',
|
|
8461
|
+
{ personId: { columnName: 'person_id' } },
|
|
8462
|
+
'points',
|
|
8463
|
+
{ orderId: { columnName: 'order_id' } },
|
|
8464
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8465
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8466
|
+
];
|
|
8467
|
+
}
|
|
8468
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
8469
|
+
super({
|
|
8470
|
+
tableName: 'product',
|
|
8471
|
+
model: ProductHasuraGraphQL,
|
|
8472
|
+
endpoint,
|
|
8473
|
+
authOptions,
|
|
8474
|
+
interceptors,
|
|
8475
|
+
fields: fieldsConfiguration$2,
|
|
8476
|
+
cache,
|
|
8477
|
+
});
|
|
8478
|
+
this.bindReviewToModel = (plain) => ProductReview.toInstance({
|
|
8479
|
+
...is(lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
|
|
8480
|
+
createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
|
|
8481
|
+
updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
|
|
8482
|
+
personId: plain.person_id,
|
|
8483
|
+
orderId: plain.order_id,
|
|
8484
|
+
});
|
|
8485
|
+
this.bindReviewToHasura = (review) => ({
|
|
8486
|
+
...is(lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
|
|
8487
|
+
person_id: review.personId,
|
|
8488
|
+
order_id: review.orderId,
|
|
8489
|
+
});
|
|
8490
|
+
}
|
|
8491
|
+
async create(params) {
|
|
8492
|
+
const { metadata, ...data } = params;
|
|
8493
|
+
const product = await super.create(lodash.omit({ ...data, metadata: metadata || { description: null, title: null } }, ['reviews']));
|
|
8494
|
+
try {
|
|
8495
|
+
product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
|
|
8496
|
+
}
|
|
8497
|
+
catch (error) {
|
|
8498
|
+
await this.delete({ id: product.id });
|
|
8499
|
+
throw error;
|
|
8500
|
+
}
|
|
8501
|
+
return product;
|
|
8502
|
+
}
|
|
8503
|
+
async get(identifiers, options) {
|
|
8504
|
+
const product = Number.isNaN(+identifiers.id)
|
|
8505
|
+
? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
|
|
8506
|
+
.data?.[0]
|
|
8507
|
+
: await super.get(identifiers, options);
|
|
8508
|
+
if (product.productId)
|
|
8509
|
+
throw new NotFoundError('Product not found, it is a variant');
|
|
8510
|
+
product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, false, options));
|
|
8511
|
+
if (!product.variants?.length) {
|
|
8512
|
+
for (const [index, variant] of product.variants.entries()) {
|
|
8513
|
+
product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
|
|
8514
|
+
}
|
|
8515
|
+
}
|
|
8516
|
+
return product;
|
|
8517
|
+
}
|
|
8518
|
+
async find(params, optionsParams) {
|
|
8519
|
+
const { filters, fields, ...options } = params || {};
|
|
8520
|
+
const bindFields = fields ||
|
|
8521
|
+
this.fields
|
|
8522
|
+
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
8523
|
+
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
8524
|
+
if (options.options?.minimal?.includes('price'))
|
|
8525
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
8526
|
+
if (options.options?.maximum?.includes('price'))
|
|
8527
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
8528
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
8529
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
8530
|
+
return super.find({
|
|
8531
|
+
...options,
|
|
8532
|
+
filters: { ...filters, productId: { operator: exports.Where.ISNULL } },
|
|
8533
|
+
fields: [
|
|
8534
|
+
...bindFields,
|
|
8535
|
+
...(bindFields.includes('price')
|
|
8536
|
+
? [
|
|
8537
|
+
'subscriberPrice',
|
|
8538
|
+
'subscriberDiscountPercentage',
|
|
8539
|
+
'fullPrice',
|
|
8540
|
+
]
|
|
8541
|
+
: []),
|
|
8542
|
+
],
|
|
8543
|
+
}, optionsParams);
|
|
8544
|
+
}
|
|
8545
|
+
async getBySlug(slug, options) {
|
|
8546
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
8547
|
+
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
8548
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
8549
|
+
if (cachedData) {
|
|
8550
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
8551
|
+
return this.model.toInstance(deserialize(cachedData));
|
|
8552
|
+
}
|
|
8553
|
+
}
|
|
8554
|
+
const result = await this.find({
|
|
7579
8555
|
filters: {
|
|
7580
8556
|
slug,
|
|
8557
|
+
productId: {
|
|
8558
|
+
operator: exports.Where.ISNULL,
|
|
8559
|
+
},
|
|
7581
8560
|
},
|
|
7582
8561
|
fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
|
|
7583
8562
|
options: {
|
|
@@ -7587,6 +8566,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7587
8566
|
if (!result.data.length)
|
|
7588
8567
|
return null;
|
|
7589
8568
|
const product = result?.data?.shift();
|
|
8569
|
+
if (!product.variants?.length) {
|
|
8570
|
+
for (const [index, variant] of product.variants.entries()) {
|
|
8571
|
+
product.variants[index].reviews = await this.findReviewsByProduct(+variant.id, true);
|
|
8572
|
+
}
|
|
8573
|
+
}
|
|
7590
8574
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
7591
8575
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7592
8576
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
@@ -7766,7 +8750,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7766
8750
|
const plainData = this.paramsToPlain({ metadata });
|
|
7767
8751
|
if (!plainData.metadata)
|
|
7768
8752
|
return null;
|
|
7769
|
-
|
|
8753
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8754
|
+
const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
|
|
7770
8755
|
pk_columns: {
|
|
7771
8756
|
value: { product_id: productId },
|
|
7772
8757
|
type: 'product_metadata_pk_columns_input',
|
|
@@ -7778,6 +8763,14 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7778
8763
|
required: true,
|
|
7779
8764
|
},
|
|
7780
8765
|
});
|
|
8766
|
+
if (!update_product_metadata_by_pk) {
|
|
8767
|
+
await this.mutation('insert_product_metadata', ['affected_rows'], {
|
|
8768
|
+
objects: {
|
|
8769
|
+
type: '[product_metadata_insert_input!]!',
|
|
8770
|
+
value: [{ product_id: productId, ...metadata }],
|
|
8771
|
+
},
|
|
8772
|
+
});
|
|
8773
|
+
}
|
|
7781
8774
|
return plainData.metadata;
|
|
7782
8775
|
}
|
|
7783
8776
|
async getId(id) {
|
|
@@ -7788,7 +8781,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7788
8781
|
return data?.[0]?.id;
|
|
7789
8782
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7790
8783
|
}
|
|
7791
|
-
async findReviewsByProduct(productId, options) {
|
|
8784
|
+
async findReviewsByProduct(productId, onlyApproved, options) {
|
|
7792
8785
|
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7793
8786
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7794
8787
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
@@ -7801,10 +8794,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7801
8794
|
where: {
|
|
7802
8795
|
value: {
|
|
7803
8796
|
product_id: { _eq: productId },
|
|
8797
|
+
...(onlyApproved && { status: { _eq: true } }),
|
|
7804
8798
|
},
|
|
7805
8799
|
type: 'product_review_bool_exp',
|
|
7806
8800
|
required: true,
|
|
7807
8801
|
},
|
|
8802
|
+
order_by: {
|
|
8803
|
+
type: '[product_review_order_by]',
|
|
8804
|
+
value: [{ createdAt: 'desc' }],
|
|
8805
|
+
required: true,
|
|
8806
|
+
},
|
|
7808
8807
|
});
|
|
7809
8808
|
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
7810
8809
|
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
@@ -7909,10 +8908,53 @@ tslib.__decorate([
|
|
|
7909
8908
|
tslib.__decorate([
|
|
7910
8909
|
Log(),
|
|
7911
8910
|
tslib.__metadata("design:type", Function),
|
|
7912
|
-
tslib.__metadata("design:paramtypes", [Number, Object]),
|
|
8911
|
+
tslib.__metadata("design:paramtypes", [Number, Boolean, Object]),
|
|
7913
8912
|
tslib.__metadata("design:returntype", Promise)
|
|
7914
8913
|
], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
|
|
7915
8914
|
|
|
8915
|
+
class ProductPriceLogHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8916
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
8917
|
+
super({
|
|
8918
|
+
tableName: 'product_price_log',
|
|
8919
|
+
model: ProductPriceLog,
|
|
8920
|
+
endpoint,
|
|
8921
|
+
authOptions,
|
|
8922
|
+
interceptors,
|
|
8923
|
+
fields: [
|
|
8924
|
+
{
|
|
8925
|
+
id: {
|
|
8926
|
+
columnName: 'id',
|
|
8927
|
+
to: (value) => +value,
|
|
8928
|
+
from: (value) => value.toString(),
|
|
8929
|
+
},
|
|
8930
|
+
},
|
|
8931
|
+
{ productId: { columnName: 'product_id' } },
|
|
8932
|
+
{ productEAN: { columnName: 'product_ean' } },
|
|
8933
|
+
{ productSKU: { columnName: 'product_sku' } },
|
|
8934
|
+
{ productName: { columnName: 'product_name' } },
|
|
8935
|
+
{ productCostPrice: { columnName: 'product_cost_price' } },
|
|
8936
|
+
{ productPrice: { columnName: 'product_price' } },
|
|
8937
|
+
{ productSubscriberPrice: { columnName: 'product_subscriber_price' } },
|
|
8938
|
+
{ productSubscriberDiscountPercentage: { columnName: 'product_subscriber_discount_percentage' } },
|
|
8939
|
+
{ markupMin: { columnName: 'markup_min' } },
|
|
8940
|
+
{ markupWithoutCompetitor: { columnName: 'markup_without_competitor' } },
|
|
8941
|
+
{ discountCompetitor: { columnName: 'discount_competitor' } },
|
|
8942
|
+
{ minViablePrice: { columnName: 'min_viable_price' } },
|
|
8943
|
+
{ targetPrice: { columnName: 'target_price' } },
|
|
8944
|
+
{ groupId: { columnName: 'group_id' } },
|
|
8945
|
+
{ competitorsAndPrices: { columnName: 'competitors_and_prices', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8946
|
+
{ competitorsPrices: { columnName: 'competitors_prices', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8947
|
+
{ competitorsMinPrice: { columnName: 'competitors_min_price' } },
|
|
8948
|
+
{ competitorsSellerMinPrice: { columnName: 'competitors_seller_min_price' } },
|
|
8949
|
+
{ statusPrecificacao: { columnName: 'status_precificacao' } },
|
|
8950
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
8951
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8952
|
+
],
|
|
8953
|
+
cache,
|
|
8954
|
+
});
|
|
8955
|
+
}
|
|
8956
|
+
}
|
|
8957
|
+
|
|
7916
8958
|
class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7917
8959
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
7918
8960
|
super({
|
|
@@ -7941,7 +8983,25 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
|
|
|
7941
8983
|
product: {
|
|
7942
8984
|
columnName: 'product',
|
|
7943
8985
|
foreignKeyColumn: { id: 'productId' },
|
|
7944
|
-
fields: [
|
|
8986
|
+
fields: [
|
|
8987
|
+
'id',
|
|
8988
|
+
{
|
|
8989
|
+
productId: {
|
|
8990
|
+
columnName: 'main_product_id',
|
|
8991
|
+
to: (value) => +value,
|
|
8992
|
+
from: (value) => value?.toString(),
|
|
8993
|
+
},
|
|
8994
|
+
},
|
|
8995
|
+
'ean',
|
|
8996
|
+
'sku',
|
|
8997
|
+
'name',
|
|
8998
|
+
'brand',
|
|
8999
|
+
'slug',
|
|
9000
|
+
'images',
|
|
9001
|
+
'grade',
|
|
9002
|
+
'gender',
|
|
9003
|
+
'',
|
|
9004
|
+
],
|
|
7945
9005
|
},
|
|
7946
9006
|
},
|
|
7947
9007
|
],
|
|
@@ -7986,6 +9046,33 @@ tslib.__decorate([
|
|
|
7986
9046
|
tslib.__metadata("design:returntype", void 0)
|
|
7987
9047
|
], ProductReviewHasuraGraphQLRepository.prototype, "disaproveReview", null);
|
|
7988
9048
|
|
|
9049
|
+
class ProductStockEntryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
9050
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
9051
|
+
super({
|
|
9052
|
+
tableName: 'product_millenium_stock_entry',
|
|
9053
|
+
model: ProductStockEntry,
|
|
9054
|
+
endpoint,
|
|
9055
|
+
authOptions,
|
|
9056
|
+
interceptors,
|
|
9057
|
+
cache,
|
|
9058
|
+
fields: [
|
|
9059
|
+
'id',
|
|
9060
|
+
{ productId: { columnName: 'product_id' } },
|
|
9061
|
+
{ codProduct: { columnName: 'cod_product' } },
|
|
9062
|
+
{ productDescription: { columnName: 'product_description' } },
|
|
9063
|
+
{ eventDescription: { columnName: 'event_description' } },
|
|
9064
|
+
{ invoiceValue: { columnName: 'invoice_value' } },
|
|
9065
|
+
'price',
|
|
9066
|
+
'quantity',
|
|
9067
|
+
{ invoiceId: { columnName: 'invoice_id' } },
|
|
9068
|
+
{ nfeKey: { columnName: 'nfe_key' } },
|
|
9069
|
+
'batch',
|
|
9070
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
9071
|
+
],
|
|
9072
|
+
});
|
|
9073
|
+
}
|
|
9074
|
+
}
|
|
9075
|
+
|
|
7989
9076
|
class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7990
9077
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
7991
9078
|
super({
|
|
@@ -8134,12 +9221,153 @@ const fieldsConfiguration$1 = [
|
|
|
8134
9221
|
},
|
|
8135
9222
|
},
|
|
8136
9223
|
'group',
|
|
9224
|
+
{ groupId: { columnName: 'group_id' } },
|
|
9225
|
+
'type',
|
|
8137
9226
|
'validity',
|
|
8138
|
-
// { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8139
9227
|
'published',
|
|
8140
9228
|
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8141
9229
|
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
9230
|
+
{ tagsSupply: { columnName: 'tags_supply', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8142
9231
|
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
9232
|
+
{
|
|
9233
|
+
images: {
|
|
9234
|
+
columnName: 'images',
|
|
9235
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
9236
|
+
},
|
|
9237
|
+
},
|
|
9238
|
+
{
|
|
9239
|
+
miniatures: {
|
|
9240
|
+
columnName: 'miniatures',
|
|
9241
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
9242
|
+
},
|
|
9243
|
+
},
|
|
9244
|
+
{
|
|
9245
|
+
imagesCard: {
|
|
9246
|
+
columnName: 'images_card',
|
|
9247
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
9248
|
+
},
|
|
9249
|
+
},
|
|
9250
|
+
'slug',
|
|
9251
|
+
'brand',
|
|
9252
|
+
'name',
|
|
9253
|
+
'sku',
|
|
9254
|
+
{ NCM: { columnName: 'ncm' } },
|
|
9255
|
+
{ CEST: { columnName: 'cest' } },
|
|
9256
|
+
{
|
|
9257
|
+
description: {
|
|
9258
|
+
columnName: 'description',
|
|
9259
|
+
from: (description, data) => ({
|
|
9260
|
+
description,
|
|
9261
|
+
differentials: data.differentials,
|
|
9262
|
+
whoMustUse: data.who_must_use,
|
|
9263
|
+
howToUse: data.how_to_use,
|
|
9264
|
+
brand: data.brand_description,
|
|
9265
|
+
ingredients: data.ingredients,
|
|
9266
|
+
purpose: data.purpose,
|
|
9267
|
+
}),
|
|
9268
|
+
bindFindFilter: (filters) => {
|
|
9269
|
+
return {
|
|
9270
|
+
...(filters?.description && { description: filters.description }),
|
|
9271
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
9272
|
+
...(filters.whoMustUse && {
|
|
9273
|
+
who_must_use: filters.whoMustUse,
|
|
9274
|
+
}),
|
|
9275
|
+
...(filters.howToUse && {
|
|
9276
|
+
how_to_use: filters.howToUse,
|
|
9277
|
+
}),
|
|
9278
|
+
...(filters.brand && {
|
|
9279
|
+
brand_description: filters.brand,
|
|
9280
|
+
}),
|
|
9281
|
+
...(filters.ingredients && {
|
|
9282
|
+
ingredients: filters.ingredients,
|
|
9283
|
+
}),
|
|
9284
|
+
...(filters.purpose && {
|
|
9285
|
+
purpose: filters.purpose,
|
|
9286
|
+
}),
|
|
9287
|
+
};
|
|
9288
|
+
},
|
|
9289
|
+
bindPersistData: (descriptionData) => ({
|
|
9290
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
9291
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
9292
|
+
...(descriptionData.whoMustUse && {
|
|
9293
|
+
who_must_use: descriptionData.whoMustUse,
|
|
9294
|
+
}),
|
|
9295
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
9296
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
9297
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
9298
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
9299
|
+
}),
|
|
9300
|
+
},
|
|
9301
|
+
},
|
|
9302
|
+
{ differentials: { columnName: 'differentials' } },
|
|
9303
|
+
{ whoMustUse: { columnName: 'who_must_use' } },
|
|
9304
|
+
{ howToUse: { columnName: 'how_to_use' } },
|
|
9305
|
+
{ brandDescription: { columnName: 'brand_description' } },
|
|
9306
|
+
{ ingredients: { columnName: 'ingredients' } },
|
|
9307
|
+
{ purpose: { columnName: 'purpose' } },
|
|
9308
|
+
'gender',
|
|
9309
|
+
{ intGender: { columnName: 'int_gender' } },
|
|
9310
|
+
'label',
|
|
9311
|
+
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
9312
|
+
{ rate: { columnName: 'rating' } },
|
|
9313
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
9314
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
9315
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
9316
|
+
{
|
|
9317
|
+
category: {
|
|
9318
|
+
columnName: 'category',
|
|
9319
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
9320
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
9321
|
+
},
|
|
9322
|
+
},
|
|
9323
|
+
{
|
|
9324
|
+
categories: {
|
|
9325
|
+
columnName: 'categories',
|
|
9326
|
+
fields: ['category_id'],
|
|
9327
|
+
bindPersistData: (value) => ({
|
|
9328
|
+
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
9329
|
+
}),
|
|
9330
|
+
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
9331
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
9332
|
+
},
|
|
9333
|
+
},
|
|
9334
|
+
{
|
|
9335
|
+
metadata: {
|
|
9336
|
+
columnName: 'metadata',
|
|
9337
|
+
fields: ['title', 'description'],
|
|
9338
|
+
bindPersistData: (value) => ({
|
|
9339
|
+
metadata: { data: value },
|
|
9340
|
+
}),
|
|
9341
|
+
},
|
|
9342
|
+
},
|
|
9343
|
+
{
|
|
9344
|
+
reviews: {
|
|
9345
|
+
columnName: 'reviews',
|
|
9346
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
9347
|
+
fields: [
|
|
9348
|
+
'id',
|
|
9349
|
+
'shop',
|
|
9350
|
+
'rate',
|
|
9351
|
+
'author',
|
|
9352
|
+
'email',
|
|
9353
|
+
'location',
|
|
9354
|
+
'review',
|
|
9355
|
+
'status',
|
|
9356
|
+
'title',
|
|
9357
|
+
{ personId: { columnName: 'person_id' } },
|
|
9358
|
+
'points',
|
|
9359
|
+
{ orderId: { columnName: 'order_id' } },
|
|
9360
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
9361
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
9362
|
+
],
|
|
9363
|
+
},
|
|
9364
|
+
},
|
|
9365
|
+
{ variantSlug: { columnName: 'variant_slug' } },
|
|
9366
|
+
{ caixariaMinima: { columnName: 'caixaria_minima', type: HasuraGraphQLColumnType.Jsonb } },
|
|
9367
|
+
'suppliers',
|
|
9368
|
+
'curve',
|
|
9369
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
9370
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
8143
9371
|
];
|
|
8144
9372
|
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8145
9373
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
@@ -8180,17 +9408,45 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8180
9408
|
return data.at(0);
|
|
8181
9409
|
}
|
|
8182
9410
|
async update(params) {
|
|
8183
|
-
const { productId, id: checkId, ...data } = params;
|
|
9411
|
+
const { productId, id: checkId, metadata, ...data } = params;
|
|
8184
9412
|
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
8185
9413
|
if (!dataWithProductId.id) {
|
|
8186
9414
|
throw new NotFoundError('Variant ID is required for update');
|
|
8187
9415
|
}
|
|
8188
9416
|
const id = await this.getId(dataWithProductId.id);
|
|
8189
9417
|
const product = await super.update({ id, ...data });
|
|
9418
|
+
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
8190
9419
|
if (dataWithProductId.productId) {
|
|
8191
9420
|
product.productId = dataWithProductId.productId;
|
|
8192
9421
|
}
|
|
8193
|
-
return product;
|
|
9422
|
+
return product;
|
|
9423
|
+
}
|
|
9424
|
+
async updateMetadata(productId, { metadata }) {
|
|
9425
|
+
const plainData = this.paramsToPlain({ metadata });
|
|
9426
|
+
if (!plainData.metadata)
|
|
9427
|
+
return null;
|
|
9428
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
9429
|
+
const { update_product_metadata_by_pk } = await this.mutation('update_product_metadata_by_pk', ['product_id'], {
|
|
9430
|
+
pk_columns: {
|
|
9431
|
+
value: { product_id: productId },
|
|
9432
|
+
type: 'product_metadata_pk_columns_input',
|
|
9433
|
+
required: true,
|
|
9434
|
+
},
|
|
9435
|
+
_set: {
|
|
9436
|
+
value: lodash.omit(metadata, ['product_id']),
|
|
9437
|
+
type: 'product_metadata_set_input',
|
|
9438
|
+
required: true,
|
|
9439
|
+
},
|
|
9440
|
+
});
|
|
9441
|
+
if (!update_product_metadata_by_pk) {
|
|
9442
|
+
await this.mutation('insert_product_metadata', ['affected_rows'], {
|
|
9443
|
+
objects: {
|
|
9444
|
+
type: '[product_metadata_insert_input!]!',
|
|
9445
|
+
value: [{ product_id: productId, ...metadata }],
|
|
9446
|
+
},
|
|
9447
|
+
});
|
|
9448
|
+
}
|
|
9449
|
+
return plainData.metadata;
|
|
8194
9450
|
}
|
|
8195
9451
|
async getId(id) {
|
|
8196
9452
|
if (!Number.isNaN(+id))
|
|
@@ -8413,124 +9669,670 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8413
9669
|
async getCategoryBySlug(slug, _shop) {
|
|
8414
9670
|
return this.getWishlistBySlug(slug);
|
|
8415
9671
|
}
|
|
8416
|
-
async getCategoryByShop(shop) {
|
|
8417
|
-
if (!shop)
|
|
8418
|
-
return;
|
|
8419
|
-
const { data } = await this.find({
|
|
8420
|
-
filters: {
|
|
8421
|
-
shops: { operator: exports.Where.IN, value: [shop] },
|
|
8422
|
-
published: { operator: exports.Where.EQUALS, value: true },
|
|
8423
|
-
isWishlist: { operator: exports.Where.EQUALS, value: true },
|
|
8424
|
-
},
|
|
8425
|
-
options: {
|
|
8426
|
-
enableCount: false,
|
|
9672
|
+
async getCategoryByShop(shop) {
|
|
9673
|
+
if (!shop)
|
|
9674
|
+
return;
|
|
9675
|
+
const { data } = await this.find({
|
|
9676
|
+
filters: {
|
|
9677
|
+
shops: { operator: exports.Where.IN, value: [shop] },
|
|
9678
|
+
published: { operator: exports.Where.EQUALS, value: true },
|
|
9679
|
+
isWishlist: { operator: exports.Where.EQUALS, value: true },
|
|
9680
|
+
},
|
|
9681
|
+
options: {
|
|
9682
|
+
enableCount: false,
|
|
9683
|
+
},
|
|
9684
|
+
});
|
|
9685
|
+
return data;
|
|
9686
|
+
}
|
|
9687
|
+
async findBfluOrGlamgirlWishlists(params, shops) {
|
|
9688
|
+
return this.find({
|
|
9689
|
+
...params,
|
|
9690
|
+
filters: {
|
|
9691
|
+
...params.filters,
|
|
9692
|
+
published: true,
|
|
9693
|
+
shops: { operator: exports.Where.LIKE, value: shops },
|
|
9694
|
+
personType: params.filters?.personType ?? {
|
|
9695
|
+
operator: exports.Where.IN,
|
|
9696
|
+
value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
|
|
9697
|
+
},
|
|
9698
|
+
},
|
|
9699
|
+
orderBy: {
|
|
9700
|
+
personHasPhoto: 'desc',
|
|
9701
|
+
...lodash.omit(params.orderBy, ['personHasPhoto']),
|
|
9702
|
+
},
|
|
9703
|
+
});
|
|
9704
|
+
}
|
|
9705
|
+
getCategoriesForHome() {
|
|
9706
|
+
return;
|
|
9707
|
+
}
|
|
9708
|
+
mountCategory() {
|
|
9709
|
+
return;
|
|
9710
|
+
}
|
|
9711
|
+
getChildren(_parentId) {
|
|
9712
|
+
return;
|
|
9713
|
+
}
|
|
9714
|
+
isChild(_id, _parentId) {
|
|
9715
|
+
return;
|
|
9716
|
+
}
|
|
9717
|
+
async updateMetadata(categoryId, { metadatas }) {
|
|
9718
|
+
if (Array.isArray(metadatas) && !metadatas.length)
|
|
9719
|
+
return [];
|
|
9720
|
+
if (Array.isArray(metadatas) && metadatas.length) {
|
|
9721
|
+
const metadataUpdated = [];
|
|
9722
|
+
for (const data of metadatas) {
|
|
9723
|
+
const update = await this.mutation('update_category_metadata_by_pk', ['category_id', 'shop'], {
|
|
9724
|
+
pk_columns: {
|
|
9725
|
+
value: { category_id: categoryId, shop: data.shop },
|
|
9726
|
+
type: 'category_metadata_pk_columns_input',
|
|
9727
|
+
required: true,
|
|
9728
|
+
},
|
|
9729
|
+
_set: {
|
|
9730
|
+
value: lodash.omit(data, ['category_id', 'shop']),
|
|
9731
|
+
type: 'category_metadata_set_input',
|
|
9732
|
+
required: true,
|
|
9733
|
+
},
|
|
9734
|
+
});
|
|
9735
|
+
metadataUpdated.push(update);
|
|
9736
|
+
}
|
|
9737
|
+
return metadataUpdated;
|
|
9738
|
+
}
|
|
9739
|
+
if ('action' in metadatas && metadatas.action === 'remove' && metadatas.value.length) {
|
|
9740
|
+
for (let i = 0; i < metadatas.value.length; i++) {
|
|
9741
|
+
await this.mutation('delete_category_metadata', ['affected_rows'], {
|
|
9742
|
+
where: {
|
|
9743
|
+
type: 'category_metadata_bool_exp',
|
|
9744
|
+
required: true,
|
|
9745
|
+
value: { category_id: { _eq: categoryId }, shop: metadatas.value[i].shop },
|
|
9746
|
+
},
|
|
9747
|
+
});
|
|
9748
|
+
}
|
|
9749
|
+
return [];
|
|
9750
|
+
}
|
|
9751
|
+
}
|
|
9752
|
+
async addProduct(wishlistId, productId) {
|
|
9753
|
+
await this.categoryProductRepository.create({
|
|
9754
|
+
categoryId: +wishlistId,
|
|
9755
|
+
productId: +productId,
|
|
9756
|
+
order: 0,
|
|
9757
|
+
});
|
|
9758
|
+
}
|
|
9759
|
+
async removeProduct(wishlistId, productId) {
|
|
9760
|
+
return this.categoryProductRepository.delete({
|
|
9761
|
+
categoryId: +wishlistId,
|
|
9762
|
+
productId: +productId,
|
|
9763
|
+
});
|
|
9764
|
+
}
|
|
9765
|
+
async getBrandsWithProducts() {
|
|
9766
|
+
return;
|
|
9767
|
+
}
|
|
9768
|
+
}
|
|
9769
|
+
tslib.__decorate([
|
|
9770
|
+
Log(),
|
|
9771
|
+
tslib.__metadata("design:type", Function),
|
|
9772
|
+
tslib.__metadata("design:paramtypes", [String]),
|
|
9773
|
+
tslib.__metadata("design:returntype", Promise)
|
|
9774
|
+
], WishlistHasuraGraphQLRepository.prototype, "getWishlistBySlug", null);
|
|
9775
|
+
tslib.__decorate([
|
|
9776
|
+
Log(),
|
|
9777
|
+
tslib.__metadata("design:type", Function),
|
|
9778
|
+
tslib.__metadata("design:paramtypes", [String]),
|
|
9779
|
+
tslib.__metadata("design:returntype", Promise)
|
|
9780
|
+
], WishlistHasuraGraphQLRepository.prototype, "getWishlistByPerson", null);
|
|
9781
|
+
tslib.__decorate([
|
|
9782
|
+
Log(),
|
|
9783
|
+
tslib.__metadata("design:type", Function),
|
|
9784
|
+
tslib.__metadata("design:paramtypes", [String]),
|
|
9785
|
+
tslib.__metadata("design:returntype", Promise)
|
|
9786
|
+
], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
|
|
9787
|
+
tslib.__decorate([
|
|
9788
|
+
Log(),
|
|
9789
|
+
tslib.__metadata("design:type", Function),
|
|
9790
|
+
tslib.__metadata("design:paramtypes", [Object, Array]),
|
|
9791
|
+
tslib.__metadata("design:returntype", Promise)
|
|
9792
|
+
], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
|
|
9793
|
+
|
|
9794
|
+
class MercadoPagoErrorHelper {
|
|
9795
|
+
static getErrorTypeFromResponse(errorCode) {
|
|
9796
|
+
switch (errorCode) {
|
|
9797
|
+
case 'bad_filled_card_data':
|
|
9798
|
+
case 'invalid_card_token':
|
|
9799
|
+
case 'card_disabled':
|
|
9800
|
+
case 'cc_rejected_card_disabled':
|
|
9801
|
+
case 'cc_rejected_bad_filled_card_number':
|
|
9802
|
+
case 'cc_rejected_bad_filled_date':
|
|
9803
|
+
case 'cc_rejected_bad_filled_other':
|
|
9804
|
+
case 'cc_rejected_bad_filled_security_code':
|
|
9805
|
+
return exports.ErrorsCode.invalidCardError;
|
|
9806
|
+
case 'high_risk':
|
|
9807
|
+
case 'rejected_high_risk':
|
|
9808
|
+
case 'cc_rejected_blacklist':
|
|
9809
|
+
case 'cc_rejected_call_for_authorize':
|
|
9810
|
+
case 'cc_rejected_high_risk':
|
|
9811
|
+
return exports.ErrorsCode.fraudPreventionExternal;
|
|
9812
|
+
case 'rejected_by_issuer':
|
|
9813
|
+
case 'rejected_by_bank':
|
|
9814
|
+
case 'cc_rejected_max_attempts':
|
|
9815
|
+
case 'required_call_for_authorize':
|
|
9816
|
+
case 'max_attempts_exceeded':
|
|
9817
|
+
return exports.ErrorsCode.paymentNotAuthorizedError;
|
|
9818
|
+
case 'insufficient_amount':
|
|
9819
|
+
case 'amount_limit_exceeded':
|
|
9820
|
+
case 'cc_rejected_insufficient_amount':
|
|
9821
|
+
return exports.ErrorsCode.insufficientFundsError;
|
|
9822
|
+
case 'processing_error':
|
|
9823
|
+
return exports.ErrorsCode.paymentError;
|
|
9824
|
+
case 'invalid_installments':
|
|
9825
|
+
case 'cc_rejected_invalid_installments':
|
|
9826
|
+
case 'cc_rejected_other_reason':
|
|
9827
|
+
case 'rejected_insufficient_data':
|
|
9828
|
+
return exports.ErrorsCode.businessError;
|
|
9829
|
+
default:
|
|
9830
|
+
return exports.ErrorsCode.paymentError;
|
|
9831
|
+
}
|
|
9832
|
+
}
|
|
9833
|
+
}
|
|
9834
|
+
|
|
9835
|
+
class MercadoPagoRequestHelper {
|
|
9836
|
+
static build(data) {
|
|
9837
|
+
const { checkout, method, postback, card } = data;
|
|
9838
|
+
return {
|
|
9839
|
+
transaction_amount: +checkout.totalPrice.toFixed(2),
|
|
9840
|
+
notification_url: postback,
|
|
9841
|
+
metadata: {
|
|
9842
|
+
checkoutId: checkout.id,
|
|
9843
|
+
},
|
|
9844
|
+
payer: this.buildPayer(checkout, card),
|
|
9845
|
+
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'loja glam' : 'mens market',
|
|
9846
|
+
additional_info: {
|
|
9847
|
+
items: this.buildItems(checkout),
|
|
9848
|
+
},
|
|
9849
|
+
...(method === 'credit_card' && this.buildCardPayment(card)),
|
|
9850
|
+
...(method === 'pix' && this.buildPixPayment()),
|
|
9851
|
+
...(method === 'boleto' && this.buildBoletoPayment(checkout)),
|
|
9852
|
+
};
|
|
9853
|
+
}
|
|
9854
|
+
static buildItems(checkout) {
|
|
9855
|
+
return checkout.lineItems
|
|
9856
|
+
.filter((item) => !item.isGift)
|
|
9857
|
+
.map((item) => {
|
|
9858
|
+
return {
|
|
9859
|
+
id: item.EAN,
|
|
9860
|
+
title: item.name,
|
|
9861
|
+
description: item.name,
|
|
9862
|
+
picture_url: item.image ?? null,
|
|
9863
|
+
category_id: item.category?.id ?? null,
|
|
9864
|
+
quantity: item.quantity,
|
|
9865
|
+
unit_price: +item.pricePaid.toFixed(2),
|
|
9866
|
+
};
|
|
9867
|
+
});
|
|
9868
|
+
}
|
|
9869
|
+
static buildPayer(checkout, card) {
|
|
9870
|
+
return {
|
|
9871
|
+
...(card && { id: card.customerId }),
|
|
9872
|
+
first_name: checkout.user.firstName,
|
|
9873
|
+
last_name: checkout.user.lastName,
|
|
9874
|
+
email: checkout.user.email,
|
|
9875
|
+
identification: {
|
|
9876
|
+
type: 'CPF',
|
|
9877
|
+
number: checkout.user.cpf.replace(/\D/g, ''),
|
|
9878
|
+
},
|
|
9879
|
+
};
|
|
9880
|
+
}
|
|
9881
|
+
static buildFullPayer(checkout) {
|
|
9882
|
+
return {
|
|
9883
|
+
first_name: checkout.user.firstName,
|
|
9884
|
+
last_name: checkout.user.lastName,
|
|
9885
|
+
phone: {
|
|
9886
|
+
area_code: checkout.user.phone.substring(0, 2),
|
|
9887
|
+
number: checkout.user.phone.substring(2),
|
|
9888
|
+
},
|
|
9889
|
+
address: {
|
|
9890
|
+
zip_code: checkout.shippingAddress.zip,
|
|
9891
|
+
street_name: `${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
9892
|
+
street_number: checkout.shippingAddress.number,
|
|
9893
|
+
neighborhood: checkout.shippingAddress.district,
|
|
9894
|
+
city: checkout.shippingAddress.city,
|
|
9895
|
+
federal_unit: checkout.shippingAddress.state,
|
|
9896
|
+
},
|
|
9897
|
+
};
|
|
9898
|
+
}
|
|
9899
|
+
static buildCardPayment(card) {
|
|
9900
|
+
return {
|
|
9901
|
+
installments: card.installments,
|
|
9902
|
+
token: card.cardId,
|
|
9903
|
+
binary_mode: true,
|
|
9904
|
+
capture: true,
|
|
9905
|
+
};
|
|
9906
|
+
}
|
|
9907
|
+
static buildPixPayment() {
|
|
9908
|
+
return {
|
|
9909
|
+
payment_method_id: 'pix',
|
|
9910
|
+
date_of_expiration: dateFns.format(dateFns.addHours(new Date(), 24), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx"),
|
|
9911
|
+
};
|
|
9912
|
+
}
|
|
9913
|
+
static buildBoletoPayment(checkout) {
|
|
9914
|
+
return {
|
|
9915
|
+
payment_method_id: 'bolbradesco',
|
|
9916
|
+
date_of_expiration: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd') + 'T23:59:59.999-03:00',
|
|
9917
|
+
payer: {
|
|
9918
|
+
first_name: checkout.user.firstName,
|
|
9919
|
+
last_name: checkout.user.lastName,
|
|
9920
|
+
email: checkout.user.email,
|
|
9921
|
+
identification: {
|
|
9922
|
+
type: 'CPF',
|
|
9923
|
+
number: checkout.user.cpf.replace(/\D/g, ''),
|
|
9924
|
+
},
|
|
9925
|
+
phone: {
|
|
9926
|
+
area_code: checkout.user.phone.substring(0, 2),
|
|
9927
|
+
number: checkout.user.phone.substring(2),
|
|
9928
|
+
},
|
|
9929
|
+
address: {
|
|
9930
|
+
zip_code: checkout.shippingAddress.zip.replace(/\D/g, ''),
|
|
9931
|
+
street_name: `${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
9932
|
+
street_number: checkout.shippingAddress.number,
|
|
9933
|
+
neighborhood: checkout.shippingAddress.district,
|
|
9934
|
+
city: checkout.shippingAddress.city,
|
|
9935
|
+
federal_unit: checkout.shippingAddress.state,
|
|
9936
|
+
},
|
|
9937
|
+
},
|
|
9938
|
+
};
|
|
9939
|
+
}
|
|
9940
|
+
}
|
|
9941
|
+
|
|
9942
|
+
class MercadoPagoResponseHelper {
|
|
9943
|
+
static build(method, checkout, response) {
|
|
9944
|
+
return Payment.toInstance({
|
|
9945
|
+
createdAt: new Date(),
|
|
9946
|
+
updatedAt: new Date(),
|
|
9947
|
+
userId: checkout.user.id,
|
|
9948
|
+
checkoutId: checkout.id,
|
|
9949
|
+
totalPrice: checkout.totalPrice,
|
|
9950
|
+
paymentProvider: exports.PaymentProviders.MERCADOPAGO,
|
|
9951
|
+
mercadoPagoId: response.id,
|
|
9952
|
+
transaction: this.buildPaymentTransaction(method, response),
|
|
9953
|
+
});
|
|
9954
|
+
}
|
|
9955
|
+
static buildPaymentTransaction(method, response) {
|
|
9956
|
+
return PaymentTransaction.toInstance({
|
|
9957
|
+
id: response.id.toString(),
|
|
9958
|
+
acquirer_name: exports.PaymentProviders.MERCADOPAGO,
|
|
9959
|
+
amount: response.transaction_amount,
|
|
9960
|
+
status: this.statusMapping(response.status),
|
|
9961
|
+
status_reason: response.status_detail?.toString(),
|
|
9962
|
+
payment_method: method,
|
|
9963
|
+
currency: response.currency_id?.toString(),
|
|
9964
|
+
paid_amount: response.transaction_details?.total_paid_amount ?? null,
|
|
9965
|
+
paid_at: response.date_approved ?? null,
|
|
9966
|
+
charger_id: response.charges_details?.at(0)?.id?.toString() ?? null,
|
|
9967
|
+
...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(response)),
|
|
9968
|
+
...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(response)),
|
|
9969
|
+
...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(response)),
|
|
9970
|
+
});
|
|
9971
|
+
}
|
|
9972
|
+
static getBoletoReponse(response) {
|
|
9973
|
+
return {
|
|
9974
|
+
boleto_url: response.transaction_details?.external_resource_url?.toString(),
|
|
9975
|
+
boleto_barcode: response.transaction_details?.barcode?.content?.toString(),
|
|
9976
|
+
boleto_line: response.transaction_details?.digitable_line?.toString(),
|
|
9977
|
+
boleto_expiration_date: response.date_of_expiration?.toString(),
|
|
9978
|
+
boleto_document_number: response.transaction_details?.verification_code?.toString(),
|
|
9979
|
+
};
|
|
9980
|
+
}
|
|
9981
|
+
static getPixReponse(response) {
|
|
9982
|
+
return {
|
|
9983
|
+
pix_qr_code: response.point_of_interaction?.transaction_data?.qr_code,
|
|
9984
|
+
pix_expiration_date: response.date_of_expiration?.toString(),
|
|
9985
|
+
};
|
|
9986
|
+
}
|
|
9987
|
+
static getCardReponse(response) {
|
|
9988
|
+
return {
|
|
9989
|
+
soft_descriptor: response.statement_descriptor?.toString(),
|
|
9990
|
+
installments: response.installments,
|
|
9991
|
+
card_brand: response.payment_method_id?.toString(),
|
|
9992
|
+
card_first_digits: response.card?.first_six_digits?.toString(),
|
|
9993
|
+
card_last_digits: response.card?.last_four_digits?.toString(),
|
|
9994
|
+
card_id: response.card?.id?.toString(),
|
|
9995
|
+
card_holder_name: response.card?.cardholder?.name?.toString(),
|
|
9996
|
+
card_expiration_month: response.card?.expiration_month?.toString(),
|
|
9997
|
+
card_expiration_year: response.card?.expiration_year?.toString(),
|
|
9998
|
+
capture_method: response.payment_type_id?.toString(),
|
|
9999
|
+
authorization_code: response.authorization_code?.toString(),
|
|
10000
|
+
paid_amount: this.statusMapping(response.status) == 'paid' ? response.transaction_details?.total_paid_amount : null,
|
|
10001
|
+
paid_at: this.statusMapping(response.status) == 'paid' ? response.date_approved : null,
|
|
10002
|
+
};
|
|
10003
|
+
}
|
|
10004
|
+
static statusMapping(status) {
|
|
10005
|
+
const statusMap = {
|
|
10006
|
+
approved: 'paid',
|
|
10007
|
+
pending: 'waiting_payment',
|
|
10008
|
+
in_process: 'processing',
|
|
10009
|
+
rejected: 'refused',
|
|
10010
|
+
cancelled: 'refused',
|
|
10011
|
+
refunded: 'refunded',
|
|
10012
|
+
charged_back: 'chargedback',
|
|
10013
|
+
};
|
|
10014
|
+
return statusMap[status] || status;
|
|
10015
|
+
}
|
|
10016
|
+
}
|
|
10017
|
+
|
|
10018
|
+
class MercadoPagoBankSlipAxiosAdapter {
|
|
10019
|
+
constructor(credentials, paymentRepository) {
|
|
10020
|
+
this.credentials = credentials;
|
|
10021
|
+
this.paymentRepository = paymentRepository;
|
|
10022
|
+
}
|
|
10023
|
+
async pay(checkout) {
|
|
10024
|
+
try {
|
|
10025
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
10026
|
+
checkout,
|
|
10027
|
+
method: 'boleto',
|
|
10028
|
+
postback: this.credentials.postback,
|
|
10029
|
+
});
|
|
10030
|
+
console.warn('[MERCADO PAGO BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
10031
|
+
const { data } = await axios__default["default"]({
|
|
10032
|
+
method: 'POST',
|
|
10033
|
+
url: `${this.credentials.url}/v1/payments`,
|
|
10034
|
+
headers: {
|
|
10035
|
+
'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
|
|
10036
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10037
|
+
'Content-Type': 'application/json',
|
|
10038
|
+
},
|
|
10039
|
+
data: payload,
|
|
10040
|
+
});
|
|
10041
|
+
console.warn('[MERCADO PAGO RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
10042
|
+
const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
|
|
10043
|
+
return payment;
|
|
10044
|
+
}
|
|
10045
|
+
catch (error) {
|
|
10046
|
+
if (error instanceof axios.AxiosError) {
|
|
10047
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
10048
|
+
}
|
|
10049
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
10050
|
+
checkoutId: checkout.id,
|
|
10051
|
+
userEmail: checkout.user.email,
|
|
10052
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
10053
|
+
});
|
|
10054
|
+
}
|
|
10055
|
+
}
|
|
10056
|
+
getBoletoTransaction(paymentId) {
|
|
10057
|
+
throw new Error('Method not implemented.');
|
|
10058
|
+
}
|
|
10059
|
+
}
|
|
10060
|
+
|
|
10061
|
+
exports.MercadoPagoStatusDetailEnum = void 0;
|
|
10062
|
+
(function (MercadoPagoStatusDetailEnum) {
|
|
10063
|
+
MercadoPagoStatusDetailEnum["accredited"] = "accredited";
|
|
10064
|
+
MercadoPagoStatusDetailEnum["partially_refunded"] = "partially_refunded";
|
|
10065
|
+
MercadoPagoStatusDetailEnum["pending_capture"] = "pending_capture";
|
|
10066
|
+
MercadoPagoStatusDetailEnum["offline_process"] = "offline_process";
|
|
10067
|
+
MercadoPagoStatusDetailEnum["pending_contingency"] = "pending_contingency";
|
|
10068
|
+
MercadoPagoStatusDetailEnum["pending_review_manual"] = "pending_review_manual";
|
|
10069
|
+
MercadoPagoStatusDetailEnum["pending_waiting_transfer"] = "pending_waiting_transfer";
|
|
10070
|
+
MercadoPagoStatusDetailEnum["pending_waiting_payment"] = "pending_waiting_payment";
|
|
10071
|
+
MercadoPagoStatusDetailEnum["pending_challenge"] = "pending_challenge";
|
|
10072
|
+
MercadoPagoStatusDetailEnum["bank_error"] = "bank_error";
|
|
10073
|
+
MercadoPagoStatusDetailEnum["cc_rejected_3ds_mandatory"] = "cc_rejected_3ds_mandatory";
|
|
10074
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_card_number"] = "cc_rejected_bad_filled_card_number";
|
|
10075
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_date"] = "cc_rejected_bad_filled_date";
|
|
10076
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_other"] = "cc_rejected_bad_filled_other";
|
|
10077
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_security_code"] = "cc_rejected_bad_filled_security_code";
|
|
10078
|
+
MercadoPagoStatusDetailEnum["cc_rejected_blacklist"] = "cc_rejected_blacklist";
|
|
10079
|
+
MercadoPagoStatusDetailEnum["cc_rejected_call_for_authorize"] = "cc_rejected_call_for_authorize";
|
|
10080
|
+
MercadoPagoStatusDetailEnum["cc_rejected_card_disabled"] = "cc_rejected_card_disabled";
|
|
10081
|
+
MercadoPagoStatusDetailEnum["cc_rejected_card_error"] = "cc_rejected_card_error";
|
|
10082
|
+
MercadoPagoStatusDetailEnum["cc_rejected_duplicated_payment"] = "cc_rejected_duplicated_payment";
|
|
10083
|
+
MercadoPagoStatusDetailEnum["cc_rejected_high_risk"] = "cc_rejected_high_risk";
|
|
10084
|
+
MercadoPagoStatusDetailEnum["cc_rejected_insufficient_amount"] = "cc_rejected_insufficient_amount";
|
|
10085
|
+
MercadoPagoStatusDetailEnum["cc_rejected_invalid_installments"] = "cc_rejected_invalid_installments";
|
|
10086
|
+
MercadoPagoStatusDetailEnum["cc_rejected_max_attempts"] = "cc_rejected_max_attempts";
|
|
10087
|
+
MercadoPagoStatusDetailEnum["cc_rejected_other_reason"] = "cc_rejected_other_reason";
|
|
10088
|
+
MercadoPagoStatusDetailEnum["cc_amount_rate_limit_exceeded"] = "cc_amount_rate_limit_exceeded";
|
|
10089
|
+
MercadoPagoStatusDetailEnum["rejected_insufficient_data"] = "rejected_insufficient_data";
|
|
10090
|
+
MercadoPagoStatusDetailEnum["rejected_by_bank"] = "rejected_by_bank";
|
|
10091
|
+
MercadoPagoStatusDetailEnum["rejected_by_regulations"] = "rejected_by_regulations";
|
|
10092
|
+
MercadoPagoStatusDetailEnum["insufficient_amount"] = "insufficient_amount";
|
|
10093
|
+
MercadoPagoStatusDetailEnum["cc_rejected_card_type_not_allowed"] = "cc_rejected_card_type_not_allowed";
|
|
10094
|
+
})(exports.MercadoPagoStatusDetailEnum || (exports.MercadoPagoStatusDetailEnum = {}));
|
|
10095
|
+
|
|
10096
|
+
exports.MercadoPagoStatusEnum = void 0;
|
|
10097
|
+
(function (MercadoPagoStatusEnum) {
|
|
10098
|
+
MercadoPagoStatusEnum["approved"] = "approved";
|
|
10099
|
+
MercadoPagoStatusEnum["authorized"] = "authorized";
|
|
10100
|
+
MercadoPagoStatusEnum["pending"] = "pending";
|
|
10101
|
+
MercadoPagoStatusEnum["in_process"] = "in_process";
|
|
10102
|
+
MercadoPagoStatusEnum["rejected"] = "rejected";
|
|
10103
|
+
MercadoPagoStatusEnum["cancelled"] = "cancelled";
|
|
10104
|
+
MercadoPagoStatusEnum["refunded"] = "refunded";
|
|
10105
|
+
MercadoPagoStatusEnum["charged_back"] = "charged_back";
|
|
10106
|
+
})(exports.MercadoPagoStatusEnum || (exports.MercadoPagoStatusEnum = {}));
|
|
10107
|
+
|
|
10108
|
+
class MercadoPagoBaseAxiosAdapter {
|
|
10109
|
+
constructor(credentials, paymentRepository) {
|
|
10110
|
+
this.credentials = credentials;
|
|
10111
|
+
this.paymentRepository = paymentRepository;
|
|
10112
|
+
}
|
|
10113
|
+
async refund(order, amount) {
|
|
10114
|
+
const { data } = await axios__default["default"]({
|
|
10115
|
+
method: 'POST',
|
|
10116
|
+
url: `${this.credentials.url}/v1/payments/${order.payment.id}/refunds`,
|
|
10117
|
+
headers: {
|
|
10118
|
+
'X-Idempotency-Key': `${order.payment.charger_id}-${new Date().getTime()}`,
|
|
10119
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10120
|
+
'Content-Type': 'application/json',
|
|
10121
|
+
},
|
|
10122
|
+
data: {
|
|
10123
|
+
amount: +amount.toFixed(2),
|
|
10124
|
+
},
|
|
10125
|
+
});
|
|
10126
|
+
await this.paymentRepository.create({
|
|
10127
|
+
createdAt: new Date(),
|
|
10128
|
+
updatedAt: new Date(),
|
|
10129
|
+
userId: order.user.id,
|
|
10130
|
+
orderId: order.id,
|
|
10131
|
+
totalPrice: amount,
|
|
10132
|
+
paymentProvider: exports.PaymentProviders.MERCADOPAGO,
|
|
10133
|
+
mercadoPagoId: data.id,
|
|
10134
|
+
transaction: data,
|
|
10135
|
+
});
|
|
10136
|
+
console.warn('[RESPONSE MERCADO PAGO REFUND]', JSON.stringify(data));
|
|
10137
|
+
return {
|
|
10138
|
+
status: this.getRefundStatus(data.status),
|
|
10139
|
+
success: [
|
|
10140
|
+
exports.MercadoPagoStatusEnum.approved,
|
|
10141
|
+
exports.MercadoPagoStatusEnum.refunded,
|
|
10142
|
+
exports.MercadoPagoStatusEnum.cancelled,
|
|
10143
|
+
exports.MercadoPagoStatusEnum.authorized,
|
|
10144
|
+
].includes(data.status)
|
|
10145
|
+
? true
|
|
10146
|
+
: false,
|
|
10147
|
+
};
|
|
10148
|
+
}
|
|
10149
|
+
getRefundStatus(status) {
|
|
10150
|
+
if ([exports.MercadoPagoStatusEnum.in_process, exports.MercadoPagoStatusEnum.pending].includes(status)) {
|
|
10151
|
+
return 'processing';
|
|
10152
|
+
}
|
|
10153
|
+
if ([
|
|
10154
|
+
exports.MercadoPagoStatusEnum.approved,
|
|
10155
|
+
exports.MercadoPagoStatusEnum.refunded,
|
|
10156
|
+
exports.MercadoPagoStatusEnum.cancelled,
|
|
10157
|
+
exports.MercadoPagoStatusEnum.authorized,
|
|
10158
|
+
].includes(status)) {
|
|
10159
|
+
return 'success';
|
|
10160
|
+
}
|
|
10161
|
+
return 'unknown';
|
|
10162
|
+
}
|
|
10163
|
+
}
|
|
10164
|
+
|
|
10165
|
+
class MercadoPagoCardAxiosAdapter extends MercadoPagoBaseAxiosAdapter {
|
|
10166
|
+
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
10167
|
+
super(credentials, paymentRepository);
|
|
10168
|
+
this.credentials = credentials;
|
|
10169
|
+
this.paymentRepository = paymentRepository;
|
|
10170
|
+
this.orderBlockedRepository = orderBlockedRepository;
|
|
10171
|
+
}
|
|
10172
|
+
async pay(checkout, card) {
|
|
10173
|
+
try {
|
|
10174
|
+
const payload = await this.getPaymentPayload(checkout, card);
|
|
10175
|
+
console.warn('[MERCADO PAGO CARD DATA TO SEND]', JSON.stringify(payload));
|
|
10176
|
+
const data = await this.requestPayment(checkout, payload);
|
|
10177
|
+
console.warn('[MERCADO PAGO RESPONSE CARD DATA]', JSON.stringify(data));
|
|
10178
|
+
if (data.status == exports.MercadoPagoStatusEnum.rejected) {
|
|
10179
|
+
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
10180
|
+
checkout,
|
|
10181
|
+
blockType: 'Card not authorized',
|
|
10182
|
+
type: 'Card',
|
|
10183
|
+
limiteRange: 'day',
|
|
10184
|
+
card,
|
|
10185
|
+
gatewayInfo: {
|
|
10186
|
+
gateway: exports.PaymentProviders.MERCADOPAGO,
|
|
10187
|
+
status: data.status,
|
|
10188
|
+
statusDetail: data.status_detail,
|
|
10189
|
+
},
|
|
10190
|
+
});
|
|
10191
|
+
const errorCode = MercadoPagoErrorHelper.getErrorTypeFromResponse(data.status_detail);
|
|
10192
|
+
throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', errorCode, {
|
|
10193
|
+
checkoutId: checkout.id,
|
|
10194
|
+
userEmail: checkout.user.email,
|
|
10195
|
+
info: data,
|
|
10196
|
+
});
|
|
10197
|
+
}
|
|
10198
|
+
const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
|
|
10199
|
+
return payment;
|
|
10200
|
+
}
|
|
10201
|
+
catch (error) {
|
|
10202
|
+
if (error instanceof axios.AxiosError) {
|
|
10203
|
+
console.warn(JSON.stringify(error.response?.data?.message));
|
|
10204
|
+
throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', exports.ErrorsCode.paymentError, {
|
|
10205
|
+
checkoutId: checkout.id,
|
|
10206
|
+
userEmail: checkout.user.email,
|
|
10207
|
+
info: error.response?.data?.message || error.message?.toString(),
|
|
10208
|
+
});
|
|
10209
|
+
}
|
|
10210
|
+
throw error;
|
|
10211
|
+
}
|
|
10212
|
+
}
|
|
10213
|
+
async requestPayment(checkout, payload) {
|
|
10214
|
+
const { data } = await axios__default["default"]({
|
|
10215
|
+
method: 'POST',
|
|
10216
|
+
url: `${this.credentials.url}/v1/payments`,
|
|
10217
|
+
headers: {
|
|
10218
|
+
'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
|
|
10219
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10220
|
+
'Content-Type': 'application/json',
|
|
8427
10221
|
},
|
|
10222
|
+
data: payload,
|
|
8428
10223
|
});
|
|
8429
10224
|
return data;
|
|
8430
10225
|
}
|
|
8431
|
-
async
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
|
|
8441
|
-
},
|
|
8442
|
-
},
|
|
8443
|
-
orderBy: {
|
|
8444
|
-
personHasPhoto: 'desc',
|
|
8445
|
-
...lodash.omit(params.orderBy, ['personHasPhoto']),
|
|
10226
|
+
async getPaymentPayload(checkout, card) {
|
|
10227
|
+
const cardResponse = await this.getCardByToken(card.customerId, card.cardId, card.cardCvv);
|
|
10228
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
10229
|
+
checkout,
|
|
10230
|
+
method: 'credit_card',
|
|
10231
|
+
postback: this.credentials.postback,
|
|
10232
|
+
card: {
|
|
10233
|
+
...card,
|
|
10234
|
+
cardId: cardResponse.id,
|
|
8446
10235
|
},
|
|
8447
10236
|
});
|
|
10237
|
+
return payload;
|
|
8448
10238
|
}
|
|
8449
|
-
|
|
10239
|
+
async addCard(card, customer) {
|
|
8450
10240
|
return;
|
|
8451
10241
|
}
|
|
8452
|
-
|
|
8453
|
-
|
|
10242
|
+
async getCardByToken(customerId, token, cardCvv) {
|
|
10243
|
+
try {
|
|
10244
|
+
const payload = { cardId: token, customerId: customerId, securityCode: cardCvv };
|
|
10245
|
+
console.warn('payload getCardByToken', payload);
|
|
10246
|
+
const { data } = await axios__default["default"]({
|
|
10247
|
+
method: 'POST',
|
|
10248
|
+
url: `${this.credentials.url}/v1/card_tokens`,
|
|
10249
|
+
headers: {
|
|
10250
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10251
|
+
'Content-Type': 'application/json',
|
|
10252
|
+
},
|
|
10253
|
+
data: payload,
|
|
10254
|
+
});
|
|
10255
|
+
return data;
|
|
10256
|
+
}
|
|
10257
|
+
catch (error) {
|
|
10258
|
+
if (error instanceof axios.AxiosError) {
|
|
10259
|
+
console.warn(JSON.stringify(error.response.data.cause));
|
|
10260
|
+
}
|
|
10261
|
+
throw error;
|
|
10262
|
+
}
|
|
8454
10263
|
}
|
|
8455
|
-
|
|
10264
|
+
createCardHash(bu, shop, card) {
|
|
8456
10265
|
return;
|
|
8457
10266
|
}
|
|
8458
|
-
|
|
10267
|
+
createTransaction(info) {
|
|
8459
10268
|
return;
|
|
8460
10269
|
}
|
|
8461
|
-
async
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
|
|
8469
|
-
|
|
8470
|
-
|
|
8471
|
-
|
|
8472
|
-
|
|
8473
|
-
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
10270
|
+
async createOrUpdateCustomer(customer) {
|
|
10271
|
+
const { data } = await axios__default["default"]({
|
|
10272
|
+
method: 'POST',
|
|
10273
|
+
url: `${this.credentials.url}/v1/customers`,
|
|
10274
|
+
headers: {
|
|
10275
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10276
|
+
'Content-Type': 'application/json',
|
|
10277
|
+
},
|
|
10278
|
+
data: {
|
|
10279
|
+
email: customer.email,
|
|
10280
|
+
first_name: customer.firstName,
|
|
10281
|
+
last_name: customer.lastName,
|
|
10282
|
+
phone: {
|
|
10283
|
+
area_code: customer.phone.substring(0, 2),
|
|
10284
|
+
number: customer.phone.substring(2),
|
|
10285
|
+
},
|
|
10286
|
+
identification: {
|
|
10287
|
+
type: 'CPF',
|
|
10288
|
+
number: customer.cpf.replace(/\D/g, ''),
|
|
10289
|
+
},
|
|
10290
|
+
},
|
|
10291
|
+
});
|
|
10292
|
+
return data;
|
|
10293
|
+
}
|
|
10294
|
+
}
|
|
10295
|
+
|
|
10296
|
+
class MercadoPagoPixAxiosAdapter extends MercadoPagoBaseAxiosAdapter {
|
|
10297
|
+
constructor(credentials, paymentRepository) {
|
|
10298
|
+
super(credentials, paymentRepository);
|
|
10299
|
+
this.credentials = credentials;
|
|
10300
|
+
this.paymentRepository = paymentRepository;
|
|
10301
|
+
}
|
|
10302
|
+
async pay(checkout) {
|
|
10303
|
+
try {
|
|
10304
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
10305
|
+
checkout,
|
|
10306
|
+
method: 'pix',
|
|
10307
|
+
postback: this.credentials.postback,
|
|
10308
|
+
});
|
|
10309
|
+
console.warn('[MERCADO PAGO PIX DATA TO SEND]', JSON.stringify(payload));
|
|
10310
|
+
const { data } = await axios__default["default"]({
|
|
10311
|
+
method: 'POST',
|
|
10312
|
+
url: `${this.credentials.url}/v1/payments`,
|
|
10313
|
+
headers: {
|
|
10314
|
+
'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
|
|
10315
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
10316
|
+
'Content-Type': 'application/json',
|
|
10317
|
+
},
|
|
10318
|
+
data: payload,
|
|
10319
|
+
});
|
|
10320
|
+
console.warn('[MERCADO PAGO RESPONSE PIX DATA]', JSON.stringify(data));
|
|
10321
|
+
const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
|
|
10322
|
+
return payment;
|
|
8482
10323
|
}
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
-
where: {
|
|
8487
|
-
type: 'category_metadata_bool_exp',
|
|
8488
|
-
required: true,
|
|
8489
|
-
value: { category_id: { _eq: categoryId }, shop: metadatas.value[i].shop },
|
|
8490
|
-
},
|
|
8491
|
-
});
|
|
10324
|
+
catch (error) {
|
|
10325
|
+
if (error instanceof axios.AxiosError) {
|
|
10326
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
8492
10327
|
}
|
|
8493
|
-
|
|
10328
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', exports.ErrorsCode.paymentError, {
|
|
10329
|
+
checkoutId: checkout.id,
|
|
10330
|
+
userEmail: checkout.user.email,
|
|
10331
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
10332
|
+
});
|
|
8494
10333
|
}
|
|
8495
10334
|
}
|
|
8496
|
-
async addProduct(wishlistId, productId) {
|
|
8497
|
-
await this.categoryProductRepository.create({
|
|
8498
|
-
categoryId: +wishlistId,
|
|
8499
|
-
productId: +productId,
|
|
8500
|
-
order: 0,
|
|
8501
|
-
});
|
|
8502
|
-
}
|
|
8503
|
-
async removeProduct(wishlistId, productId) {
|
|
8504
|
-
return this.categoryProductRepository.delete({
|
|
8505
|
-
categoryId: +wishlistId,
|
|
8506
|
-
productId: +productId,
|
|
8507
|
-
});
|
|
8508
|
-
}
|
|
8509
10335
|
}
|
|
8510
|
-
tslib.__decorate([
|
|
8511
|
-
Log(),
|
|
8512
|
-
tslib.__metadata("design:type", Function),
|
|
8513
|
-
tslib.__metadata("design:paramtypes", [String]),
|
|
8514
|
-
tslib.__metadata("design:returntype", Promise)
|
|
8515
|
-
], WishlistHasuraGraphQLRepository.prototype, "getWishlistBySlug", null);
|
|
8516
|
-
tslib.__decorate([
|
|
8517
|
-
Log(),
|
|
8518
|
-
tslib.__metadata("design:type", Function),
|
|
8519
|
-
tslib.__metadata("design:paramtypes", [String]),
|
|
8520
|
-
tslib.__metadata("design:returntype", Promise)
|
|
8521
|
-
], WishlistHasuraGraphQLRepository.prototype, "getWishlistByPerson", null);
|
|
8522
|
-
tslib.__decorate([
|
|
8523
|
-
Log(),
|
|
8524
|
-
tslib.__metadata("design:type", Function),
|
|
8525
|
-
tslib.__metadata("design:paramtypes", [String]),
|
|
8526
|
-
tslib.__metadata("design:returntype", Promise)
|
|
8527
|
-
], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
|
|
8528
|
-
tslib.__decorate([
|
|
8529
|
-
Log(),
|
|
8530
|
-
tslib.__metadata("design:type", Function),
|
|
8531
|
-
tslib.__metadata("design:paramtypes", [Object, Array]),
|
|
8532
|
-
tslib.__metadata("design:returntype", Promise)
|
|
8533
|
-
], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
|
|
8534
10336
|
|
|
8535
10337
|
class PagarmeBankSlipAxiosAdapter {
|
|
8536
10338
|
constructor(credentials, paymentRepository) {
|
|
@@ -8547,7 +10349,7 @@ class PagarmeBankSlipAxiosAdapter {
|
|
|
8547
10349
|
});
|
|
8548
10350
|
console.warn('[PAGARME BOLETO DATA TO SEND]', payload);
|
|
8549
10351
|
if (result.data.status !== exports.PagarmePaymentStatus['Em processamento']) {
|
|
8550
|
-
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
10352
|
+
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
8551
10353
|
checkoutId: checkout.id,
|
|
8552
10354
|
userEmail: checkout.user.email,
|
|
8553
10355
|
info: result.data,
|
|
@@ -8565,7 +10367,7 @@ class PagarmeBankSlipAxiosAdapter {
|
|
|
8565
10367
|
return payment;
|
|
8566
10368
|
}
|
|
8567
10369
|
catch (error) {
|
|
8568
|
-
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
10370
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
8569
10371
|
checkoutId: checkout.id,
|
|
8570
10372
|
userEmail: checkout.user.email,
|
|
8571
10373
|
info: error.response.data,
|
|
@@ -8613,62 +10415,423 @@ class PagarmeBankSlipAxiosAdapter {
|
|
|
8613
10415
|
},
|
|
8614
10416
|
};
|
|
8615
10417
|
}
|
|
8616
|
-
}
|
|
8617
|
-
|
|
8618
|
-
class PagarmeBlockedOrderHelper {
|
|
8619
|
-
static async createBlockedOrderForUnauthorizedCard(params) {
|
|
8620
|
-
const { checkout, card, orderBlockedRepository } = params;
|
|
8621
|
-
await orderBlockedRepository.createBlockedOrderOrPayment({
|
|
8622
|
-
checkout,
|
|
8623
|
-
blockType: 'Card not authorized',
|
|
8624
|
-
type: 'Card',
|
|
8625
|
-
limiteRange: 'day',
|
|
8626
|
-
card,
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
10418
|
+
}
|
|
10419
|
+
|
|
10420
|
+
class PagarmeBlockedOrderHelper {
|
|
10421
|
+
static async createBlockedOrderForUnauthorizedCard(params) {
|
|
10422
|
+
const { checkout, card, orderBlockedRepository, gatewayInfo } = params;
|
|
10423
|
+
await orderBlockedRepository.createBlockedOrderOrPayment({
|
|
10424
|
+
checkout,
|
|
10425
|
+
blockType: 'Card not authorized',
|
|
10426
|
+
type: 'Card',
|
|
10427
|
+
limiteRange: 'day',
|
|
10428
|
+
card,
|
|
10429
|
+
gatewayInfo,
|
|
10430
|
+
});
|
|
10431
|
+
}
|
|
10432
|
+
static createPaymentError(checkout, errorType, resultData) {
|
|
10433
|
+
return new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', errorType, {
|
|
10434
|
+
checkoutId: checkout.id,
|
|
10435
|
+
userEmail: checkout.user.email,
|
|
10436
|
+
info: resultData,
|
|
10437
|
+
});
|
|
10438
|
+
}
|
|
10439
|
+
static createGenericPaymentError(checkout, errorType, errorResponseData) {
|
|
10440
|
+
return new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', errorType, {
|
|
10441
|
+
checkoutId: checkout.id,
|
|
10442
|
+
userEmail: checkout.user.email,
|
|
10443
|
+
info: errorResponseData,
|
|
10444
|
+
});
|
|
10445
|
+
}
|
|
10446
|
+
}
|
|
10447
|
+
|
|
10448
|
+
/* eslint-disable complexity */
|
|
10449
|
+
class PagarMeErrorHelper {
|
|
10450
|
+
static getErrorTypeFromResponse(errorCode) {
|
|
10451
|
+
switch (errorCode) {
|
|
10452
|
+
// Cartão inválido, vencido, bloqueado
|
|
10453
|
+
case '1000':
|
|
10454
|
+
case '1001':
|
|
10455
|
+
case '1011':
|
|
10456
|
+
case '1025':
|
|
10457
|
+
case '1032':
|
|
10458
|
+
case '1045':
|
|
10459
|
+
case '1068':
|
|
10460
|
+
case '1069':
|
|
10461
|
+
case '1070':
|
|
10462
|
+
case '2001':
|
|
10463
|
+
case '2004':
|
|
10464
|
+
case '5025':
|
|
10465
|
+
case '9124':
|
|
10466
|
+
return exports.ErrorsCode.invalidCardError;
|
|
10467
|
+
// Dados obrigatórios ausentes
|
|
10468
|
+
case '1044':
|
|
10469
|
+
case '5034':
|
|
10470
|
+
case '5047':
|
|
10471
|
+
case '5061':
|
|
10472
|
+
return exports.ErrorsCode.invalidCardError;
|
|
10473
|
+
// Suspeita de fraude, prevenção do banco
|
|
10474
|
+
case '1002':
|
|
10475
|
+
case '1004':
|
|
10476
|
+
case '1019':
|
|
10477
|
+
case '2002':
|
|
10478
|
+
case '2005':
|
|
10479
|
+
case '2007':
|
|
10480
|
+
case '2008':
|
|
10481
|
+
case '2009':
|
|
10482
|
+
case '2010':
|
|
10483
|
+
case '9201':
|
|
10484
|
+
return exports.ErrorsCode.fraudPreventionExternal;
|
|
10485
|
+
// Recusado pelo banco/emissor
|
|
10486
|
+
case '1007':
|
|
10487
|
+
case '1008':
|
|
10488
|
+
case '2000':
|
|
10489
|
+
case '5093':
|
|
10490
|
+
return exports.ErrorsCode.paymentNotAuthorizedError;
|
|
10491
|
+
// Saldo/limite insuficiente ou excedido
|
|
10492
|
+
case '1016':
|
|
10493
|
+
case '1021':
|
|
10494
|
+
case '1023':
|
|
10495
|
+
case '2011':
|
|
10496
|
+
case '2012':
|
|
10497
|
+
case '5051':
|
|
10498
|
+
case '5087':
|
|
10499
|
+
return exports.ErrorsCode.insufficientFundsError;
|
|
10500
|
+
// Valor solicitado inválido
|
|
10501
|
+
case '5094':
|
|
10502
|
+
case '5016':
|
|
10503
|
+
case '5092':
|
|
10504
|
+
return exports.ErrorsCode.paymentError;
|
|
10505
|
+
// Erros internos ou genéricos
|
|
10506
|
+
case '5000':
|
|
10507
|
+
case '5001':
|
|
10508
|
+
case '5003':
|
|
10509
|
+
case '5004':
|
|
10510
|
+
case '5006':
|
|
10511
|
+
case '5008':
|
|
10512
|
+
case '5009':
|
|
10513
|
+
case '5010':
|
|
10514
|
+
case '5011':
|
|
10515
|
+
case '5012':
|
|
10516
|
+
case '5013':
|
|
10517
|
+
case '5014':
|
|
10518
|
+
case '5015':
|
|
10519
|
+
case '5017':
|
|
10520
|
+
case '5018':
|
|
10521
|
+
case '5019':
|
|
10522
|
+
case '5020':
|
|
10523
|
+
case '5021':
|
|
10524
|
+
case '5022':
|
|
10525
|
+
case '5023':
|
|
10526
|
+
case '5024':
|
|
10527
|
+
case '5026':
|
|
10528
|
+
case '5027':
|
|
10529
|
+
case '5028':
|
|
10530
|
+
case '5029':
|
|
10531
|
+
case '5030':
|
|
10532
|
+
case '5031':
|
|
10533
|
+
case '5032':
|
|
10534
|
+
case '5033':
|
|
10535
|
+
case '5035':
|
|
10536
|
+
case '5036':
|
|
10537
|
+
case '5037':
|
|
10538
|
+
case '5038':
|
|
10539
|
+
case '5039':
|
|
10540
|
+
case '5040':
|
|
10541
|
+
case '5041':
|
|
10542
|
+
case '5042':
|
|
10543
|
+
case '5043':
|
|
10544
|
+
case '5044':
|
|
10545
|
+
case '5045':
|
|
10546
|
+
case '5049':
|
|
10547
|
+
case '5050':
|
|
10548
|
+
case '5052':
|
|
10549
|
+
case '5053':
|
|
10550
|
+
case '5054':
|
|
10551
|
+
case '5055':
|
|
10552
|
+
case '5056':
|
|
10553
|
+
case '5057':
|
|
10554
|
+
case '5058':
|
|
10555
|
+
case '5059':
|
|
10556
|
+
case '5060':
|
|
10557
|
+
case '5062':
|
|
10558
|
+
case '5063':
|
|
10559
|
+
case '5064':
|
|
10560
|
+
case '5065':
|
|
10561
|
+
case '5066':
|
|
10562
|
+
case '5067':
|
|
10563
|
+
case '5068':
|
|
10564
|
+
case '5069':
|
|
10565
|
+
case '5070':
|
|
10566
|
+
case '5071':
|
|
10567
|
+
case '5072':
|
|
10568
|
+
case '5073':
|
|
10569
|
+
case '5074':
|
|
10570
|
+
case '5075':
|
|
10571
|
+
case '5076':
|
|
10572
|
+
case '5077':
|
|
10573
|
+
case '5078':
|
|
10574
|
+
case '5079':
|
|
10575
|
+
case '5080':
|
|
10576
|
+
case '5081':
|
|
10577
|
+
case '5082':
|
|
10578
|
+
case '5083':
|
|
10579
|
+
case '5084':
|
|
10580
|
+
case '5085':
|
|
10581
|
+
case '5089':
|
|
10582
|
+
case '5090':
|
|
10583
|
+
case '5095':
|
|
10584
|
+
case '5096':
|
|
10585
|
+
case '5097':
|
|
10586
|
+
return exports.ErrorsCode.paymentError;
|
|
10587
|
+
// Banco/emissor inválido ou não operante
|
|
10588
|
+
case '1049':
|
|
10589
|
+
case '1050':
|
|
10590
|
+
return exports.ErrorsCode.paymentError;
|
|
10591
|
+
// Transação não suportada para o banco/emissor
|
|
10592
|
+
case '1061':
|
|
10593
|
+
return exports.ErrorsCode.paymentError;
|
|
10594
|
+
case '1010':
|
|
10595
|
+
case '1046':
|
|
10596
|
+
return exports.ErrorsCode.invalidCheckoutError;
|
|
10597
|
+
default:
|
|
10598
|
+
return exports.ErrorsCode.paymentError;
|
|
10599
|
+
}
|
|
10600
|
+
}
|
|
10601
|
+
}
|
|
10602
|
+
|
|
10603
|
+
class PagarmePaymentFactoryHelper {
|
|
10604
|
+
static async createSuccessfulPayment(params) {
|
|
10605
|
+
const { checkout, resultData, paymentRepository } = params;
|
|
10606
|
+
const payment = await paymentRepository.create({
|
|
10607
|
+
createdAt: new Date(),
|
|
10608
|
+
updatedAt: new Date(),
|
|
10609
|
+
userId: checkout.user.id,
|
|
10610
|
+
checkoutId: checkout.id,
|
|
10611
|
+
totalPrice: checkout.totalPrice,
|
|
10612
|
+
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
10613
|
+
transaction: { ...resultData, paidAt: new Date() },
|
|
10614
|
+
});
|
|
10615
|
+
return payment;
|
|
10616
|
+
}
|
|
10617
|
+
}
|
|
10618
|
+
|
|
10619
|
+
class PagarmePaymentOperationsHelper {
|
|
10620
|
+
static async executePaymentRequest(params) {
|
|
10621
|
+
const { checkout, card, credentials, createPayloadFunction } = params;
|
|
10622
|
+
const payload = createPayloadFunction(checkout, card);
|
|
10623
|
+
console.warn('[PAGARME CARD DATA TO SEND]', payload);
|
|
10624
|
+
const result = await axios__default["default"]({
|
|
10625
|
+
method: 'POST',
|
|
10626
|
+
url: `${credentials.URL}/transactions`,
|
|
10627
|
+
data: payload,
|
|
10628
|
+
});
|
|
10629
|
+
return result;
|
|
10630
|
+
}
|
|
10631
|
+
}
|
|
10632
|
+
|
|
10633
|
+
class PagarMeV5RequestHelper {
|
|
10634
|
+
static build(checkout, method, card) {
|
|
10635
|
+
return {
|
|
10636
|
+
items: this.buildItems(checkout),
|
|
10637
|
+
customer: this.buildCustomer(checkout),
|
|
10638
|
+
shipping: this.buildShipping(checkout),
|
|
10639
|
+
payments: this.buildPayment(checkout, method, card),
|
|
10640
|
+
...this.buildAdditionalInfo(checkout),
|
|
10641
|
+
};
|
|
10642
|
+
}
|
|
10643
|
+
static buildItems(checkout) {
|
|
10644
|
+
const isSubscriber = checkout.user?.isSubscriber ?? false;
|
|
10645
|
+
return checkout.lineItems
|
|
10646
|
+
.filter((item) => !item.isGift)
|
|
10647
|
+
.map((item) => {
|
|
10648
|
+
return {
|
|
10649
|
+
amount: Math.floor(item.pricePaid * 100),
|
|
10650
|
+
description: isSubscriber ? `${item.name} - ASSINANTE` : item.name,
|
|
10651
|
+
quantity: item.quantity,
|
|
10652
|
+
code: item.EAN,
|
|
10653
|
+
};
|
|
10654
|
+
});
|
|
10655
|
+
}
|
|
10656
|
+
static buildCustomer(checkout) {
|
|
10657
|
+
return {
|
|
10658
|
+
name: checkout.user.displayName,
|
|
10659
|
+
email: checkout.user.email,
|
|
10660
|
+
type: 'individual',
|
|
10661
|
+
document: checkout.user.cpf,
|
|
10662
|
+
phones: {
|
|
10663
|
+
home_phone: {
|
|
10664
|
+
country_code: '55',
|
|
10665
|
+
number: checkout.user.phone.slice(2),
|
|
10666
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
10667
|
+
},
|
|
10668
|
+
mobile_phone: {
|
|
10669
|
+
country_code: '55',
|
|
10670
|
+
number: checkout.user.phone.slice(2),
|
|
10671
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
10672
|
+
},
|
|
10673
|
+
},
|
|
10674
|
+
address: {
|
|
10675
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
10676
|
+
line_2: `${checkout.billingAddress.extension}`,
|
|
10677
|
+
zip_code: checkout.shippingAddress.zip,
|
|
10678
|
+
city: checkout.billingAddress.city,
|
|
10679
|
+
state: checkout.billingAddress.state,
|
|
10680
|
+
country: 'BR',
|
|
10681
|
+
},
|
|
10682
|
+
};
|
|
10683
|
+
}
|
|
10684
|
+
static buildShipping(checkout) {
|
|
10685
|
+
return {
|
|
10686
|
+
amount: Math.floor(checkout.shipping.ShippingPrice * 100),
|
|
10687
|
+
description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
|
|
10688
|
+
recipient_name: checkout.shippingAddress.recipient,
|
|
10689
|
+
recipient_phone: checkout.user.phone,
|
|
10690
|
+
address: {
|
|
10691
|
+
line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
10692
|
+
line_2: `${checkout.shippingAddress.extension}`,
|
|
10693
|
+
zip_code: checkout.shippingAddress.zip,
|
|
10694
|
+
city: checkout.shippingAddress.city,
|
|
10695
|
+
state: checkout.shippingAddress.state,
|
|
10696
|
+
country: 'BR',
|
|
10697
|
+
},
|
|
10698
|
+
};
|
|
10699
|
+
}
|
|
10700
|
+
static buildPayment(checkout, method, card) {
|
|
10701
|
+
return [
|
|
10702
|
+
{
|
|
10703
|
+
payment_method: method,
|
|
10704
|
+
amount: Math.floor(checkout.totalPrice * 100),
|
|
10705
|
+
...(method === 'pix' && {
|
|
10706
|
+
pix: this.getPixOrder(),
|
|
10707
|
+
}),
|
|
10708
|
+
...(method === 'boleto' && {
|
|
10709
|
+
boleto: this.getBoletoOrder(),
|
|
10710
|
+
}),
|
|
10711
|
+
...(method === 'credit_card' && {
|
|
10712
|
+
credit_card: this.getCardOrder(checkout, card),
|
|
10713
|
+
}),
|
|
10714
|
+
},
|
|
10715
|
+
];
|
|
10716
|
+
}
|
|
10717
|
+
static getPixOrder() {
|
|
10718
|
+
return {
|
|
10719
|
+
expires_at: dateFns.format(dateFns.addHours(new Date(), 24), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx"),
|
|
10720
|
+
};
|
|
10721
|
+
}
|
|
10722
|
+
static getBoletoOrder() {
|
|
10723
|
+
return {
|
|
10724
|
+
due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd') + 'T23:59:59.999-03:00',
|
|
10725
|
+
instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
|
|
10726
|
+
type: 'DM',
|
|
10727
|
+
document_number: new Date().getTime().toString(),
|
|
10728
|
+
};
|
|
10729
|
+
}
|
|
10730
|
+
static getCardOrder(checkout, card) {
|
|
10731
|
+
return {
|
|
10732
|
+
installments: card.installments,
|
|
10733
|
+
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'loja glam' : 'mens market',
|
|
10734
|
+
card_id: card.cardId,
|
|
10735
|
+
card: {
|
|
10736
|
+
cvv: card.cardCvv,
|
|
10737
|
+
billing_address: {
|
|
10738
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
10739
|
+
zip_code: checkout.billingAddress.zip,
|
|
10740
|
+
city: checkout.billingAddress.city,
|
|
10741
|
+
state: checkout.billingAddress.state,
|
|
10742
|
+
country: 'BR',
|
|
10743
|
+
},
|
|
10744
|
+
},
|
|
10745
|
+
};
|
|
10746
|
+
}
|
|
10747
|
+
static buildAdditionalInfo(checkout) {
|
|
10748
|
+
const isSubscriber = checkout.user?.isSubscriber ?? false;
|
|
10749
|
+
if (isSubscriber)
|
|
10750
|
+
return {
|
|
10751
|
+
antifraude_enabled: false,
|
|
10752
|
+
};
|
|
10753
|
+
return {};
|
|
8642
10754
|
}
|
|
8643
10755
|
}
|
|
8644
10756
|
|
|
8645
|
-
class
|
|
8646
|
-
static
|
|
8647
|
-
|
|
8648
|
-
const payment = await paymentRepository.create({
|
|
10757
|
+
class PagarMeV5ResponseHelper {
|
|
10758
|
+
static build(method, checkout, response) {
|
|
10759
|
+
return Payment.toInstance({
|
|
8649
10760
|
createdAt: new Date(),
|
|
8650
10761
|
updatedAt: new Date(),
|
|
8651
10762
|
userId: checkout.user.id,
|
|
8652
10763
|
checkoutId: checkout.id,
|
|
8653
10764
|
totalPrice: checkout.totalPrice,
|
|
8654
10765
|
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
10766
|
+
pagarMeOrderId: response.id,
|
|
10767
|
+
transaction: this.buildPaymentTransaction(method, response),
|
|
10768
|
+
});
|
|
10769
|
+
}
|
|
10770
|
+
static buildPaymentTransaction(method, response) {
|
|
10771
|
+
const charger = response.charges.at(0);
|
|
10772
|
+
const transaction = charger.last_transaction;
|
|
10773
|
+
return PaymentTransaction.toInstance({
|
|
10774
|
+
acquirer_name: exports.PaymentProviders.PAGARME,
|
|
10775
|
+
amount: charger.amount,
|
|
10776
|
+
currency: charger.currency,
|
|
10777
|
+
gateway_id: charger.gateway_id,
|
|
10778
|
+
status: this.getPaymentStatus(transaction.status),
|
|
10779
|
+
payment_method: charger.payment_method,
|
|
10780
|
+
date_created: charger.created_at,
|
|
10781
|
+
date_updated: charger.updated_at,
|
|
10782
|
+
paid_amount: charger.paid_amount,
|
|
10783
|
+
paid_at: charger.paid_at,
|
|
10784
|
+
order_id: response.id,
|
|
10785
|
+
charger_id: charger.id,
|
|
10786
|
+
tid: charger.id,
|
|
10787
|
+
id: charger.id,
|
|
10788
|
+
...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
|
|
10789
|
+
...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
|
|
10790
|
+
...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
|
|
10791
|
+
});
|
|
10792
|
+
}
|
|
10793
|
+
static getPaymentStatus(status) {
|
|
10794
|
+
if (status == exports.PagarMeV5PaymentStatus.Gerado)
|
|
10795
|
+
return exports.PagarMeV5PaymentStatus['Aguardando pagamento'];
|
|
10796
|
+
if (status == exports.PagarMeV5PaymentStatus.Capturada)
|
|
10797
|
+
return exports.PagarMeV5PaymentStatus.Pago;
|
|
10798
|
+
return status;
|
|
10799
|
+
}
|
|
10800
|
+
static getBoletoReponse(transaction) {
|
|
10801
|
+
return {
|
|
10802
|
+
boleto_url: transaction.url?.toString(),
|
|
10803
|
+
boleto_barcode: transaction.line?.toString(),
|
|
10804
|
+
boleto_qr_code: transaction.qr_code?.toString(),
|
|
10805
|
+
boleto_expiration_date: transaction.due_at?.toString(),
|
|
10806
|
+
boleto_instructions: transaction.instructions?.toString(),
|
|
10807
|
+
boleto_nosso_numero: transaction.nosso_numero?.toString(),
|
|
10808
|
+
boleto_type: transaction.type?.toString(),
|
|
10809
|
+
boleto_document_number: transaction.document_number?.toString(),
|
|
10810
|
+
};
|
|
8658
10811
|
}
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
10812
|
+
static getPixReponse(transaction) {
|
|
10813
|
+
return {
|
|
10814
|
+
pix_qr_code: transaction.qr_code?.toString(),
|
|
10815
|
+
pix_qr_code_url: transaction.qr_code_url?.toString(),
|
|
10816
|
+
pix_expiration_date: transaction.expires_at?.toString(),
|
|
10817
|
+
};
|
|
10818
|
+
}
|
|
10819
|
+
static getCardReponse(transaction) {
|
|
10820
|
+
return {
|
|
10821
|
+
soft_descriptor: transaction.statement_descriptor?.toString(),
|
|
10822
|
+
acquirer_name: transaction.acquirer_name?.toString(),
|
|
10823
|
+
acquirer_id: transaction.acquirer_tid?.toString(),
|
|
10824
|
+
acquirer_nsu: transaction.acquirer_nsu?.toString(),
|
|
10825
|
+
acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
|
|
10826
|
+
acquirer_message: transaction.acquirer_message?.toString(),
|
|
10827
|
+
acquirer_return_code: transaction.acquirer_return_code?.toString(),
|
|
10828
|
+
installments: transaction.installments ?? null,
|
|
10829
|
+
card_holder_name: transaction.card?.holder_name?.toString(),
|
|
10830
|
+
card_last_digits: transaction.card?.last_four_digits?.toString(),
|
|
10831
|
+
card_first_digits: transaction.card?.first_six_digits?.toString(),
|
|
10832
|
+
card_brand: transaction.card?.brand?.toString(),
|
|
10833
|
+
card_id: transaction.card?.id?.toString(),
|
|
10834
|
+
};
|
|
8672
10835
|
}
|
|
8673
10836
|
}
|
|
8674
10837
|
|
|
@@ -8692,7 +10855,7 @@ class PagarmeCardAxiosAdapter {
|
|
|
8692
10855
|
card,
|
|
8693
10856
|
orderBlockedRepository: this.orderBlockedRepository,
|
|
8694
10857
|
});
|
|
8695
|
-
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, result.data);
|
|
10858
|
+
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, exports.ErrorsCode.paymentError, result.data);
|
|
8696
10859
|
}
|
|
8697
10860
|
return PagarmePaymentFactoryHelper.createSuccessfulPayment({
|
|
8698
10861
|
checkout,
|
|
@@ -8704,7 +10867,7 @@ class PagarmeCardAxiosAdapter {
|
|
|
8704
10867
|
if (error instanceof PaymentError) {
|
|
8705
10868
|
throw error;
|
|
8706
10869
|
}
|
|
8707
|
-
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
10870
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, exports.ErrorsCode.paymentError, error.response?.data);
|
|
8708
10871
|
}
|
|
8709
10872
|
}
|
|
8710
10873
|
async addCard(card) {
|
|
@@ -8728,8 +10891,9 @@ class PagarmeCardAxiosAdapter {
|
|
|
8728
10891
|
});
|
|
8729
10892
|
}
|
|
8730
10893
|
}
|
|
8731
|
-
async createCardHash(bu) {
|
|
8732
|
-
const
|
|
10894
|
+
async createCardHash(bu, shop) {
|
|
10895
|
+
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
10896
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
8733
10897
|
try {
|
|
8734
10898
|
const { data } = await axios__default["default"]({
|
|
8735
10899
|
method: 'GET',
|
|
@@ -8860,7 +11024,7 @@ class PagarmePixAxiosAdapter {
|
|
|
8860
11024
|
return payment;
|
|
8861
11025
|
}
|
|
8862
11026
|
catch (error) {
|
|
8863
|
-
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
11027
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', exports.ErrorsCode.paymentError, {
|
|
8864
11028
|
checkoutId: checkout.id,
|
|
8865
11029
|
userEmail: checkout.user.email,
|
|
8866
11030
|
info: error.response?.data,
|
|
@@ -8892,6 +11056,341 @@ class PagarmePixAxiosAdapter {
|
|
|
8892
11056
|
}
|
|
8893
11057
|
}
|
|
8894
11058
|
|
|
11059
|
+
class PagarmeV5BankSlipAxiosAdapter {
|
|
11060
|
+
constructor(credentials, paymentRepository) {
|
|
11061
|
+
this.credentials = credentials;
|
|
11062
|
+
this.paymentRepository = paymentRepository;
|
|
11063
|
+
}
|
|
11064
|
+
async pay(checkout) {
|
|
11065
|
+
try {
|
|
11066
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
|
|
11067
|
+
console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
11068
|
+
const { data } = await axios__default["default"]({
|
|
11069
|
+
method: 'POST',
|
|
11070
|
+
url: `${this.credentials.URL}/orders`,
|
|
11071
|
+
headers: {
|
|
11072
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11073
|
+
'Content-Type': 'application/json',
|
|
11074
|
+
},
|
|
11075
|
+
data: payload,
|
|
11076
|
+
});
|
|
11077
|
+
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
11078
|
+
if (data.status === exports.PagarMeV5OrderStatus.Falha ||
|
|
11079
|
+
data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
|
|
11080
|
+
(data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado &&
|
|
11081
|
+
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus['Em processamento'])) {
|
|
11082
|
+
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
11083
|
+
checkoutId: checkout.id,
|
|
11084
|
+
userEmail: checkout.user.email,
|
|
11085
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
11086
|
+
}));
|
|
11087
|
+
}
|
|
11088
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
|
|
11089
|
+
return payment;
|
|
11090
|
+
}
|
|
11091
|
+
catch (error) {
|
|
11092
|
+
if (error instanceof axios.AxiosError) {
|
|
11093
|
+
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
11094
|
+
}
|
|
11095
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', exports.ErrorsCode.paymentError, {
|
|
11096
|
+
checkoutId: checkout.id,
|
|
11097
|
+
userEmail: checkout.user.email,
|
|
11098
|
+
info: error.response?.data,
|
|
11099
|
+
});
|
|
11100
|
+
}
|
|
11101
|
+
}
|
|
11102
|
+
async getBoletoTransaction(paymentId) {
|
|
11103
|
+
try {
|
|
11104
|
+
const { data } = await axios__default["default"]({
|
|
11105
|
+
method: 'GET',
|
|
11106
|
+
url: `${this.credentials.URL}/charges/${paymentId}`,
|
|
11107
|
+
headers: {
|
|
11108
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11109
|
+
'Content-Type': 'application/json',
|
|
11110
|
+
},
|
|
11111
|
+
});
|
|
11112
|
+
const payment = await this.paymentRepository.get({
|
|
11113
|
+
id: data.id,
|
|
11114
|
+
});
|
|
11115
|
+
return payment.transaction;
|
|
11116
|
+
}
|
|
11117
|
+
catch (error) {
|
|
11118
|
+
throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
|
|
11119
|
+
paymentId,
|
|
11120
|
+
info: error.response.data,
|
|
11121
|
+
});
|
|
11122
|
+
}
|
|
11123
|
+
}
|
|
11124
|
+
}
|
|
11125
|
+
|
|
11126
|
+
class PagarmeV5BaseAxiosAdapter {
|
|
11127
|
+
constructor(credentials, paymentRepository) {
|
|
11128
|
+
this.credentials = credentials;
|
|
11129
|
+
this.paymentRepository = paymentRepository;
|
|
11130
|
+
}
|
|
11131
|
+
async refund(order, amount) {
|
|
11132
|
+
try {
|
|
11133
|
+
console.warn('[PAGARME REFUND] Starting refund process for order', order.id, order.payment, 'with amount', amount);
|
|
11134
|
+
const amountToSend = +amount.toFixed(2) * 100;
|
|
11135
|
+
console.warn('[PAGARME REFUND] Amount to send in cents', amountToSend);
|
|
11136
|
+
const { data } = await axios__default["default"]({
|
|
11137
|
+
method: 'DELETE',
|
|
11138
|
+
url: `${this.credentials.URL}/charges/${order.payment.charger_id}`,
|
|
11139
|
+
headers: {
|
|
11140
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11141
|
+
'Content-Type': 'application/json',
|
|
11142
|
+
},
|
|
11143
|
+
data: {
|
|
11144
|
+
amount: amountToSend,
|
|
11145
|
+
},
|
|
11146
|
+
});
|
|
11147
|
+
console.warn('[RESPONSE PAGARME REFUND]', JSON.stringify(data));
|
|
11148
|
+
await this.paymentRepository.create({
|
|
11149
|
+
createdAt: new Date(),
|
|
11150
|
+
updatedAt: new Date(),
|
|
11151
|
+
userId: order.user.id,
|
|
11152
|
+
orderId: order.id,
|
|
11153
|
+
totalPrice: amount,
|
|
11154
|
+
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
11155
|
+
pagarMeOrderId: data.id,
|
|
11156
|
+
transaction: data,
|
|
11157
|
+
});
|
|
11158
|
+
return {
|
|
11159
|
+
status: this.getRefundStatus(data.status),
|
|
11160
|
+
success: [exports.PagarMeV5OrderStatus.Pago, exports.PagarMeV5OrderStatus.Cancelado].includes(data.status) ? true : false,
|
|
11161
|
+
};
|
|
11162
|
+
}
|
|
11163
|
+
catch (error) {
|
|
11164
|
+
console.error('Error during refund process for order', order.id, 'with error', error);
|
|
11165
|
+
throw error;
|
|
11166
|
+
}
|
|
11167
|
+
}
|
|
11168
|
+
getRefundStatus(status) {
|
|
11169
|
+
if ([exports.PagarMeV5PaymentStatus['Em processamento']].includes(status)) {
|
|
11170
|
+
return 'processing';
|
|
11171
|
+
}
|
|
11172
|
+
if ([exports.PagarMeV5OrderStatus.Pago, exports.PagarMeV5OrderStatus.Cancelado].includes(status)) {
|
|
11173
|
+
return 'success';
|
|
11174
|
+
}
|
|
11175
|
+
return 'unknown';
|
|
11176
|
+
}
|
|
11177
|
+
}
|
|
11178
|
+
|
|
11179
|
+
class PagarmeV5CardAxiosAdapter extends PagarmeV5BaseAxiosAdapter {
|
|
11180
|
+
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
11181
|
+
super(credentials, paymentRepository);
|
|
11182
|
+
this.credentials = credentials;
|
|
11183
|
+
this.paymentRepository = paymentRepository;
|
|
11184
|
+
this.orderBlockedRepository = orderBlockedRepository;
|
|
11185
|
+
}
|
|
11186
|
+
async pay(checkout, card) {
|
|
11187
|
+
try {
|
|
11188
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
|
|
11189
|
+
console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
|
|
11190
|
+
const { data } = await axios__default["default"]({
|
|
11191
|
+
method: 'POST',
|
|
11192
|
+
url: `${this.credentials.URL}/orders`,
|
|
11193
|
+
headers: {
|
|
11194
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11195
|
+
'Content-Type': 'application/json',
|
|
11196
|
+
},
|
|
11197
|
+
data: payload,
|
|
11198
|
+
});
|
|
11199
|
+
console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
|
|
11200
|
+
const charge = data.charges.at(0);
|
|
11201
|
+
if (data.status == exports.PagarMeV5OrderStatus.Falha ||
|
|
11202
|
+
charge.status !== exports.PagarMeV5OrderStatus.Pago ||
|
|
11203
|
+
charge.last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
|
|
11204
|
+
await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
|
|
11205
|
+
checkout,
|
|
11206
|
+
card,
|
|
11207
|
+
orderBlockedRepository: this.orderBlockedRepository,
|
|
11208
|
+
gatewayInfo: {
|
|
11209
|
+
gateway: exports.PaymentProviders.PAGARME,
|
|
11210
|
+
status: charge.status,
|
|
11211
|
+
statusDetail: charge.last_transaction?.status,
|
|
11212
|
+
},
|
|
11213
|
+
});
|
|
11214
|
+
const errorCode = PagarMeErrorHelper.getErrorTypeFromResponse(charge.last_transaction.acquirer_return_code);
|
|
11215
|
+
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, errorCode, data);
|
|
11216
|
+
}
|
|
11217
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
|
|
11218
|
+
return payment;
|
|
11219
|
+
}
|
|
11220
|
+
catch (error) {
|
|
11221
|
+
if (error instanceof axios.AxiosError) {
|
|
11222
|
+
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
11223
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, exports.ErrorsCode.paymentError, error.response?.data);
|
|
11224
|
+
}
|
|
11225
|
+
throw error;
|
|
11226
|
+
}
|
|
11227
|
+
}
|
|
11228
|
+
async addCard(card, customer) {
|
|
11229
|
+
try {
|
|
11230
|
+
const { id } = await this.createOrUpdateCustomer(customer);
|
|
11231
|
+
const { data } = await axios__default["default"]({
|
|
11232
|
+
method: 'POST',
|
|
11233
|
+
url: `${this.credentials.URL}/customers/${id}/cards`,
|
|
11234
|
+
headers: {
|
|
11235
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11236
|
+
'Content-Type': 'application/json',
|
|
11237
|
+
},
|
|
11238
|
+
data: {
|
|
11239
|
+
number: card.number,
|
|
11240
|
+
holder_name: card.name,
|
|
11241
|
+
holder_document: card.cpf,
|
|
11242
|
+
exp_month: card.expirationDate.split('/').at(0),
|
|
11243
|
+
exp_year: card.expirationDate.split('/').at(1),
|
|
11244
|
+
cvv: card.cvv,
|
|
11245
|
+
billing_address: {
|
|
11246
|
+
line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
|
|
11247
|
+
line_2: `${customer.billingAddress.extension}`,
|
|
11248
|
+
zip_code: customer.billingAddress.zip,
|
|
11249
|
+
city: customer.billingAddress.city,
|
|
11250
|
+
state: customer.billingAddress.state,
|
|
11251
|
+
country: 'BR',
|
|
11252
|
+
},
|
|
11253
|
+
},
|
|
11254
|
+
});
|
|
11255
|
+
return data;
|
|
11256
|
+
}
|
|
11257
|
+
catch (error) {
|
|
11258
|
+
console.warn(JSON.stringify(error));
|
|
11259
|
+
throw error;
|
|
11260
|
+
}
|
|
11261
|
+
}
|
|
11262
|
+
async createCardHash(bu, shop) {
|
|
11263
|
+
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
11264
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
11265
|
+
try {
|
|
11266
|
+
const { data } = await axios__default["default"]({
|
|
11267
|
+
method: 'GET',
|
|
11268
|
+
headers: {
|
|
11269
|
+
'content-type': 'application/json',
|
|
11270
|
+
},
|
|
11271
|
+
url: `${this.credentials.URL}/transactions/card_hash_key`,
|
|
11272
|
+
data: JSON.stringify({
|
|
11273
|
+
api_key: key,
|
|
11274
|
+
}),
|
|
11275
|
+
});
|
|
11276
|
+
return data;
|
|
11277
|
+
}
|
|
11278
|
+
catch (error) {
|
|
11279
|
+
throw new BusinessError('Houve uma falha gerar o hash', {
|
|
11280
|
+
info: error.response.data,
|
|
11281
|
+
});
|
|
11282
|
+
}
|
|
11283
|
+
}
|
|
11284
|
+
async getCardByToken(customerId, token) {
|
|
11285
|
+
try {
|
|
11286
|
+
const { data } = await axios__default["default"]({
|
|
11287
|
+
method: 'GET',
|
|
11288
|
+
url: `${this.credentials.URL}/cards/${token}`,
|
|
11289
|
+
data: {
|
|
11290
|
+
api_key: this.credentials.API_KEY,
|
|
11291
|
+
},
|
|
11292
|
+
});
|
|
11293
|
+
return data;
|
|
11294
|
+
}
|
|
11295
|
+
catch (error) {
|
|
11296
|
+
throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
|
|
11297
|
+
info: error.response.data,
|
|
11298
|
+
});
|
|
11299
|
+
}
|
|
11300
|
+
}
|
|
11301
|
+
async createTransaction(info) {
|
|
11302
|
+
return info;
|
|
11303
|
+
}
|
|
11304
|
+
async createOrUpdateCustomer(customer) {
|
|
11305
|
+
try {
|
|
11306
|
+
const { data } = await axios__default["default"]({
|
|
11307
|
+
method: 'POST',
|
|
11308
|
+
url: `${this.credentials.URL}/customers`,
|
|
11309
|
+
headers: {
|
|
11310
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11311
|
+
'Content-Type': 'application/json',
|
|
11312
|
+
},
|
|
11313
|
+
data: {
|
|
11314
|
+
name: customer.displayName,
|
|
11315
|
+
email: customer.email,
|
|
11316
|
+
document: customer.cpf,
|
|
11317
|
+
type: 'individual',
|
|
11318
|
+
document_type: 'CPF',
|
|
11319
|
+
address: {
|
|
11320
|
+
line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
|
|
11321
|
+
line_2: `${customer.billingAddress.extension}`,
|
|
11322
|
+
zip_code: customer.billingAddress.zip,
|
|
11323
|
+
city: customer.billingAddress.city,
|
|
11324
|
+
state: customer.billingAddress.state,
|
|
11325
|
+
country: 'BR',
|
|
11326
|
+
},
|
|
11327
|
+
birthdate: dateFns.format(new Date(customer.birthday), 'MM/dd/yyyy'),
|
|
11328
|
+
phones: {
|
|
11329
|
+
home_phone: {
|
|
11330
|
+
country_code: '55',
|
|
11331
|
+
number: customer.phone.slice(2),
|
|
11332
|
+
area_code: customer.phone.slice(0, 2),
|
|
11333
|
+
},
|
|
11334
|
+
mobile_phone: {
|
|
11335
|
+
country_code: '55',
|
|
11336
|
+
number: customer.phone.slice(2),
|
|
11337
|
+
area_code: customer.phone.slice(0, 2),
|
|
11338
|
+
},
|
|
11339
|
+
},
|
|
11340
|
+
},
|
|
11341
|
+
});
|
|
11342
|
+
return data;
|
|
11343
|
+
}
|
|
11344
|
+
catch (error) {
|
|
11345
|
+
console.warn(error);
|
|
11346
|
+
throw error;
|
|
11347
|
+
}
|
|
11348
|
+
}
|
|
11349
|
+
}
|
|
11350
|
+
|
|
11351
|
+
class PagarmeV5PixAxiosAdapter extends PagarmeV5BaseAxiosAdapter {
|
|
11352
|
+
constructor(credentials, paymentRepository) {
|
|
11353
|
+
super(credentials, paymentRepository);
|
|
11354
|
+
this.credentials = credentials;
|
|
11355
|
+
this.paymentRepository = paymentRepository;
|
|
11356
|
+
}
|
|
11357
|
+
async pay(checkout) {
|
|
11358
|
+
try {
|
|
11359
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
|
|
11360
|
+
console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
|
|
11361
|
+
const { data } = await axios__default["default"]({
|
|
11362
|
+
method: 'POST',
|
|
11363
|
+
url: `${this.credentials.URL}/orders`,
|
|
11364
|
+
headers: {
|
|
11365
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
11366
|
+
'Content-Type': 'application/json',
|
|
11367
|
+
},
|
|
11368
|
+
data: payload,
|
|
11369
|
+
});
|
|
11370
|
+
console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
|
|
11371
|
+
if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
|
|
11372
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', exports.ErrorsCode.paymentError, {
|
|
11373
|
+
checkoutId: checkout.id,
|
|
11374
|
+
userEmail: checkout.user.email,
|
|
11375
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
11376
|
+
});
|
|
11377
|
+
}
|
|
11378
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
|
|
11379
|
+
return payment;
|
|
11380
|
+
}
|
|
11381
|
+
catch (error) {
|
|
11382
|
+
if (error instanceof axios.AxiosError) {
|
|
11383
|
+
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
11384
|
+
}
|
|
11385
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', exports.ErrorsCode.paymentError, {
|
|
11386
|
+
checkoutId: checkout.id,
|
|
11387
|
+
userEmail: checkout.user.email,
|
|
11388
|
+
info: error.response?.data,
|
|
11389
|
+
});
|
|
11390
|
+
}
|
|
11391
|
+
}
|
|
11392
|
+
}
|
|
11393
|
+
|
|
8895
11394
|
class VertexAxiosAdapter {
|
|
8896
11395
|
constructor(config) {
|
|
8897
11396
|
this.config = config;
|
|
@@ -9057,6 +11556,10 @@ Object.defineProperty(exports, 'addDays', {
|
|
|
9057
11556
|
enumerable: true,
|
|
9058
11557
|
get: function () { return dateFns.addDays; }
|
|
9059
11558
|
});
|
|
11559
|
+
Object.defineProperty(exports, 'addHours', {
|
|
11560
|
+
enumerable: true,
|
|
11561
|
+
get: function () { return dateFns.addHours; }
|
|
11562
|
+
});
|
|
9060
11563
|
Object.defineProperty(exports, 'addMonths', {
|
|
9061
11564
|
enumerable: true,
|
|
9062
11565
|
get: function () { return dateFns.addMonths; }
|
|
@@ -9093,6 +11596,10 @@ Object.defineProperty(exports, 'subDays', {
|
|
|
9093
11596
|
enumerable: true,
|
|
9094
11597
|
get: function () { return dateFns.subDays; }
|
|
9095
11598
|
});
|
|
11599
|
+
Object.defineProperty(exports, 'formatInTimeZone', {
|
|
11600
|
+
enumerable: true,
|
|
11601
|
+
get: function () { return dateFnsTz.formatInTimeZone; }
|
|
11602
|
+
});
|
|
9096
11603
|
Object.defineProperty(exports, 'chunk', {
|
|
9097
11604
|
enumerable: true,
|
|
9098
11605
|
get: function () { return lodash.chunk; }
|
|
@@ -9180,6 +11687,8 @@ exports.Base = Base;
|
|
|
9180
11687
|
exports.BaseModel = BaseModel;
|
|
9181
11688
|
exports.BeautyProfile = BeautyProfile;
|
|
9182
11689
|
exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
|
|
11690
|
+
exports.BrandCategory = BrandCategory;
|
|
11691
|
+
exports.BrandCategoryFirestoreRepository = BrandCategoryFirestoreRepository;
|
|
9183
11692
|
exports.BusinessError = BusinessError;
|
|
9184
11693
|
exports.Buy2Win = Buy2Win;
|
|
9185
11694
|
exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
|
|
@@ -9228,6 +11737,7 @@ exports.GroupFirestoreRepository = GroupFirestoreRepository;
|
|
|
9228
11737
|
exports.Home = Home;
|
|
9229
11738
|
exports.HomeFirestoreRepository = HomeFirestoreRepository;
|
|
9230
11739
|
exports.InvalidArgumentError = InvalidArgumentError;
|
|
11740
|
+
exports.InvalidCheckoutError = InvalidCheckoutError;
|
|
9231
11741
|
exports.KitProduct = KitProduct;
|
|
9232
11742
|
exports.KitProductHasuraGraphQL = KitProductHasuraGraphQL;
|
|
9233
11743
|
exports.Lead = Lead;
|
|
@@ -9238,6 +11748,13 @@ exports.Log = Log;
|
|
|
9238
11748
|
exports.LogDocument = LogDocument;
|
|
9239
11749
|
exports.LogFirestoreRepository = LogFirestoreRepository;
|
|
9240
11750
|
exports.Logger = Logger;
|
|
11751
|
+
exports.MercadoPagoBankSlipAxiosAdapter = MercadoPagoBankSlipAxiosAdapter;
|
|
11752
|
+
exports.MercadoPagoCardAxiosAdapter = MercadoPagoCardAxiosAdapter;
|
|
11753
|
+
exports.MercadoPagoErrorHelper = MercadoPagoErrorHelper;
|
|
11754
|
+
exports.MercadoPagoPaymentMethodFactory = MercadoPagoPaymentMethodFactory;
|
|
11755
|
+
exports.MercadoPagoPixAxiosAdapter = MercadoPagoPixAxiosAdapter;
|
|
11756
|
+
exports.MercadoPagoRequestHelper = MercadoPagoRequestHelper;
|
|
11757
|
+
exports.MercadoPagoResponseHelper = MercadoPagoResponseHelper;
|
|
9241
11758
|
exports.NotFoundError = NotFoundError;
|
|
9242
11759
|
exports.ObsEmitter = ObsEmitter;
|
|
9243
11760
|
exports.Order = Order;
|
|
@@ -9248,20 +11765,33 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
|
|
|
9248
11765
|
exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
|
|
9249
11766
|
exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
|
|
9250
11767
|
exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
|
|
11768
|
+
exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
|
|
11769
|
+
exports.PagarmeV5BaseAxiosAdapter = PagarmeV5BaseAxiosAdapter;
|
|
11770
|
+
exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
|
|
11771
|
+
exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
|
|
9251
11772
|
exports.Payment = Payment;
|
|
9252
11773
|
exports.PaymentError = PaymentError;
|
|
9253
11774
|
exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|
|
9254
11775
|
exports.PaymentProviderFactory = PaymentProviderFactory;
|
|
9255
11776
|
exports.PaymentTransaction = PaymentTransaction;
|
|
9256
11777
|
exports.Product = Product;
|
|
11778
|
+
exports.ProductCatalogHasuraGraphQL = ProductCatalogHasuraGraphQL;
|
|
11779
|
+
exports.ProductCatalogHasuraGraphQLRepository = ProductCatalogHasuraGraphQLRepository;
|
|
9257
11780
|
exports.ProductErrors = ProductErrors;
|
|
9258
11781
|
exports.ProductErrorsHasuraGraphQL = ProductErrorsHasuraGraphQL;
|
|
9259
11782
|
exports.ProductErrorsHasuraGraphQLRepository = ProductErrorsHasuraGraphQLRepository;
|
|
9260
11783
|
exports.ProductFirestoreRepository = ProductFirestoreRepository;
|
|
11784
|
+
exports.ProductGroup = ProductGroup;
|
|
11785
|
+
exports.ProductGroupHasuraGraphQLRepository = ProductGroupHasuraGraphQLRepository;
|
|
9261
11786
|
exports.ProductHasuraGraphQL = ProductHasuraGraphQL;
|
|
9262
11787
|
exports.ProductHasuraGraphQLRepository = ProductHasuraGraphQLRepository;
|
|
11788
|
+
exports.ProductPriceLog = ProductPriceLog;
|
|
11789
|
+
exports.ProductPriceLogHasuraGraphQLRepository = ProductPriceLogHasuraGraphQLRepository;
|
|
9263
11790
|
exports.ProductReview = ProductReview;
|
|
9264
11791
|
exports.ProductReviewHasuraGraphQLRepository = ProductReviewHasuraGraphQLRepository;
|
|
11792
|
+
exports.ProductStockEntry = ProductStockEntry;
|
|
11793
|
+
exports.ProductStockEntryHasuraGraphQL = ProductStockEntryHasuraGraphQL;
|
|
11794
|
+
exports.ProductStockEntryHasuraGraphQLRepository = ProductStockEntryHasuraGraphQLRepository;
|
|
9265
11795
|
exports.ProductStockNotification = ProductStockNotification;
|
|
9266
11796
|
exports.ProductStockNotificationHasuraGraphQLRepository = ProductStockNotificationHasuraGraphQLRepository;
|
|
9267
11797
|
exports.ProductVariantFirestoreRepository = ProductVariantFirestoreRepository;
|
|
@@ -9277,10 +11807,18 @@ exports.RoundProductPricesHelper = RoundProductPricesHelper;
|
|
|
9277
11807
|
exports.Sequence = Sequence;
|
|
9278
11808
|
exports.SequenceFirestoreRepository = SequenceFirestoreRepository;
|
|
9279
11809
|
exports.ShippingMethod = ShippingMethod;
|
|
11810
|
+
exports.ShopConfigs = ShopConfigs;
|
|
11811
|
+
exports.ShopConfigsFirestoreRepository = ShopConfigsFirestoreRepository;
|
|
9280
11812
|
exports.ShopMenu = ShopMenu;
|
|
9281
11813
|
exports.ShopMenuFirestoreRepository = ShopMenuFirestoreRepository;
|
|
9282
11814
|
exports.ShopSettings = ShopSettings;
|
|
9283
11815
|
exports.ShopSettingsFirestoreRepository = ShopSettingsFirestoreRepository;
|
|
11816
|
+
exports.ShoppingRecurrence = ShoppingRecurrence;
|
|
11817
|
+
exports.ShoppingRecurrenceEdition = ShoppingRecurrenceEdition;
|
|
11818
|
+
exports.ShoppingRecurrenceEditionFirestoreRepository = ShoppingRecurrenceEditionFirestoreRepository;
|
|
11819
|
+
exports.ShoppingRecurrenceErrorLog = ShoppingRecurrenceErrorLog;
|
|
11820
|
+
exports.ShoppingRecurrenceErrorLogFirestoreRepository = ShoppingRecurrenceErrorLogFirestoreRepository;
|
|
11821
|
+
exports.ShoppingRecurrenceFirestoreRepository = ShoppingRecurrenceFirestoreRepository;
|
|
9284
11822
|
exports.SignOut = SignOut;
|
|
9285
11823
|
exports.StockLimitError = StockLimitError;
|
|
9286
11824
|
exports.StockOutError = StockOutError;
|