@infrab4a/connect 5.0.0-alpha.9 → 5.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +1154 -533
- package/index.esm.js +1153 -535
- package/package.json +1 -1
- package/src/domain/shopping/enums/index.d.ts +1 -0
- package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +24 -0
- package/src/domain/shopping/models/payment-transaction.d.ts +14 -0
- package/src/domain/shopping/models/payment.d.ts +1 -0
- package/src/domain/shopping/types/index.d.ts +1 -0
- package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +4 -0
- package/src/infra/firebase/firestore/mixins/helpers/firestore-operations.helper.d.ts +1 -1
- package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
- package/src/infra/pagarme/adapters/helpers/index.d.ts +2 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +12 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +9 -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} +5 -5
- package/src/infra/pagarme/adapters/v4/pagarme-pix-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +16 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +10 -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 +3 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +85 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +126 -0
- package/src/infra/pagarme/types/v5/pagarmev5-postback-response.type.d.ts +11 -0
- package/src/utils/circular-dependencies.d.ts +0 -4
- package/src/infra/pagarme/adapters/pagarme-pix-payment-axios.adapter.d.ts +0 -11
package/index.cjs.js
CHANGED
|
@@ -73,6 +73,33 @@ exports.PagarmePaymentStatus = void 0;
|
|
|
73
73
|
PagarmePaymentStatus["Chargedback"] = "chargedback";
|
|
74
74
|
})(exports.PagarmePaymentStatus || (exports.PagarmePaymentStatus = {}));
|
|
75
75
|
|
|
76
|
+
exports.PagarMeV5PaymentStatus = void 0;
|
|
77
|
+
(function (PagarMeV5PaymentStatus) {
|
|
78
|
+
PagarMeV5PaymentStatus["Em processamento"] = "processing";
|
|
79
|
+
PagarMeV5PaymentStatus["Gerado"] = "generated";
|
|
80
|
+
PagarMeV5PaymentStatus["Visualizado"] = "viewed";
|
|
81
|
+
PagarMeV5PaymentStatus["Pago a menor"] = "underpaid";
|
|
82
|
+
PagarMeV5PaymentStatus["Pago a maior"] = "overpaid";
|
|
83
|
+
PagarMeV5PaymentStatus["Aguardando pagamento"] = "waiting_payment";
|
|
84
|
+
PagarMeV5PaymentStatus["Pago"] = "paid";
|
|
85
|
+
PagarMeV5PaymentStatus["Aguardando estorno"] = "pending_refund";
|
|
86
|
+
PagarMeV5PaymentStatus["Autorizada pendente de captura"] = "authorized_pending_capture";
|
|
87
|
+
PagarMeV5PaymentStatus["N\u00E3o autorizada"] = "not_authorized";
|
|
88
|
+
PagarMeV5PaymentStatus["Capturada"] = "captured";
|
|
89
|
+
PagarMeV5PaymentStatus["Aguardando captura"] = "waiting_capture";
|
|
90
|
+
PagarMeV5PaymentStatus["Com erro"] = "with_error";
|
|
91
|
+
PagarMeV5PaymentStatus["Estornado"] = "refunded";
|
|
92
|
+
PagarMeV5PaymentStatus["Cancelado"] = "voided";
|
|
93
|
+
PagarMeV5PaymentStatus["Falha"] = "failed";
|
|
94
|
+
})(exports.PagarMeV5PaymentStatus || (exports.PagarMeV5PaymentStatus = {}));
|
|
95
|
+
exports.PagarMeV5OrderStatus = void 0;
|
|
96
|
+
(function (PagarMeV5OrderStatus) {
|
|
97
|
+
PagarMeV5OrderStatus["Pendente"] = "pending";
|
|
98
|
+
PagarMeV5OrderStatus["Pago"] = "paid";
|
|
99
|
+
PagarMeV5OrderStatus["Cancelado"] = "canceled";
|
|
100
|
+
PagarMeV5OrderStatus["Falha"] = "failed";
|
|
101
|
+
})(exports.PagarMeV5OrderStatus || (exports.PagarMeV5OrderStatus = {}));
|
|
102
|
+
|
|
76
103
|
exports.PaymentMethods = void 0;
|
|
77
104
|
(function (PaymentMethods) {
|
|
78
105
|
PaymentMethods["CARD"] = "card";
|
|
@@ -124,25 +151,15 @@ class PaymentProviderFactory {
|
|
|
124
151
|
}
|
|
125
152
|
}
|
|
126
153
|
|
|
127
|
-
/**
|
|
128
|
-
* Este arquivo define funções para resolver dependências circulares
|
|
129
|
-
* em ambiente ESM, onde não podemos usar require()
|
|
130
|
-
*/
|
|
131
|
-
// Armazenamento global para classes registradas
|
|
132
154
|
const registry = new Map();
|
|
133
|
-
// Registrar uma classe na resolução de dependências circulares
|
|
134
155
|
function registerClass(name, classConstructor) {
|
|
135
156
|
registry.set(name, classConstructor);
|
|
136
157
|
}
|
|
137
|
-
// Obter uma classe registrada
|
|
138
158
|
function getClass(name) {
|
|
139
159
|
return registry.get(name);
|
|
140
160
|
}
|
|
141
|
-
// Função de resolução para class-transformer
|
|
142
161
|
function resolveClass(name) {
|
|
143
162
|
return () => {
|
|
144
|
-
// Forçamos o retorno de uma função que retorna a classe
|
|
145
|
-
// ao invés da classe diretamente para evitar problemas com o decorator
|
|
146
163
|
return getClass(name);
|
|
147
164
|
};
|
|
148
165
|
}
|
|
@@ -216,7 +233,7 @@ class ReflectHelper {
|
|
|
216
233
|
return Reflect.getMetadata(key, target, property) || null;
|
|
217
234
|
}
|
|
218
235
|
}
|
|
219
|
-
catch
|
|
236
|
+
catch {
|
|
220
237
|
return null;
|
|
221
238
|
}
|
|
222
239
|
}
|
|
@@ -526,7 +543,7 @@ function Debug(opts) {
|
|
|
526
543
|
|
|
527
544
|
const ASYNC_IDENTIFIER = 'async';
|
|
528
545
|
function Log(options = {}) {
|
|
529
|
-
return Trace(
|
|
546
|
+
return Trace({ level: 'log', ...options });
|
|
530
547
|
}
|
|
531
548
|
function Trace(options = {}) {
|
|
532
549
|
return function (target, propertyKey, propertyDescriptor) {
|
|
@@ -626,7 +643,7 @@ class BaseModel {
|
|
|
626
643
|
get identifier() {
|
|
627
644
|
const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
|
|
628
645
|
const data = this;
|
|
629
|
-
return fields.reduce((object, field) => (
|
|
646
|
+
return fields.reduce((object, field) => ({ ...object, [field]: data[field] }), {});
|
|
630
647
|
}
|
|
631
648
|
get identifiersFields() {
|
|
632
649
|
return this.constructor.identifiersFields;
|
|
@@ -691,8 +708,7 @@ class Category extends BaseModel {
|
|
|
691
708
|
return ['id'];
|
|
692
709
|
}
|
|
693
710
|
get glamImages() {
|
|
694
|
-
|
|
695
|
-
return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[exports.Shops.GLAMSHOP])
|
|
711
|
+
return this.images?.[exports.Shops.GLAMSHOP]
|
|
696
712
|
? this.images[exports.Shops.GLAMSHOP]
|
|
697
713
|
: {
|
|
698
714
|
brandBanner: null,
|
|
@@ -701,8 +717,7 @@ class Category extends BaseModel {
|
|
|
701
717
|
};
|
|
702
718
|
}
|
|
703
719
|
get mensImages() {
|
|
704
|
-
|
|
705
|
-
return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[exports.Shops.MENSMARKET])
|
|
720
|
+
return this.images?.[exports.Shops.MENSMARKET]
|
|
706
721
|
? this.images[exports.Shops.MENSMARKET]
|
|
707
722
|
: {
|
|
708
723
|
brandBanner: null,
|
|
@@ -717,8 +732,7 @@ class Category extends BaseModel {
|
|
|
717
732
|
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.MENSMARKET);
|
|
718
733
|
}
|
|
719
734
|
getMostRelevantByShop(shop) {
|
|
720
|
-
|
|
721
|
-
return ((_a = this.mostRelevants) === null || _a === void 0 ? void 0 : _a[shop]) || [];
|
|
735
|
+
return this.mostRelevants?.[shop] || [];
|
|
722
736
|
}
|
|
723
737
|
}
|
|
724
738
|
tslib.__decorate([
|
|
@@ -1451,10 +1465,18 @@ class Authentication {
|
|
|
1451
1465
|
return signInMethod === exports.SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
|
|
1452
1466
|
}
|
|
1453
1467
|
async createsUserByCredential(user) {
|
|
1454
|
-
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1457
|
-
|
|
1468
|
+
const [firstName, lastName] = user.displayName?.split(/\s/) ?? [];
|
|
1469
|
+
const person = User.toInstance({
|
|
1470
|
+
...user,
|
|
1471
|
+
cpf: '',
|
|
1472
|
+
birthday: new Date(),
|
|
1473
|
+
firstName,
|
|
1474
|
+
lastName,
|
|
1475
|
+
acceptsNewsletter: false,
|
|
1476
|
+
area: exports.Area.Transactional,
|
|
1477
|
+
officePosition: exports.OfficePosition.Intern,
|
|
1478
|
+
type: exports.UserType.Collaborator,
|
|
1479
|
+
});
|
|
1458
1480
|
return this.userRepository.create(person);
|
|
1459
1481
|
}
|
|
1460
1482
|
}
|
|
@@ -1503,8 +1525,15 @@ class Register {
|
|
|
1503
1525
|
password: params.password,
|
|
1504
1526
|
});
|
|
1505
1527
|
delete params.password;
|
|
1506
|
-
const user = await this.userRepository.create(
|
|
1507
|
-
|
|
1528
|
+
const user = await this.userRepository.create({
|
|
1529
|
+
...params,
|
|
1530
|
+
id: auth.id,
|
|
1531
|
+
email,
|
|
1532
|
+
displayName,
|
|
1533
|
+
type: exports.UserType.B2C,
|
|
1534
|
+
dateCreated: new Date(),
|
|
1535
|
+
dateModified: new Date(),
|
|
1536
|
+
});
|
|
1508
1537
|
return user;
|
|
1509
1538
|
}
|
|
1510
1539
|
}
|
|
@@ -1698,8 +1727,7 @@ class AntifraudBankSlipService {
|
|
|
1698
1727
|
this.MAX_ORDER_VALUE = 5000;
|
|
1699
1728
|
}
|
|
1700
1729
|
async validate(checkout) {
|
|
1701
|
-
|
|
1702
|
-
if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
|
|
1730
|
+
if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !checkout.user?.isSubscriber) {
|
|
1703
1731
|
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
1704
1732
|
checkout,
|
|
1705
1733
|
blockType: 'Boleto not authorized',
|
|
@@ -1710,7 +1738,7 @@ class AntifraudBankSlipService {
|
|
|
1710
1738
|
checkoutId: checkout.id,
|
|
1711
1739
|
userEmail: checkout.user.email,
|
|
1712
1740
|
info: {
|
|
1713
|
-
isSubscriber:
|
|
1741
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1714
1742
|
subtotal: checkout.subTotalPrice,
|
|
1715
1743
|
total: checkout.totalPrice,
|
|
1716
1744
|
},
|
|
@@ -1734,14 +1762,13 @@ class AntifraudCardService {
|
|
|
1734
1762
|
return true;
|
|
1735
1763
|
}
|
|
1736
1764
|
async validateBlockedOrderAttempts(checkout, card) {
|
|
1737
|
-
var _a;
|
|
1738
1765
|
const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
|
|
1739
1766
|
if (!isValid) {
|
|
1740
1767
|
throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
|
|
1741
1768
|
checkoutId: checkout.id,
|
|
1742
1769
|
userEmail: checkout.user.email,
|
|
1743
1770
|
info: {
|
|
1744
|
-
isSubscriber:
|
|
1771
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1745
1772
|
subtotal: checkout.subTotalPrice,
|
|
1746
1773
|
total: checkout.totalPrice,
|
|
1747
1774
|
},
|
|
@@ -1749,14 +1776,13 @@ class AntifraudCardService {
|
|
|
1749
1776
|
}
|
|
1750
1777
|
}
|
|
1751
1778
|
async validateDayAndWeekOrderLimits(checkout, card) {
|
|
1752
|
-
var _a;
|
|
1753
1779
|
const isValid = await this.verifyDayAndWeekOrders(checkout, card);
|
|
1754
1780
|
if (!isValid) {
|
|
1755
1781
|
throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
|
|
1756
1782
|
checkoutId: checkout.id,
|
|
1757
1783
|
userEmail: checkout.user.email,
|
|
1758
1784
|
info: {
|
|
1759
|
-
isSubscriber:
|
|
1785
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1760
1786
|
subtotal: checkout.subTotalPrice,
|
|
1761
1787
|
total: checkout.totalPrice,
|
|
1762
1788
|
},
|
|
@@ -1785,17 +1811,16 @@ class AntifraudCardService {
|
|
|
1785
1811
|
return { day, endOfDay };
|
|
1786
1812
|
}
|
|
1787
1813
|
async getBlockedOrdersByMultipleCriteria(checkout, dateRange) {
|
|
1788
|
-
var _a, _b, _c, _d;
|
|
1789
1814
|
const { day, endOfDay } = dateRange;
|
|
1790
1815
|
const dateFilter = [
|
|
1791
1816
|
{ operator: exports.Where.GTE, value: new Date(day) },
|
|
1792
1817
|
{ operator: exports.Where.LTE, value: new Date(endOfDay) },
|
|
1793
1818
|
];
|
|
1794
1819
|
const [ordersBlockedWithCpf, ordersBlockedWithEmail, ordersBlockedWithCep, ordersBlockedWithPhone] = await Promise.all([
|
|
1795
|
-
this.getBlockedOrdersByCpf(
|
|
1796
|
-
this.getBlockedOrdersByEmail(
|
|
1797
|
-
this.getBlockedOrdersByZip(
|
|
1798
|
-
this.getBlockedOrdersByPhone(
|
|
1820
|
+
this.getBlockedOrdersByCpf(checkout.user?.cpf, dateFilter),
|
|
1821
|
+
this.getBlockedOrdersByEmail(checkout.user?.email, dateFilter),
|
|
1822
|
+
this.getBlockedOrdersByZip(checkout.shippingAddress?.zip, dateFilter),
|
|
1823
|
+
this.getBlockedOrdersByPhone(checkout.user?.phone, dateFilter),
|
|
1799
1824
|
]);
|
|
1800
1825
|
return {
|
|
1801
1826
|
ordersBlockedWithCpf,
|
|
@@ -1852,18 +1877,15 @@ class AntifraudCardService {
|
|
|
1852
1877
|
return ordersBlockedWithCpf.concat(blockedUniqueEmails).concat(blockedUniqueCeps).concat(blockedUniquePhone).length;
|
|
1853
1878
|
}
|
|
1854
1879
|
filterUniqueEmailBlocked(ordersBlockedWithEmail, checkout) {
|
|
1855
|
-
return ordersBlockedWithEmail.filter((e) =>
|
|
1880
|
+
return ordersBlockedWithEmail.filter((e) => e.customer.cpf !== checkout.user?.cpf);
|
|
1856
1881
|
}
|
|
1857
1882
|
filterUniqueZipBlocked(ordersBlockedWithCep, checkout) {
|
|
1858
|
-
return ordersBlockedWithCep.filter((e) =>
|
|
1883
|
+
return ordersBlockedWithCep.filter((e) => e.customer.cpf !== checkout.user?.cpf && e.customer.email !== checkout.user?.email);
|
|
1859
1884
|
}
|
|
1860
1885
|
filterUniquePhoneBlocked(ordersBlockedWithPhone, checkout) {
|
|
1861
|
-
return ordersBlockedWithPhone.filter((e) =>
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
|
|
1865
|
-
((_d = (_c = e.customer.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip) === null || _d === void 0 ? void 0 : _d.toString()) !== ((_f = (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.zip) === null || _f === void 0 ? void 0 : _f.toString());
|
|
1866
|
-
});
|
|
1886
|
+
return ordersBlockedWithPhone.filter((e) => e.customer.cpf !== checkout.user?.cpf &&
|
|
1887
|
+
e.customer.email !== checkout.user?.email &&
|
|
1888
|
+
e.customer.shippingAddress?.zip?.toString() !== checkout.shippingAddress?.zip?.toString());
|
|
1867
1889
|
}
|
|
1868
1890
|
async createBlockedOrderRecord(params) {
|
|
1869
1891
|
const { checkout, card, reason, key, period } = params;
|
|
@@ -1884,12 +1906,11 @@ class AntifraudCardService {
|
|
|
1884
1906
|
return isWeekLimitValid;
|
|
1885
1907
|
}
|
|
1886
1908
|
buildValidationParams(checkout, card) {
|
|
1887
|
-
var _a, _b, _c, _d;
|
|
1888
1909
|
return {
|
|
1889
|
-
cpf:
|
|
1890
|
-
email:
|
|
1891
|
-
phone:
|
|
1892
|
-
zip:
|
|
1910
|
+
cpf: checkout.user?.cpf,
|
|
1911
|
+
email: checkout.user?.email,
|
|
1912
|
+
phone: checkout.user?.phone,
|
|
1913
|
+
zip: checkout.shippingAddress?.zip,
|
|
1893
1914
|
card,
|
|
1894
1915
|
};
|
|
1895
1916
|
}
|
|
@@ -1914,7 +1935,7 @@ class AntifraudCardService {
|
|
|
1914
1935
|
async checkOrderLimitsAndBlock(params) {
|
|
1915
1936
|
const { checkout, orderCounts, limit, period } = params;
|
|
1916
1937
|
for (const key in orderCounts) {
|
|
1917
|
-
if (orderCounts[key]
|
|
1938
|
+
if (orderCounts[key] >= limit) {
|
|
1918
1939
|
await this.createBlockedOrderRecord({
|
|
1919
1940
|
checkout,
|
|
1920
1941
|
card: null,
|
|
@@ -1928,18 +1949,20 @@ class AntifraudCardService {
|
|
|
1928
1949
|
return true;
|
|
1929
1950
|
}
|
|
1930
1951
|
async validateOrdersByRange(params, range) {
|
|
1931
|
-
const { cpf, email, phone, zip } = params;
|
|
1932
|
-
const [ordersCpf, ordersByEmail, ordersByPhone, ordersByZip] = await Promise.all([
|
|
1952
|
+
const { cpf, email, phone, zip, card } = params;
|
|
1953
|
+
const [ordersCpf, ordersByEmail, ordersByPhone, ordersByZip, ordersByCard] = await Promise.all([
|
|
1933
1954
|
this.countOrdersByField({ property: 'user', field: 'cpf', value: cpf, range }),
|
|
1934
1955
|
this.countOrdersByField({ property: 'user', field: 'email', value: email, range }),
|
|
1935
1956
|
this.countOrdersByField({ property: 'user', field: 'phone', value: phone, range }),
|
|
1936
1957
|
this.countOrdersByField({ property: 'shippingAddress', field: 'zip', value: zip, range }),
|
|
1958
|
+
this.countOrdersByField({ property: 'payment', field: 'card.id', value: card.cardId, range }),
|
|
1937
1959
|
]);
|
|
1938
1960
|
return {
|
|
1939
1961
|
cpf: ordersCpf,
|
|
1940
1962
|
email: ordersByEmail,
|
|
1941
1963
|
phone: ordersByPhone,
|
|
1942
1964
|
zip: ordersByZip,
|
|
1965
|
+
card: ordersByCard,
|
|
1943
1966
|
};
|
|
1944
1967
|
}
|
|
1945
1968
|
async countOrdersByField(params) {
|
|
@@ -1953,8 +1976,8 @@ class AntifraudCardService {
|
|
|
1953
1976
|
{ operator: exports.Where.LTE, value: range.lastDate },
|
|
1954
1977
|
],
|
|
1955
1978
|
};
|
|
1956
|
-
const
|
|
1957
|
-
return
|
|
1979
|
+
const { count } = await this.orderRepository.find({ filters });
|
|
1980
|
+
return count;
|
|
1958
1981
|
}
|
|
1959
1982
|
getDateRange(range = 'day') {
|
|
1960
1983
|
switch (range) {
|
|
@@ -2025,10 +2048,9 @@ class GlampointsPaymentService {
|
|
|
2025
2048
|
return payment;
|
|
2026
2049
|
}
|
|
2027
2050
|
async rewardByOrder(order, user) {
|
|
2028
|
-
var _a;
|
|
2029
2051
|
try {
|
|
2030
2052
|
const points = order.lineItems.filter((item) => !item.isGift).reduce((acc, li) => acc + li.quantity, 0);
|
|
2031
|
-
const hasGlambeauty =
|
|
2053
|
+
const hasGlambeauty = order.lineItems?.some((doc) => doc.brand && doc.brand.toUpperCase() === 'GLAM BEAUTY');
|
|
2032
2054
|
const result = await axios__default["default"]({
|
|
2033
2055
|
method: 'POST',
|
|
2034
2056
|
url: `${this.glamCredentials.baseUrl}/integration/win/reward`,
|
|
@@ -2289,7 +2311,7 @@ class AdyenPaymentFactoryHelper {
|
|
|
2289
2311
|
checkoutId: checkout.id,
|
|
2290
2312
|
totalPrice: checkout.totalPrice,
|
|
2291
2313
|
paymentProvider: 'adyen',
|
|
2292
|
-
transaction:
|
|
2314
|
+
transaction: { ...adyenResponse, status: 'paid' },
|
|
2293
2315
|
});
|
|
2294
2316
|
return paymentRepository.create(paymentData);
|
|
2295
2317
|
}
|
|
@@ -2300,7 +2322,7 @@ class AdyenPaymentOperationsHelper {
|
|
|
2300
2322
|
return {
|
|
2301
2323
|
amount: {
|
|
2302
2324
|
currency: 'BRL',
|
|
2303
|
-
value: (
|
|
2325
|
+
value: (checkout?.totalPrice || 0) * 100,
|
|
2304
2326
|
},
|
|
2305
2327
|
paymentMethod: {
|
|
2306
2328
|
type: 'scheme',
|
|
@@ -2385,7 +2407,11 @@ class RestCacheAdapter {
|
|
|
2385
2407
|
this.logger = new DebugHelper('RestCacheAdapter');
|
|
2386
2408
|
this.client = axios__default["default"].create({
|
|
2387
2409
|
baseURL: config.baseURL,
|
|
2388
|
-
headers:
|
|
2410
|
+
headers: {
|
|
2411
|
+
'Content-Type': 'application/json',
|
|
2412
|
+
...(lodash.isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` }),
|
|
2413
|
+
...(lodash.isNil(config.mobileApiKey) ? {} : { 'X-Mobile-API-Key': config.mobileApiKey }),
|
|
2414
|
+
},
|
|
2389
2415
|
});
|
|
2390
2416
|
}
|
|
2391
2417
|
async set(options) {
|
|
@@ -2641,7 +2667,10 @@ class ElasticSearchResultProcessorHelper {
|
|
|
2641
2667
|
});
|
|
2642
2668
|
}
|
|
2643
2669
|
static transformHitsToProducts(hits) {
|
|
2644
|
-
return hits.map((hit) => (
|
|
2670
|
+
return hits.map((hit) => ({
|
|
2671
|
+
...hit._source,
|
|
2672
|
+
stock: hit._source.stock.quantity,
|
|
2673
|
+
}));
|
|
2645
2674
|
}
|
|
2646
2675
|
}
|
|
2647
2676
|
|
|
@@ -2784,11 +2813,11 @@ class FirestoreDataConverterHelper {
|
|
|
2784
2813
|
return (data &&
|
|
2785
2814
|
!Array.isArray(data) &&
|
|
2786
2815
|
typeof data === 'object' &&
|
|
2787
|
-
|
|
2816
|
+
data?.constructor.name !== 'Timestamp' &&
|
|
2788
2817
|
!('seconds' in data));
|
|
2789
2818
|
}
|
|
2790
2819
|
static convertToDate(data, keyName) {
|
|
2791
|
-
if (
|
|
2820
|
+
if (data?.constructor.name === 'Timestamp')
|
|
2792
2821
|
return data.toDate();
|
|
2793
2822
|
if (data && typeof data === 'object' && 'seconds' in data)
|
|
2794
2823
|
return new Date(data.seconds * 1000);
|
|
@@ -2833,7 +2862,7 @@ class FirestoreModelConverterHelper {
|
|
|
2833
2862
|
}
|
|
2834
2863
|
buildToFirestoreConverter() {
|
|
2835
2864
|
return (data) => {
|
|
2836
|
-
const plain =
|
|
2865
|
+
const plain = data?.toPlain ? data.toPlain() : data;
|
|
2837
2866
|
return FirestoreModelConverterHelper.omitByRecursivelyInPlace(plain, (value) => value === undefined);
|
|
2838
2867
|
};
|
|
2839
2868
|
}
|
|
@@ -2843,7 +2872,7 @@ class FirestoreModelConverterHelper {
|
|
|
2843
2872
|
const data = snap.data();
|
|
2844
2873
|
const ids = { id: snap.id };
|
|
2845
2874
|
const bindedData = FirestoreDataConverterHelper.bindAllDateFromObject(data);
|
|
2846
|
-
return this.model.toInstance(
|
|
2875
|
+
return this.model.toInstance({ ...bindedData, ...ids });
|
|
2847
2876
|
}
|
|
2848
2877
|
catch (error) {
|
|
2849
2878
|
this.handleConversionError(snap.id, snap.data(), error);
|
|
@@ -2911,18 +2940,17 @@ const withHelpers = (MixinBase) => {
|
|
|
2911
2940
|
class AttributeOptionHelper {
|
|
2912
2941
|
}
|
|
2913
2942
|
AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
2914
|
-
var _a;
|
|
2915
2943
|
if (fields.includes(attributeName))
|
|
2916
2944
|
return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
|
|
2917
2945
|
const field = fields.find((columnOption) => lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
2918
|
-
const fieldOption =
|
|
2946
|
+
const fieldOption = is(field)?.[attributeName];
|
|
2919
2947
|
if (lodash.isNil(fieldOption))
|
|
2920
2948
|
return { columnName: attributeName.toString(), attributeName };
|
|
2921
2949
|
if (Array.isArray(fieldOption))
|
|
2922
2950
|
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
2923
|
-
return
|
|
2951
|
+
return { attributeName, columnName: attributeName.toString(), ...fieldOption };
|
|
2924
2952
|
};
|
|
2925
|
-
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!
|
|
2953
|
+
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
|
|
2926
2954
|
AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
2927
2955
|
if (fields.includes(columnName))
|
|
2928
2956
|
return { columnName, attributeName: columnName };
|
|
@@ -2930,13 +2958,17 @@ AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
|
2930
2958
|
if (!lodash.isObject(field))
|
|
2931
2959
|
return false;
|
|
2932
2960
|
const columnOption = Object.values(field).find((option) => AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName ? option : {});
|
|
2933
|
-
return AttributeOptionHelper.CheckIsColumnOption(columnOption) &&
|
|
2961
|
+
return AttributeOptionHelper.CheckIsColumnOption(columnOption) && columnOption?.columnName === columnName;
|
|
2934
2962
|
}) || {});
|
|
2935
2963
|
const attributeName = Object.keys(field).find((fieldOptionFromList) => AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) || Array.isArray(field[fieldOptionFromList]));
|
|
2936
|
-
const fieldOption = field
|
|
2964
|
+
const fieldOption = field?.[attributeName];
|
|
2937
2965
|
if (Array.isArray(fieldOption))
|
|
2938
2966
|
return { attributeName: attributeName, fields: fieldOption };
|
|
2939
|
-
return
|
|
2967
|
+
return {
|
|
2968
|
+
attributeName: attributeName || columnName,
|
|
2969
|
+
columnName,
|
|
2970
|
+
...fieldOption,
|
|
2971
|
+
};
|
|
2940
2972
|
};
|
|
2941
2973
|
|
|
2942
2974
|
var HasuraGraphQLWhere;
|
|
@@ -2974,7 +3006,7 @@ var HasuraGraphQLColumnType;
|
|
|
2974
3006
|
|
|
2975
3007
|
class FilterOptionHelper {
|
|
2976
3008
|
}
|
|
2977
|
-
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !lodash.isNil(filter
|
|
3009
|
+
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !lodash.isNil(filter?.operator);
|
|
2978
3010
|
FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
|
|
2979
3011
|
if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
|
|
2980
3012
|
return filter;
|
|
@@ -3035,25 +3067,37 @@ class BindFilterQueryHelper {
|
|
|
3035
3067
|
BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => {
|
|
3036
3068
|
const columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
|
|
3037
3069
|
if (!columnOption.bindFindFilter)
|
|
3038
|
-
return
|
|
3039
|
-
|
|
3040
|
-
|
|
3070
|
+
return {
|
|
3071
|
+
...variables,
|
|
3072
|
+
...{
|
|
3073
|
+
[columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
|
|
3074
|
+
},
|
|
3075
|
+
};
|
|
3041
3076
|
const builtFilter = columnOption.bindFindFilter(filter[fieldName]);
|
|
3042
|
-
return
|
|
3077
|
+
return {
|
|
3078
|
+
...variables,
|
|
3079
|
+
...Object.keys(builtFilter).reduce((variablesList, columnName) => ({
|
|
3080
|
+
...variablesList,
|
|
3081
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields),
|
|
3082
|
+
}), {}),
|
|
3083
|
+
};
|
|
3043
3084
|
}, {});
|
|
3044
3085
|
BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
3045
3086
|
const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
3046
3087
|
const isNestedField = !Array.isArray(options) &&
|
|
3047
3088
|
lodash.isObject(options) &&
|
|
3048
|
-
lodash.isNil(options
|
|
3049
|
-
lodash.isNil(options
|
|
3050
|
-
lodash.isNil(fieldSentenceOptions
|
|
3089
|
+
lodash.isNil(options?.operator) &&
|
|
3090
|
+
lodash.isNil(options?.value) &&
|
|
3091
|
+
lodash.isNil(fieldSentenceOptions?.to);
|
|
3051
3092
|
if (isNestedField)
|
|
3052
3093
|
return Object.keys(options).reduce((variables, key) => {
|
|
3053
|
-
const fieldOptions = AttributeOptionHelper.FindByAttribute(key,
|
|
3094
|
+
const fieldOptions = AttributeOptionHelper.FindByAttribute(key, fieldSentenceOptions?.fields || fields);
|
|
3054
3095
|
const columnName = fieldOptions.columnName;
|
|
3055
3096
|
const columnFields = fieldOptions.fields;
|
|
3056
|
-
return
|
|
3097
|
+
return {
|
|
3098
|
+
...variables,
|
|
3099
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), fieldSentenceOptions?.fields || columnFields || fields),
|
|
3100
|
+
};
|
|
3057
3101
|
}, {});
|
|
3058
3102
|
if (!Array.isArray(options) && !lodash.isNil(fieldSentenceOptions.fields))
|
|
3059
3103
|
return {
|
|
@@ -3062,7 +3106,10 @@ BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
|
3062
3106
|
if (!Array.isArray(options) && lodash.isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
3063
3107
|
options = Object.values(options)[0];
|
|
3064
3108
|
return Array.isArray(options)
|
|
3065
|
-
? options.reduce((whereSentence, option) => (
|
|
3109
|
+
? options.reduce((whereSentence, option) => ({
|
|
3110
|
+
...whereSentence,
|
|
3111
|
+
...BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions),
|
|
3112
|
+
}), {})
|
|
3066
3113
|
: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions);
|
|
3067
3114
|
};
|
|
3068
3115
|
BindFilterQueryHelper.BuildOperatorSentence = (options, fieldOption) => ({
|
|
@@ -3078,14 +3125,14 @@ BindFilterQueryHelper.GetHasuraOperator = (options, fieldOption) => FilterOption
|
|
|
3078
3125
|
: options.operator === exports.Where.LIKE && options.ignoreCase
|
|
3079
3126
|
? HasuraGraphQLWhere.ILIKE
|
|
3080
3127
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3081
|
-
Object.keys(exports.Where).find((operator) => exports.Where[operator] ===
|
|
3128
|
+
Object.keys(exports.Where).find((operator) => exports.Where[operator] === options?.operator))]
|
|
3082
3129
|
: HasuraGraphQLWhere.EQUALS;
|
|
3083
3130
|
BindFilterQueryHelper.GetHasuraJsonbOperator = (options) => options.operator === exports.Where.IN
|
|
3084
3131
|
? HasuraGraphQLWhere.JSON_CONTAINS
|
|
3085
3132
|
: options.operator === exports.Where.LIKE
|
|
3086
3133
|
? HasuraGraphQLWhere.JSON_HAS_KEYS_ANY
|
|
3087
3134
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3088
|
-
Object.keys(exports.Where).find((operator) => exports.Where[operator] ===
|
|
3135
|
+
Object.keys(exports.Where).find((operator) => exports.Where[operator] === options?.operator))];
|
|
3089
3136
|
|
|
3090
3137
|
class CacheKeyGeneratorHelper {
|
|
3091
3138
|
static generateCacheKeyFromIdentifiers(modelOrModelName, identifiers) {
|
|
@@ -3100,7 +3147,8 @@ class GraphQLFieldHelper {
|
|
|
3100
3147
|
}
|
|
3101
3148
|
GraphQLFieldHelper.CheckIsGraphQLParams = (params) => !lodash.isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
|
|
3102
3149
|
GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
3103
|
-
return fields
|
|
3150
|
+
return fields
|
|
3151
|
+
?.map((field) => {
|
|
3104
3152
|
if (lodash.isString(field))
|
|
3105
3153
|
return field.toString();
|
|
3106
3154
|
if (field === 'affected_rows')
|
|
@@ -3115,41 +3163,55 @@ GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
|
3115
3163
|
if (isNestedField)
|
|
3116
3164
|
return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
|
|
3117
3165
|
return fieldValue.columnName;
|
|
3118
|
-
})
|
|
3166
|
+
})
|
|
3167
|
+
.filter((field) => !!field);
|
|
3119
3168
|
};
|
|
3120
3169
|
GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
|
|
3121
3170
|
const { attributeName, fields: attributeFields, from, } = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields);
|
|
3122
3171
|
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
3123
3172
|
if (Array.isArray(data[columnName]))
|
|
3124
|
-
return
|
|
3173
|
+
return {
|
|
3174
|
+
...result,
|
|
3175
|
+
[attributeName]: from
|
|
3125
3176
|
? from(data[columnName], data)
|
|
3126
|
-
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields))
|
|
3177
|
+
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)),
|
|
3178
|
+
};
|
|
3127
3179
|
if (lodash.isObject(data[columnName]))
|
|
3128
|
-
return
|
|
3180
|
+
return {
|
|
3181
|
+
...result,
|
|
3182
|
+
[attributeName]: from
|
|
3129
3183
|
? from(data[columnName])
|
|
3130
|
-
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields)
|
|
3184
|
+
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields),
|
|
3185
|
+
};
|
|
3131
3186
|
}
|
|
3132
3187
|
if (from)
|
|
3133
|
-
return
|
|
3134
|
-
return
|
|
3188
|
+
return { ...result, [attributeName]: from(data[columnName], data) };
|
|
3189
|
+
return {
|
|
3190
|
+
...result,
|
|
3191
|
+
[attributeName]: lodash.isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName],
|
|
3192
|
+
};
|
|
3135
3193
|
}, {});
|
|
3136
3194
|
GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
3137
|
-
|
|
3138
|
-
const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
3195
|
+
const data = instance.toPlain?.() || instance;
|
|
3139
3196
|
return Object.keys(data).reduce((result, attributeName) => {
|
|
3140
3197
|
const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
|
|
3141
3198
|
if (bindPersistData)
|
|
3142
|
-
return
|
|
3199
|
+
return {
|
|
3200
|
+
...result,
|
|
3201
|
+
...bindPersistData(data[attributeName], instance),
|
|
3202
|
+
};
|
|
3143
3203
|
if (lodash.isNil(columnName))
|
|
3144
3204
|
return result;
|
|
3145
3205
|
if (!!foreignKeyColumn &&
|
|
3146
3206
|
!lodash.isEmpty(foreignKeyColumn) &&
|
|
3147
|
-
!Object.keys(foreignKeyColumn).filter((key) =>
|
|
3207
|
+
!Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
|
|
3148
3208
|
return Object.keys(foreignKeyColumn).reduce((object, current) => {
|
|
3149
|
-
var _a;
|
|
3150
3209
|
const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
|
|
3151
|
-
return
|
|
3152
|
-
|
|
3210
|
+
return {
|
|
3211
|
+
...object,
|
|
3212
|
+
[foreignColumnName]: data[attributeName]?.[current],
|
|
3213
|
+
};
|
|
3214
|
+
}, { ...result });
|
|
3153
3215
|
if (update &&
|
|
3154
3216
|
lodash.isObject(data[attributeName]) &&
|
|
3155
3217
|
!lodash.isNil(attributeFields) &&
|
|
@@ -3161,19 +3223,25 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
3161
3223
|
const converted = !lodash.isNil(columnName) && to
|
|
3162
3224
|
? to(instance[attributeName], instance)
|
|
3163
3225
|
: data[attributeName];
|
|
3164
|
-
return
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
:
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3226
|
+
return {
|
|
3227
|
+
...result,
|
|
3228
|
+
...(converted !== undefined
|
|
3229
|
+
? {
|
|
3230
|
+
[columnName]: {
|
|
3231
|
+
data: instance[attributeName] instanceof BaseModel
|
|
3232
|
+
? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
|
|
3233
|
+
: converted,
|
|
3234
|
+
},
|
|
3235
|
+
}
|
|
3236
|
+
: {}),
|
|
3237
|
+
};
|
|
3173
3238
|
}
|
|
3174
3239
|
if (to)
|
|
3175
|
-
return
|
|
3176
|
-
|
|
3240
|
+
return {
|
|
3241
|
+
...result,
|
|
3242
|
+
[columnName]: to(instance[attributeName], instance),
|
|
3243
|
+
};
|
|
3244
|
+
return { ...result, [columnName]: data[attributeName] };
|
|
3177
3245
|
}, {});
|
|
3178
3246
|
};
|
|
3179
3247
|
GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
|
|
@@ -3231,13 +3299,17 @@ class MD5GeneratorHelper {
|
|
|
3231
3299
|
|
|
3232
3300
|
class HasuraAuthHelper {
|
|
3233
3301
|
static buildHeaders(authOptions) {
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
? {}
|
|
3237
|
-
: {
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3302
|
+
return {
|
|
3303
|
+
'Content-Type': 'application/json',
|
|
3304
|
+
...(lodash.isNil(authOptions?.authToken) ? {} : { Authorization: authOptions?.authToken }),
|
|
3305
|
+
...(lodash.isNil(authOptions?.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': authOptions?.adminSecret }),
|
|
3306
|
+
...(lodash.isNil(authOptions?.authRole)
|
|
3307
|
+
? {}
|
|
3308
|
+
: {
|
|
3309
|
+
'X-Hasura-Role': authOptions.authRole.role,
|
|
3310
|
+
'X-Hasura-User-Id': authOptions?.authRole?.userId,
|
|
3311
|
+
}),
|
|
3312
|
+
};
|
|
3241
3313
|
}
|
|
3242
3314
|
}
|
|
3243
3315
|
|
|
@@ -3327,17 +3399,21 @@ class HasuraGraphQLOperationsHelper {
|
|
|
3327
3399
|
return this.executeFetch({ query: resultQuery, operationParams });
|
|
3328
3400
|
}
|
|
3329
3401
|
static async executeQuery(params) {
|
|
3330
|
-
var _a, _b, _c, _d;
|
|
3331
3402
|
const { operation, fields, variables, operationParams, buildHasuraQueryFields } = params;
|
|
3332
3403
|
const builded = buildHasuraQueryFields({ operation, fields, variables });
|
|
3333
|
-
const intercepted = (await
|
|
3404
|
+
const intercepted = (await operationParams.interceptors?.request?.(builded)) || builded;
|
|
3334
3405
|
const resultQuery = HasuraQueryBuilderHelper.buildQuery(intercepted);
|
|
3335
3406
|
const result = await this.executeFetch({ query: resultQuery, operationParams });
|
|
3336
|
-
return (await
|
|
3407
|
+
return (await operationParams.interceptors?.response?.(result, intercepted)) || result;
|
|
3337
3408
|
}
|
|
3338
3409
|
static async executeFetch(params) {
|
|
3339
3410
|
const { query, operationParams } = params;
|
|
3340
|
-
return HasuraRequestHelper.fetch(
|
|
3411
|
+
return HasuraRequestHelper.fetch({
|
|
3412
|
+
...query,
|
|
3413
|
+
endpoint: operationParams.endpoint,
|
|
3414
|
+
headers: HasuraAuthHelper.buildHeaders(operationParams.authOptions),
|
|
3415
|
+
logger: operationParams.logger,
|
|
3416
|
+
});
|
|
3341
3417
|
}
|
|
3342
3418
|
}
|
|
3343
3419
|
|
|
@@ -3351,12 +3427,10 @@ class HasuraColumnHelper {
|
|
|
3351
3427
|
const columnOptions = Object.values(field).shift();
|
|
3352
3428
|
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
3353
3429
|
columnOptions.foreignKeyColumn && [
|
|
3354
|
-
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) =>
|
|
3430
|
+
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => AttributeOptionHelper.FindByAttribute(foreignKeyName, fields)?.columnName),
|
|
3355
3431
|
{
|
|
3356
|
-
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) =>
|
|
3357
|
-
|
|
3358
|
-
return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || foreignKeyField;
|
|
3359
|
-
}),
|
|
3432
|
+
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
|
|
3433
|
+
?.columnName || foreignKeyField),
|
|
3360
3434
|
},
|
|
3361
3435
|
]);
|
|
3362
3436
|
})
|
|
@@ -3381,7 +3455,7 @@ class HasuraCreateOperationsHelper {
|
|
|
3381
3455
|
const { model } = params;
|
|
3382
3456
|
params.repository.logger = DebugHelper.from(params.repository, 'create');
|
|
3383
3457
|
const instance = model.toInstance(data);
|
|
3384
|
-
const newData = await this.executeSave(
|
|
3458
|
+
const newData = await this.executeSave({ ...params, data: instance });
|
|
3385
3459
|
return model.toInstance(newData);
|
|
3386
3460
|
}
|
|
3387
3461
|
static async executeSave(params) {
|
|
@@ -3395,14 +3469,14 @@ class HasuraCreateOperationsHelper {
|
|
|
3395
3469
|
},
|
|
3396
3470
|
});
|
|
3397
3471
|
const convertedResult = repository.convertDataFromHasura(result[insertGraphQLOperation]);
|
|
3398
|
-
return
|
|
3472
|
+
return { ...data.toPlain(), ...convertedResult.toPlain() };
|
|
3399
3473
|
}
|
|
3400
3474
|
}
|
|
3401
3475
|
|
|
3402
3476
|
class HasuraCacheOperationsHelper {
|
|
3403
3477
|
static async removeCacheData(cache, params) {
|
|
3404
3478
|
const { model, identifiers, logger } = params;
|
|
3405
|
-
if (!
|
|
3479
|
+
if (!cache?.cacheAdapter)
|
|
3406
3480
|
return;
|
|
3407
3481
|
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3408
3482
|
await cache.cacheAdapter.remove(cacheKey);
|
|
@@ -3422,13 +3496,16 @@ class HasuraDeleteVariablesHelper {
|
|
|
3422
3496
|
if (lodash.isNil(instance.identifier[identifierBinded]))
|
|
3423
3497
|
return ids;
|
|
3424
3498
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
|
|
3425
|
-
const value =
|
|
3499
|
+
const value = columnOption?.to(identifiers[identifier], instance) ||
|
|
3426
3500
|
identifiers[identifier];
|
|
3427
|
-
return
|
|
3501
|
+
return {
|
|
3502
|
+
...ids,
|
|
3503
|
+
[columnOption.columnName]: {
|
|
3428
3504
|
type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3429
3505
|
value,
|
|
3430
3506
|
required: true,
|
|
3431
|
-
}
|
|
3507
|
+
},
|
|
3508
|
+
};
|
|
3432
3509
|
}, {});
|
|
3433
3510
|
}
|
|
3434
3511
|
}
|
|
@@ -3466,16 +3543,15 @@ class HasuraFindBindingHelper {
|
|
|
3466
3543
|
], []);
|
|
3467
3544
|
}
|
|
3468
3545
|
static bindAggregateAttributes(aggregates, fields) {
|
|
3469
|
-
var _a, _b;
|
|
3470
3546
|
return [
|
|
3471
|
-
...(
|
|
3547
|
+
...(aggregates?.minimal?.length
|
|
3472
3548
|
? [
|
|
3473
3549
|
{
|
|
3474
3550
|
min: this.bindAttributesToColumns(aggregates.minimal, fields),
|
|
3475
3551
|
},
|
|
3476
3552
|
]
|
|
3477
3553
|
: []),
|
|
3478
|
-
...(
|
|
3554
|
+
...(aggregates?.maximum?.length
|
|
3479
3555
|
? [
|
|
3480
3556
|
{
|
|
3481
3557
|
max: this.bindAttributesToColumns(aggregates.maximum, fields),
|
|
@@ -3502,7 +3578,7 @@ class HasuraFindBindingHelper {
|
|
|
3502
3578
|
});
|
|
3503
3579
|
if (typeof fieldOption === 'object' && fieldOption !== null) {
|
|
3504
3580
|
const columnOption = fieldOption[attributeName];
|
|
3505
|
-
return
|
|
3581
|
+
return columnOption?.columnName || attributeName;
|
|
3506
3582
|
}
|
|
3507
3583
|
return attributeName;
|
|
3508
3584
|
}
|
|
@@ -3515,27 +3591,27 @@ class HasuraFindCacheHelper {
|
|
|
3515
3591
|
}
|
|
3516
3592
|
static async getCachedResult(params) {
|
|
3517
3593
|
const { cache, model, findParams, cacheOptions, logger } = params;
|
|
3518
|
-
if (!
|
|
3594
|
+
if (!cache?.cacheAdapter || !cacheOptions?.enabled)
|
|
3519
3595
|
return null;
|
|
3520
3596
|
const cacheKey = this.generateCacheKey(model, findParams);
|
|
3521
3597
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
3522
3598
|
if (cachedData) {
|
|
3523
|
-
logger
|
|
3599
|
+
logger?.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
3524
3600
|
return deserialize(cachedData);
|
|
3525
3601
|
}
|
|
3526
3602
|
return null;
|
|
3527
3603
|
}
|
|
3528
3604
|
static async setCachedResult(params) {
|
|
3529
3605
|
const { cache, model, findParams, cacheOptions, result, logger } = params;
|
|
3530
|
-
if (!
|
|
3606
|
+
if (!cache?.cacheAdapter || !cacheOptions?.enabled)
|
|
3531
3607
|
return;
|
|
3532
3608
|
const cacheKey = this.generateCacheKey(model, findParams);
|
|
3533
3609
|
await cache.cacheAdapter.set({
|
|
3534
3610
|
key: cacheKey,
|
|
3535
3611
|
data: serialize(result),
|
|
3536
|
-
expirationInSeconds:
|
|
3612
|
+
expirationInSeconds: cacheOptions?.ttl || cache.ttlDefault,
|
|
3537
3613
|
});
|
|
3538
|
-
logger
|
|
3614
|
+
logger?.log(`Dados salvos no cache: ${cacheKey}`);
|
|
3539
3615
|
}
|
|
3540
3616
|
}
|
|
3541
3617
|
|
|
@@ -3543,27 +3619,40 @@ class HasuraFindResultHelper {
|
|
|
3543
3619
|
static processResult(params) {
|
|
3544
3620
|
const { result, tableName, enableCount, findOptions, tableFiltersNamed, fields, convertDataFromHasura, lastDistinct, } = params;
|
|
3545
3621
|
const data = result[tableName].map((row) => convertDataFromHasura(row));
|
|
3546
|
-
const findResult =
|
|
3622
|
+
const findResult = {
|
|
3623
|
+
data,
|
|
3624
|
+
count: enableCount ? result[`${tableName}_aggregate`].aggregate.count : Infinity,
|
|
3625
|
+
...this.processMinimalAggregates({ result, tableName, findOptions, fields }),
|
|
3626
|
+
...this.processMaximumAggregates({ result, tableName, findOptions, fields }),
|
|
3627
|
+
...this.processDistinctResults({ result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct }),
|
|
3628
|
+
};
|
|
3547
3629
|
return findResult;
|
|
3548
3630
|
}
|
|
3549
3631
|
static bindAggregateAttributes(params) {
|
|
3550
|
-
var _a, _b;
|
|
3551
3632
|
const { aggregates, fields } = params;
|
|
3552
3633
|
const convertFieldName = (fieldName) => {
|
|
3553
|
-
var _a, _b;
|
|
3554
3634
|
const finalFieldName = fieldName.toString().split('.').pop();
|
|
3555
|
-
const fieldOption =
|
|
3556
|
-
|
|
3635
|
+
const fieldOption = fields.find((fieldOption) => {
|
|
3636
|
+
if (typeof fieldOption === 'string')
|
|
3637
|
+
return fieldOption === finalFieldName;
|
|
3638
|
+
const key = Object.keys(fieldOption)[0];
|
|
3639
|
+
return key === finalFieldName;
|
|
3640
|
+
});
|
|
3641
|
+
if (fieldOption && typeof fieldOption !== 'string') {
|
|
3642
|
+
const fieldValue = Object.values(fieldOption)[0];
|
|
3643
|
+
return fieldValue?.columnName || finalFieldName;
|
|
3644
|
+
}
|
|
3645
|
+
return finalFieldName;
|
|
3557
3646
|
};
|
|
3558
3647
|
return [
|
|
3559
|
-
...(
|
|
3648
|
+
...(aggregates?.minimal?.length
|
|
3560
3649
|
? [
|
|
3561
3650
|
{
|
|
3562
3651
|
min: aggregates.minimal.map(convertFieldName),
|
|
3563
3652
|
},
|
|
3564
3653
|
]
|
|
3565
3654
|
: []),
|
|
3566
|
-
...(
|
|
3655
|
+
...(aggregates?.maximum?.length
|
|
3567
3656
|
? [
|
|
3568
3657
|
{
|
|
3569
3658
|
max: aggregates.maximum.map(convertFieldName),
|
|
@@ -3573,48 +3662,52 @@ class HasuraFindResultHelper {
|
|
|
3573
3662
|
];
|
|
3574
3663
|
}
|
|
3575
3664
|
static processMinimalAggregates(params) {
|
|
3576
|
-
var _a;
|
|
3577
3665
|
const { result, tableName, findOptions, fields } = params;
|
|
3578
|
-
return
|
|
3666
|
+
return findOptions?.minimal?.length
|
|
3579
3667
|
? {
|
|
3580
3668
|
minimal: findOptions.minimal.reduce((minimals, current) => {
|
|
3581
|
-
|
|
3582
|
-
return
|
|
3669
|
+
const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
|
|
3670
|
+
return {
|
|
3671
|
+
...minimals,
|
|
3672
|
+
...lodash.set(minimals, current, result[`${tableName}_aggregate`].aggregate.min[columnName]),
|
|
3673
|
+
};
|
|
3583
3674
|
}, {}),
|
|
3584
3675
|
}
|
|
3585
3676
|
: {};
|
|
3586
3677
|
}
|
|
3587
3678
|
static processMaximumAggregates(params) {
|
|
3588
|
-
var _a;
|
|
3589
3679
|
const { result, tableName, findOptions, fields } = params;
|
|
3590
|
-
return
|
|
3680
|
+
return findOptions?.maximum?.length
|
|
3591
3681
|
? {
|
|
3592
3682
|
maximum: findOptions.maximum.reduce((maximums, current) => {
|
|
3593
|
-
|
|
3594
|
-
return
|
|
3683
|
+
const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
|
|
3684
|
+
return {
|
|
3685
|
+
...maximums,
|
|
3686
|
+
...lodash.set(maximums, current, result[`${tableName}_aggregate`].aggregate.max[columnName]),
|
|
3687
|
+
};
|
|
3595
3688
|
}, {}),
|
|
3596
3689
|
}
|
|
3597
3690
|
: {};
|
|
3598
3691
|
}
|
|
3599
3692
|
static processDistinctResults(params) {
|
|
3600
|
-
var _a, _b;
|
|
3601
3693
|
const { result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct } = params;
|
|
3602
|
-
return
|
|
3694
|
+
return findOptions?.distinct?.length
|
|
3603
3695
|
? {
|
|
3604
|
-
distinct:
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3696
|
+
distinct: lastDistinct[tableFiltersNamed] ??
|
|
3697
|
+
(lastDistinct[tableFiltersNamed] = findOptions?.distinct.reduce((distinct, current) => {
|
|
3698
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === current) ??
|
|
3699
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
|
|
3700
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || current;
|
|
3701
|
+
return {
|
|
3702
|
+
...distinct,
|
|
3703
|
+
[current.toString()]: result[`${tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]),
|
|
3704
|
+
};
|
|
3705
|
+
}, {})),
|
|
3610
3706
|
}
|
|
3611
3707
|
: {};
|
|
3612
3708
|
}
|
|
3613
3709
|
static bindAttributesToColumns(attributes, fields) {
|
|
3614
|
-
return attributes.map((attr) =>
|
|
3615
|
-
var _a;
|
|
3616
|
-
return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
|
|
3617
|
-
});
|
|
3710
|
+
return attributes.map((attr) => AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)?.columnName || attr);
|
|
3618
3711
|
}
|
|
3619
3712
|
}
|
|
3620
3713
|
|
|
@@ -3644,16 +3737,19 @@ class HasuraFindVariablesHelper {
|
|
|
3644
3737
|
};
|
|
3645
3738
|
}
|
|
3646
3739
|
static buildDistinctVariables(params) {
|
|
3647
|
-
var _a, _b;
|
|
3648
3740
|
const { distinct, tableName, fields, filtersVariables } = params;
|
|
3649
|
-
const distinctOption =
|
|
3650
|
-
|
|
3651
|
-
|
|
3741
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
|
|
3742
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
3743
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || distinct;
|
|
3744
|
+
return {
|
|
3745
|
+
...filtersVariables,
|
|
3746
|
+
[`${tableName}_${fieldName}_distinct`]: {
|
|
3652
3747
|
type: `${tableName}_select_column!`,
|
|
3653
3748
|
list: true,
|
|
3654
3749
|
value: fieldName,
|
|
3655
3750
|
name: 'distinct_on',
|
|
3656
|
-
}
|
|
3751
|
+
},
|
|
3752
|
+
};
|
|
3657
3753
|
}
|
|
3658
3754
|
static bindOrderByAttributes(orderBy, fields) {
|
|
3659
3755
|
return Object.keys(orderBy).reduce((acc, current) => [
|
|
@@ -3673,11 +3769,17 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3673
3769
|
const { tableName, fields, params, lastDistinct } = queryParams;
|
|
3674
3770
|
const { filters, limits, orderBy, options: findOptions } = params || {};
|
|
3675
3771
|
const filtersVariables = HasuraFindVariablesHelper.buildFiltersVariables({ filters, tableName, fields });
|
|
3676
|
-
const countVariables =
|
|
3677
|
-
|
|
3772
|
+
const countVariables = {
|
|
3773
|
+
...HasuraFindVariablesHelper.buildOrderByVariables({ orderBy, tableName, fields }),
|
|
3774
|
+
...filtersVariables,
|
|
3775
|
+
};
|
|
3776
|
+
const mainVariables = {
|
|
3777
|
+
...(lodash.isNil(limits) ? {} : limits),
|
|
3778
|
+
...countVariables,
|
|
3779
|
+
};
|
|
3678
3780
|
const queries = [
|
|
3679
3781
|
this.buildMainQuery({ tableName, fields, params, mainVariables }),
|
|
3680
|
-
...this.buildAggregateQuery({ tableName, findOptions, countVariables }),
|
|
3782
|
+
...this.buildAggregateQuery({ tableName, findOptions, countVariables, fields }),
|
|
3681
3783
|
...this.buildDistinctQueries({ tableName, fields, findOptions, filtersVariables, lastDistinct }),
|
|
3682
3784
|
];
|
|
3683
3785
|
return queries.filter(Boolean);
|
|
@@ -3686,26 +3788,23 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3686
3788
|
const { tableName, fields, params: findParams, mainVariables } = params;
|
|
3687
3789
|
return {
|
|
3688
3790
|
operation: tableName,
|
|
3689
|
-
fields:
|
|
3791
|
+
fields: findParams?.fields
|
|
3690
3792
|
? findParams.fields
|
|
3691
|
-
.map((fieldName) =>
|
|
3692
|
-
|
|
3693
|
-
return (_a = fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
|
|
3694
|
-
})
|
|
3793
|
+
.map((fieldName) => fields.find((fieldOption) => fieldOption === fieldName) ??
|
|
3794
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
|
|
3695
3795
|
.filter(Boolean)
|
|
3696
3796
|
: fields,
|
|
3697
3797
|
variables: mainVariables,
|
|
3698
3798
|
};
|
|
3699
3799
|
}
|
|
3700
3800
|
static buildAggregateQuery(params) {
|
|
3701
|
-
var _a;
|
|
3702
3801
|
const { tableName, findOptions, countVariables } = params;
|
|
3703
|
-
const enableCount =
|
|
3802
|
+
const enableCount = findOptions?.enableCount ?? true;
|
|
3704
3803
|
const aggregateFields = [
|
|
3705
3804
|
...(enableCount ? ['count'] : []),
|
|
3706
3805
|
...HasuraFindResultHelper.bindAggregateAttributes({
|
|
3707
|
-
aggregates: { minimal: findOptions
|
|
3708
|
-
fields:
|
|
3806
|
+
aggregates: { minimal: findOptions?.minimal, maximum: findOptions?.maximum },
|
|
3807
|
+
fields: params.fields,
|
|
3709
3808
|
}),
|
|
3710
3809
|
];
|
|
3711
3810
|
return aggregateFields.length > 0
|
|
@@ -3723,15 +3822,14 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3723
3822
|
: [];
|
|
3724
3823
|
}
|
|
3725
3824
|
static buildDistinctQueries(params) {
|
|
3726
|
-
var _a;
|
|
3727
3825
|
const { tableName, fields, findOptions, filtersVariables, lastDistinct } = params;
|
|
3728
3826
|
const tableFiltersNamed = `${tableName}:${JSON.stringify(filtersVariables)}`;
|
|
3729
|
-
if (!
|
|
3827
|
+
if (!findOptions?.distinct?.length || lastDistinct[tableFiltersNamed]) {
|
|
3730
3828
|
return [];
|
|
3731
3829
|
}
|
|
3732
3830
|
return findOptions.distinct.map((distinct) => {
|
|
3733
|
-
|
|
3734
|
-
|
|
3831
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
|
|
3832
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
3735
3833
|
return {
|
|
3736
3834
|
operation: {
|
|
3737
3835
|
name: tableName,
|
|
@@ -3751,18 +3849,16 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3751
3849
|
|
|
3752
3850
|
class HasuraFindOperationsHelper {
|
|
3753
3851
|
static async executeFindOperation(operationParams) {
|
|
3754
|
-
var _a;
|
|
3755
3852
|
const { params, cacheOptions, model, tableName, fields, cache, query, convertDataFromHasura, lastDistinct } = operationParams;
|
|
3756
3853
|
const logger = DebugHelper.from(operationParams, 'find');
|
|
3757
3854
|
const { filters, options: findOptions } = params || {};
|
|
3758
3855
|
const tableFiltersNamed = `${tableName}:${JSON.stringify(filters)}`;
|
|
3759
|
-
const enableCount =
|
|
3760
|
-
// Verifica cache primeiro
|
|
3856
|
+
const enableCount = findOptions?.enableCount ?? true;
|
|
3761
3857
|
const cachedResult = await HasuraFindCacheHelper.getCachedResult({
|
|
3762
3858
|
cache,
|
|
3763
3859
|
model,
|
|
3764
3860
|
findParams: params,
|
|
3765
|
-
cacheOptions: cacheOptions
|
|
3861
|
+
cacheOptions: cacheOptions?.cache,
|
|
3766
3862
|
logger,
|
|
3767
3863
|
});
|
|
3768
3864
|
if (cachedResult) {
|
|
@@ -3777,7 +3873,6 @@ class HasuraFindOperationsHelper {
|
|
|
3777
3873
|
lastDistinct,
|
|
3778
3874
|
});
|
|
3779
3875
|
}
|
|
3780
|
-
// Constrói e executa queries
|
|
3781
3876
|
const queries = HasuraFindQueryBuilderHelper.buildCompleteQuery({
|
|
3782
3877
|
tableName,
|
|
3783
3878
|
fields,
|
|
@@ -3785,16 +3880,14 @@ class HasuraFindOperationsHelper {
|
|
|
3785
3880
|
lastDistinct,
|
|
3786
3881
|
});
|
|
3787
3882
|
const result = await query(queries);
|
|
3788
|
-
// Salva no cache se habilitado
|
|
3789
3883
|
await HasuraFindCacheHelper.setCachedResult({
|
|
3790
3884
|
cache,
|
|
3791
3885
|
model,
|
|
3792
3886
|
findParams: params,
|
|
3793
|
-
cacheOptions: cacheOptions
|
|
3887
|
+
cacheOptions: cacheOptions?.cache,
|
|
3794
3888
|
result,
|
|
3795
3889
|
logger,
|
|
3796
3890
|
});
|
|
3797
|
-
// Processa e retorna resultado
|
|
3798
3891
|
return HasuraFindResultHelper.processResult({
|
|
3799
3892
|
result,
|
|
3800
3893
|
tableName,
|
|
@@ -3813,9 +3906,8 @@ class HasuraGetCacheHelper {
|
|
|
3813
3906
|
return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3814
3907
|
}
|
|
3815
3908
|
static async getCachedData(cache, params) {
|
|
3816
|
-
var _a;
|
|
3817
3909
|
const { identifiers, options, model, logger } = params;
|
|
3818
|
-
if (!
|
|
3910
|
+
if (!cache?.cacheAdapter || !options?.cache?.enabled)
|
|
3819
3911
|
return null;
|
|
3820
3912
|
const cacheKey = this.generateCacheKey(model, identifiers);
|
|
3821
3913
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -3825,15 +3917,14 @@ class HasuraGetCacheHelper {
|
|
|
3825
3917
|
return model.toInstance(deserialize(cachedData));
|
|
3826
3918
|
}
|
|
3827
3919
|
static async saveCacheData(cache, params) {
|
|
3828
|
-
var _a, _b;
|
|
3829
3920
|
const { identifiers, options, data, logger } = params;
|
|
3830
|
-
if (!
|
|
3921
|
+
if (!cache?.cacheAdapter || !options?.cache?.enabled)
|
|
3831
3922
|
return;
|
|
3832
3923
|
const cacheKey = this.generateCacheKey(params.data.constructor, identifiers);
|
|
3833
3924
|
await cache.cacheAdapter.set({
|
|
3834
3925
|
key: cacheKey,
|
|
3835
3926
|
data: serialize(data),
|
|
3836
|
-
expirationInSeconds:
|
|
3927
|
+
expirationInSeconds: options?.cache?.ttl || cache.ttlDefault,
|
|
3837
3928
|
});
|
|
3838
3929
|
logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
3839
3930
|
}
|
|
@@ -3844,18 +3935,20 @@ class HasuraGetVariablesHelper {
|
|
|
3844
3935
|
const { model, fields, repository } = params;
|
|
3845
3936
|
const instance = model.toInstance(identifiers);
|
|
3846
3937
|
return model.identifiersFields.reduce((ids, identifier) => {
|
|
3847
|
-
var _a;
|
|
3848
3938
|
const identifierBinded = identifier;
|
|
3849
3939
|
if (lodash.isNil(instance[identifierBinded]))
|
|
3850
3940
|
return ids;
|
|
3851
3941
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
|
|
3852
|
-
const value =
|
|
3942
|
+
const value = columnOption?.to?.(identifiers[identifier], instance) ||
|
|
3853
3943
|
identifiers[identifier];
|
|
3854
|
-
return
|
|
3944
|
+
return {
|
|
3945
|
+
...ids,
|
|
3946
|
+
[columnOption.columnName]: {
|
|
3855
3947
|
type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3856
3948
|
value,
|
|
3857
3949
|
required: true,
|
|
3858
|
-
}
|
|
3950
|
+
},
|
|
3951
|
+
};
|
|
3859
3952
|
}, {});
|
|
3860
3953
|
}
|
|
3861
3954
|
}
|
|
@@ -3912,7 +4005,7 @@ class HasuraUpdateDataHelper {
|
|
|
3912
4005
|
static getValueByAction(options) {
|
|
3913
4006
|
if (options instanceof BaseModel)
|
|
3914
4007
|
return options.toPlain();
|
|
3915
|
-
if (lodash.isNil(options
|
|
4008
|
+
if (lodash.isNil(options?.action))
|
|
3916
4009
|
return options;
|
|
3917
4010
|
if ([exports.UpdateOptionActions.REMOVE_FIELD.toString(), exports.UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
3918
4011
|
return null;
|
|
@@ -3921,9 +4014,12 @@ class HasuraUpdateDataHelper {
|
|
|
3921
4014
|
static paramsToPlain(params, model) {
|
|
3922
4015
|
if (model.isModel(params))
|
|
3923
4016
|
return params.toPlain();
|
|
3924
|
-
return Object.keys(params).reduce((data, currentKey) => (
|
|
3925
|
-
|
|
3926
|
-
|
|
4017
|
+
return Object.keys(params).reduce((data, currentKey) => ({
|
|
4018
|
+
...data,
|
|
4019
|
+
...(params[currentKey] !== undefined && {
|
|
4020
|
+
[currentKey]: this.getValueByAction(is(params[currentKey])),
|
|
4021
|
+
}),
|
|
4022
|
+
}), {});
|
|
3927
4023
|
}
|
|
3928
4024
|
static getIdentifiersFromData(data, model) {
|
|
3929
4025
|
const instance = model.toInstance(data);
|
|
@@ -3942,13 +4038,15 @@ class HasuraUpdateVariablesHelper {
|
|
|
3942
4038
|
static getUpdateModelKeys(data, model, fields) {
|
|
3943
4039
|
const instance = model.toInstance(data);
|
|
3944
4040
|
return model.identifiersFields.reduce((ids, identifier) => {
|
|
3945
|
-
var _a;
|
|
3946
4041
|
const identifierBinded = identifier;
|
|
3947
4042
|
if (lodash.isNil(instance.identifier[identifierBinded]))
|
|
3948
4043
|
return ids;
|
|
3949
4044
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifierBinded, fields);
|
|
3950
|
-
const value =
|
|
3951
|
-
return
|
|
4045
|
+
const value = columnOption?.to?.(data[identifierBinded], instance) || data[columnOption.attributeName];
|
|
4046
|
+
return {
|
|
4047
|
+
...ids,
|
|
4048
|
+
[columnOption.columnName]: value,
|
|
4049
|
+
};
|
|
3952
4050
|
}, {});
|
|
3953
4051
|
}
|
|
3954
4052
|
static getIdentifierFields(model, fields) {
|
|
@@ -3976,9 +4074,7 @@ class HasuraUpdateOperationsHelper {
|
|
|
3976
4074
|
const { data, updateGraphQLOperation, updateGraphQLObjectType, updateGraphQLPKType, model, fields, cache, mutation, convertDataToHasura, } = params;
|
|
3977
4075
|
const logger = DebugHelper.from(params, 'update');
|
|
3978
4076
|
const plainData = HasuraUpdateDataHelper.paramsToPlain(data, model);
|
|
3979
|
-
// Gerencia cache se disponível
|
|
3980
4077
|
await this.handleCacheRemoval({ plainData, model, cache, logger });
|
|
3981
|
-
// Executa mutation
|
|
3982
4078
|
const identifierFields = HasuraUpdateVariablesHelper.getIdentifierFields(model, fields);
|
|
3983
4079
|
const mutationVariables = HasuraUpdateVariablesHelper.buildMutationVariables({
|
|
3984
4080
|
plainData,
|
|
@@ -3993,13 +4089,13 @@ class HasuraUpdateOperationsHelper {
|
|
|
3993
4089
|
}
|
|
3994
4090
|
static async handleCacheRemoval(params) {
|
|
3995
4091
|
const { plainData, model, cache, logger } = params;
|
|
3996
|
-
if (!
|
|
4092
|
+
if (!cache?.cacheAdapter)
|
|
3997
4093
|
return;
|
|
3998
4094
|
const identifiers = HasuraUpdateDataHelper.getIdentifiersFromData(plainData, model);
|
|
3999
4095
|
if (Object.keys(identifiers).length > 0) {
|
|
4000
4096
|
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
4001
4097
|
await cache.cacheAdapter.remove(cacheKey);
|
|
4002
|
-
logger
|
|
4098
|
+
logger?.log(`Cache removido: ${cacheKey}`);
|
|
4003
4099
|
}
|
|
4004
4100
|
}
|
|
4005
4101
|
}
|
|
@@ -4021,9 +4117,8 @@ class FirestoreCacheKeyGeneratorHelper {
|
|
|
4021
4117
|
|
|
4022
4118
|
class FirestoreCacheHelper {
|
|
4023
4119
|
static async getCachedData(cache, params) {
|
|
4024
|
-
var _a;
|
|
4025
4120
|
const { model, identifiers, options, logger, req } = params;
|
|
4026
|
-
if (!
|
|
4121
|
+
if (!cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4027
4122
|
return null;
|
|
4028
4123
|
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(model, identifiers);
|
|
4029
4124
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -4034,9 +4129,8 @@ class FirestoreCacheHelper {
|
|
|
4034
4129
|
return null;
|
|
4035
4130
|
}
|
|
4036
4131
|
static async getCachedFindData(cache, params) {
|
|
4037
|
-
var _a;
|
|
4038
4132
|
const { model, find, options, logger } = params;
|
|
4039
|
-
if (!
|
|
4133
|
+
if (!cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4040
4134
|
return null;
|
|
4041
4135
|
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(model, find);
|
|
4042
4136
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -4048,7 +4142,7 @@ class FirestoreCacheHelper {
|
|
|
4048
4142
|
}
|
|
4049
4143
|
static async saveCacheData(cache, params) {
|
|
4050
4144
|
const { cacheKey, data, expirationInSeconds, logger, req } = params;
|
|
4051
|
-
if (!
|
|
4145
|
+
if (!cache?.cacheAdapter)
|
|
4052
4146
|
return;
|
|
4053
4147
|
await cache.cacheAdapter.set({
|
|
4054
4148
|
key: cacheKey,
|
|
@@ -4060,7 +4154,7 @@ class FirestoreCacheHelper {
|
|
|
4060
4154
|
}
|
|
4061
4155
|
static async removeCacheData(cache, params) {
|
|
4062
4156
|
const { cacheKey, logger } = params;
|
|
4063
|
-
if (!
|
|
4157
|
+
if (!cache?.cacheAdapter)
|
|
4064
4158
|
return;
|
|
4065
4159
|
await cache.cacheAdapter.remove(cacheKey);
|
|
4066
4160
|
logger.log(`Cache removido: ${cacheKey}`);
|
|
@@ -4078,7 +4172,7 @@ class FirestoreOperationsHelper {
|
|
|
4078
4172
|
this.model = model;
|
|
4079
4173
|
}
|
|
4080
4174
|
buildInstanceFromIdentifiers(identifiers) {
|
|
4081
|
-
return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (
|
|
4175
|
+
return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
|
|
4082
4176
|
}
|
|
4083
4177
|
async validateDocumentExists(docRef, collectionName, identifiers) {
|
|
4084
4178
|
const docSnapshot = await docRef.get();
|
|
@@ -4100,7 +4194,7 @@ class FirestoreOperationsHelper {
|
|
|
4100
4194
|
calculateCount(data, limits) {
|
|
4101
4195
|
if (data.length <= 0)
|
|
4102
4196
|
return 0;
|
|
4103
|
-
if (data.length
|
|
4197
|
+
if (data.length)
|
|
4104
4198
|
return data.length;
|
|
4105
4199
|
return Infinity;
|
|
4106
4200
|
}
|
|
@@ -4113,8 +4207,8 @@ class FirestoreOperationsHelper {
|
|
|
4113
4207
|
const { isSubCollection, collectionName, parentRepository, parentIdField, identifiers } = params;
|
|
4114
4208
|
if (!isSubCollection)
|
|
4115
4209
|
return collectionName;
|
|
4116
|
-
const parentId = identifiers
|
|
4117
|
-
return `${parentRepository
|
|
4210
|
+
const parentId = identifiers?.[parentIdField];
|
|
4211
|
+
return `${parentRepository?.collectionName}/${parentId}/${collectionName}`;
|
|
4118
4212
|
}
|
|
4119
4213
|
getKeyField() {
|
|
4120
4214
|
const model = new this.model();
|
|
@@ -4165,27 +4259,25 @@ const createGetFirestoreClass = (MixinBase) => {
|
|
|
4165
4259
|
}
|
|
4166
4260
|
}
|
|
4167
4261
|
async executeGet(params) {
|
|
4168
|
-
var _a, _b, _c, _d;
|
|
4169
4262
|
const { instance, collectionName, identifiers, logger, req } = params;
|
|
4170
|
-
const intercepted = await
|
|
4171
|
-
const builded =
|
|
4263
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4264
|
+
const builded = intercepted?.instance || instance;
|
|
4172
4265
|
const docRef = await this.operationsHelper.getDocumentSnapshot(this.collection(collectionName), builded);
|
|
4173
4266
|
const data = docRef.data();
|
|
4174
4267
|
this.operationsHelper.validateDocumentData(data, collectionName, identifiers);
|
|
4175
|
-
const result = (await
|
|
4268
|
+
const result = (await this.interceptors?.response?.(data, intercepted)) || data;
|
|
4176
4269
|
logger.log({ req, res: result });
|
|
4177
4270
|
return result;
|
|
4178
4271
|
}
|
|
4179
4272
|
async saveCacheData(params) {
|
|
4180
|
-
var _a, _b, _c;
|
|
4181
4273
|
const { identifiers, options, result, logger, req } = params;
|
|
4182
|
-
if (!
|
|
4274
|
+
if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4183
4275
|
return;
|
|
4184
4276
|
const cacheKey = FirestoreCacheHelper.generateGetCacheKey(this.model, identifiers);
|
|
4185
4277
|
await FirestoreCacheHelper.saveCacheData(this.cache, {
|
|
4186
4278
|
cacheKey,
|
|
4187
4279
|
data: result,
|
|
4188
|
-
expirationInSeconds:
|
|
4280
|
+
expirationInSeconds: options?.cache?.ttl,
|
|
4189
4281
|
logger,
|
|
4190
4282
|
req,
|
|
4191
4283
|
});
|
|
@@ -4216,14 +4308,13 @@ class FirestoreQueryBuilderHelper {
|
|
|
4216
4308
|
this.config = config;
|
|
4217
4309
|
}
|
|
4218
4310
|
buildWhereSentence(fieldName, options) {
|
|
4219
|
-
|
|
4220
|
-
if (((_b = (_a = this.config).isSubCollection) === null || _b === void 0 ? void 0 : _b.call(_a, this)) && fieldName === this.config.parentIdField)
|
|
4311
|
+
if (this.config.isSubCollection?.(this) && fieldName === this.config.parentIdField)
|
|
4221
4312
|
return [];
|
|
4222
4313
|
const firestoreFieldName = this.getFirestoreFieldName(fieldName, options);
|
|
4223
4314
|
return this.buildWhereConditions(firestoreFieldName, options, fieldName);
|
|
4224
4315
|
}
|
|
4225
4316
|
getFirestoreFieldName(fieldName, options) {
|
|
4226
|
-
const value =
|
|
4317
|
+
const value = options?.value || options;
|
|
4227
4318
|
const object = {};
|
|
4228
4319
|
lodash.set(object, fieldName.toString(), value);
|
|
4229
4320
|
const plainInstance = new this.config.model(object).toPlain();
|
|
@@ -4232,19 +4323,19 @@ class FirestoreQueryBuilderHelper {
|
|
|
4232
4323
|
: Object.keys(plainInstance).find((key) => plainInstance[key]);
|
|
4233
4324
|
}
|
|
4234
4325
|
buildWhereConditions(firestoreFieldName, options, fieldName) {
|
|
4235
|
-
if (
|
|
4326
|
+
if (options?.operator === exports.Where.LIKE) {
|
|
4236
4327
|
return this.buildLikeConditions(firestoreFieldName, options);
|
|
4237
4328
|
}
|
|
4238
|
-
if (
|
|
4329
|
+
if (options?.operator === exports.Where.IN && Array.isArray(options?.value)) {
|
|
4239
4330
|
return this.buildInConditions(firestoreFieldName, options);
|
|
4240
4331
|
}
|
|
4241
4332
|
if (this.isNestedObjectFilter(options)) {
|
|
4242
4333
|
return this.buildNestedObjectConditions(fieldName, options);
|
|
4243
4334
|
}
|
|
4244
|
-
return [[firestoreFieldName, (
|
|
4335
|
+
return [[firestoreFieldName, (options?.operator || '=='), options?.value || options]];
|
|
4245
4336
|
}
|
|
4246
4337
|
buildLikeConditions(firestoreFieldName, options) {
|
|
4247
|
-
if (this.isArrayField(firestoreFieldName) && Array.isArray(options
|
|
4338
|
+
if (this.isArrayField(firestoreFieldName) && Array.isArray(options?.value)) {
|
|
4248
4339
|
return [[firestoreFieldName, 'array-contains-any', options.value]];
|
|
4249
4340
|
}
|
|
4250
4341
|
return [
|
|
@@ -4261,17 +4352,16 @@ class FirestoreQueryBuilderHelper {
|
|
|
4261
4352
|
buildNestedObjectConditions(fieldName, options) {
|
|
4262
4353
|
return Object.keys(options).reduce((queries, key) => [
|
|
4263
4354
|
...queries,
|
|
4264
|
-
...this.buildWhereSentence(`${fieldName.toString()}.${key}`, is(options)[key]),
|
|
4355
|
+
...this.buildWhereSentence(Array.isArray(options) ? fieldName : `${fieldName.toString()}.${key}`, is(options)[key]),
|
|
4265
4356
|
], []);
|
|
4266
4357
|
}
|
|
4267
4358
|
isArrayField(firestoreFieldName) {
|
|
4268
|
-
|
|
4269
|
-
return (((_a = this.config.fields) === null || _a === void 0 ? void 0 : _a[firestoreFieldName]) ===
|
|
4359
|
+
return (this.config.fields?.[firestoreFieldName] ===
|
|
4270
4360
|
FirestoreFieldType.Array ||
|
|
4271
|
-
!
|
|
4361
|
+
!this.config.fields?.[firestoreFieldName]);
|
|
4272
4362
|
}
|
|
4273
4363
|
isNestedObjectFilter(options) {
|
|
4274
|
-
return lodash.isObject(options) && lodash.isNil(options
|
|
4364
|
+
return lodash.isObject(options) && lodash.isNil(options?.operator) && lodash.isNil(options?.value);
|
|
4275
4365
|
}
|
|
4276
4366
|
buildOrderBy(filters, fieldsToOrderBy) {
|
|
4277
4367
|
const orderByKeys = Object.keys(fieldsToOrderBy || {});
|
|
@@ -4287,8 +4377,8 @@ class FirestoreQueryBuilderHelper {
|
|
|
4287
4377
|
filtersKeysWithUnordered.forEach((filterKey) => {
|
|
4288
4378
|
const filterValue = filters[filterKey];
|
|
4289
4379
|
const filterOptions = is(filterValue);
|
|
4290
|
-
if (
|
|
4291
|
-
updatedOrderBy =
|
|
4380
|
+
if (filterOptions?.operator && ![exports.Where.EQUALS].includes(filterOptions.operator)) {
|
|
4381
|
+
updatedOrderBy = { [filterKey]: 'asc', ...updatedOrderBy };
|
|
4292
4382
|
}
|
|
4293
4383
|
});
|
|
4294
4384
|
return updatedOrderBy;
|
|
@@ -4302,21 +4392,21 @@ class FirestoreQueryBuilderHelper {
|
|
|
4302
4392
|
async buildLimits(params) {
|
|
4303
4393
|
const { filters, limits, collection, buildCollectionPath } = params;
|
|
4304
4394
|
const queries = [];
|
|
4305
|
-
if (limits
|
|
4395
|
+
if (limits?.offset) {
|
|
4306
4396
|
await this.addOffsetQuery({ queries, limits, filters, collection, buildCollectionPath });
|
|
4307
4397
|
}
|
|
4308
|
-
if (limits
|
|
4398
|
+
if (limits?.limit) {
|
|
4309
4399
|
queries.push(['limit', limits.limit]);
|
|
4310
4400
|
}
|
|
4311
4401
|
return queries;
|
|
4312
4402
|
}
|
|
4313
4403
|
async addOffsetQuery(params) {
|
|
4314
|
-
var _a;
|
|
4315
4404
|
const { queries, limits, filters, collection, buildCollectionPath } = params;
|
|
4316
4405
|
if (this.config.model.isModel(limits.offset)) {
|
|
4317
4406
|
const docSnapshot = await collection(buildCollectionPath(filters))
|
|
4318
|
-
.getDoc(
|
|
4319
|
-
.shift()
|
|
4407
|
+
.getDoc(Object.values(limits.offset.identifier)
|
|
4408
|
+
.shift()
|
|
4409
|
+
?.toString())
|
|
4320
4410
|
.get();
|
|
4321
4411
|
queries.push(['fromStartAfter', docSnapshot]);
|
|
4322
4412
|
}
|
|
@@ -4331,7 +4421,7 @@ class FirestoreQueryBuilderHelper {
|
|
|
4331
4421
|
}
|
|
4332
4422
|
|
|
4333
4423
|
const createFilterHelpers = () => {
|
|
4334
|
-
const checkIfIsFilterOption = (filter) => !lodash.isNil(filter
|
|
4424
|
+
const checkIfIsFilterOption = (filter) => !lodash.isNil(filter?.operator);
|
|
4335
4425
|
const getValueFromFilter = (filter) => {
|
|
4336
4426
|
return checkIfIsFilterOption(filter) ? filter.value : filter;
|
|
4337
4427
|
};
|
|
@@ -4389,20 +4479,19 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4389
4479
|
}
|
|
4390
4480
|
}
|
|
4391
4481
|
async executeFind(params) {
|
|
4392
|
-
var _a, _b, _c, _d, _e, _f;
|
|
4393
4482
|
const { find, collectionName, logger, req } = params;
|
|
4394
4483
|
const collection = this.collection(collectionName);
|
|
4395
|
-
const enableCount =
|
|
4396
|
-
const intercepted = await
|
|
4397
|
-
const { filters, limits, orderBy } =
|
|
4484
|
+
const enableCount = find?.options?.enableCount ?? true;
|
|
4485
|
+
const intercepted = await this.interceptors?.request?.({ find });
|
|
4486
|
+
const { filters, limits, orderBy } = intercepted?.find || find;
|
|
4398
4487
|
const queryData = await this.buildQueryData(filters, orderBy, limits);
|
|
4399
4488
|
const docs = await this.executeQuery(collection, queryData);
|
|
4400
4489
|
const data = docs.docs.map((doc) => doc.data());
|
|
4401
4490
|
const result = {
|
|
4402
|
-
data: (await
|
|
4491
|
+
data: (await this.interceptors?.response?.(data, intercepted)) || data,
|
|
4403
4492
|
count: enableCount ? this.operationsHelper.calculateCount(data, limits) : Infinity,
|
|
4404
4493
|
};
|
|
4405
|
-
logger.log(
|
|
4494
|
+
logger.log({ req, ...queryData, res: result });
|
|
4406
4495
|
return result;
|
|
4407
4496
|
}
|
|
4408
4497
|
async buildQueryData(filters, orderBy, limits) {
|
|
@@ -4418,19 +4507,21 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4418
4507
|
}
|
|
4419
4508
|
async executeQuery(collection, queryData) {
|
|
4420
4509
|
return this.queryBuilder
|
|
4421
|
-
.buildQuery(
|
|
4510
|
+
.buildQuery({
|
|
4511
|
+
collection,
|
|
4512
|
+
...queryData,
|
|
4513
|
+
})
|
|
4422
4514
|
.getDocs();
|
|
4423
4515
|
}
|
|
4424
4516
|
async saveCacheData(params) {
|
|
4425
|
-
var _a, _b, _c;
|
|
4426
4517
|
const { find, options, result, logger } = params;
|
|
4427
|
-
if (!
|
|
4518
|
+
if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4428
4519
|
return;
|
|
4429
4520
|
const cacheKey = this.generateCacheKey(find);
|
|
4430
4521
|
await FirestoreCacheHelper.saveCacheData(this.cache, {
|
|
4431
4522
|
cacheKey,
|
|
4432
4523
|
data: result,
|
|
4433
|
-
expirationInSeconds:
|
|
4524
|
+
expirationInSeconds: options?.cache?.ttl,
|
|
4434
4525
|
logger,
|
|
4435
4526
|
});
|
|
4436
4527
|
}
|
|
@@ -4438,7 +4529,7 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4438
4529
|
if (!this.isSubCollection(this))
|
|
4439
4530
|
return this.collectionName;
|
|
4440
4531
|
const parentIdField = this.parentIdField;
|
|
4441
|
-
const parentId = getValueFromFilter(filters
|
|
4532
|
+
const parentId = getValueFromFilter(filters?.[parentIdField]);
|
|
4442
4533
|
return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
|
|
4443
4534
|
}
|
|
4444
4535
|
};
|
|
@@ -4447,16 +4538,15 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4447
4538
|
const withCreateFirestore = (MixinBase) => {
|
|
4448
4539
|
return class CreateFirestore extends MixinBase {
|
|
4449
4540
|
async create(data) {
|
|
4450
|
-
var _a, _b, _c, _d;
|
|
4451
4541
|
const logger = this.logger.with('create');
|
|
4452
4542
|
const instance = this.model.toInstance(data);
|
|
4453
|
-
const intercepted = await
|
|
4454
|
-
const builded =
|
|
4543
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4544
|
+
const builded = intercepted?.instance || instance;
|
|
4455
4545
|
const req = { collection: this.buildCollectionPathForAdd(builded), data };
|
|
4456
4546
|
try {
|
|
4457
4547
|
const docRef = await this.save(builded);
|
|
4458
4548
|
const doc = (await docRef.get()).data();
|
|
4459
|
-
const docBuilded = (await
|
|
4549
|
+
const docBuilded = (await this.interceptors?.response?.(doc, intercepted)) || doc;
|
|
4460
4550
|
logger.log({ req, res: docBuilded });
|
|
4461
4551
|
return docBuilded;
|
|
4462
4552
|
}
|
|
@@ -4467,10 +4557,9 @@ const withCreateFirestore = (MixinBase) => {
|
|
|
4467
4557
|
}
|
|
4468
4558
|
}
|
|
4469
4559
|
async save(data) {
|
|
4470
|
-
var _a, _b;
|
|
4471
4560
|
const collectionPath = this.buildCollectionPathForAdd(data);
|
|
4472
4561
|
const collection = this.collection(collectionPath);
|
|
4473
|
-
return collection.add(data,
|
|
4562
|
+
return collection.add(data, Object.values(data.identifier).shift()?.toString?.());
|
|
4474
4563
|
}
|
|
4475
4564
|
buildCollectionPathForAdd(identifiers) {
|
|
4476
4565
|
return this.isSubCollection(this)
|
|
@@ -4481,26 +4570,23 @@ const withCreateFirestore = (MixinBase) => {
|
|
|
4481
4570
|
};
|
|
4482
4571
|
|
|
4483
4572
|
const createUpdateHelpers = () => {
|
|
4484
|
-
const getValueFromParams = (params, field) =>
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
? is(params[field])
|
|
4488
|
-
: is(params[field]).value) || null;
|
|
4489
|
-
};
|
|
4573
|
+
const getValueFromParams = (params, field) => (lodash.isNil(is(params[field])?.value)
|
|
4574
|
+
? is(params[field])
|
|
4575
|
+
: is(params[field]).value) || null;
|
|
4490
4576
|
const getValueByAction = (options) => {
|
|
4491
|
-
if (lodash.isNil(options
|
|
4577
|
+
if (lodash.isNil(options?.action))
|
|
4492
4578
|
return options;
|
|
4493
|
-
if (
|
|
4579
|
+
if (options?.action === exports.UpdateOptionActions.REMOVE_FIELD)
|
|
4494
4580
|
return firestore.deleteField();
|
|
4495
|
-
if (
|
|
4581
|
+
if (options?.action === exports.UpdateOptionActions.NULL)
|
|
4496
4582
|
return null;
|
|
4497
|
-
if (Array.isArray(options
|
|
4498
|
-
if (
|
|
4583
|
+
if (Array.isArray(options?.value)) {
|
|
4584
|
+
if (options?.action === exports.UpdateOptionActions.MERGE)
|
|
4499
4585
|
return firestore.arrayUnion(...options.value);
|
|
4500
|
-
if (
|
|
4586
|
+
if (options?.action === exports.UpdateOptionActions.REMOVE)
|
|
4501
4587
|
return firestore.arrayRemove(...options.value);
|
|
4502
4588
|
}
|
|
4503
|
-
return options
|
|
4589
|
+
return options?.value;
|
|
4504
4590
|
};
|
|
4505
4591
|
return { getValueFromParams, getValueByAction };
|
|
4506
4592
|
};
|
|
@@ -4551,14 +4637,13 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
|
|
|
4551
4637
|
await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
|
|
4552
4638
|
}
|
|
4553
4639
|
async executeUpdate(params) {
|
|
4554
|
-
var _a, _b, _c, _d;
|
|
4555
4640
|
const { data, docRef, logger, req, identifiers } = params;
|
|
4556
4641
|
const plainFromData = this.model.toInstance(this.paramsToPlain(data));
|
|
4557
|
-
const intercepted = await
|
|
4558
|
-
const builded =
|
|
4642
|
+
const intercepted = await this.interceptors?.request?.({ instance: plainFromData });
|
|
4643
|
+
const builded = intercepted?.instance || plainFromData;
|
|
4559
4644
|
await docRef.save(builded.toPlain());
|
|
4560
4645
|
const docData = await docRef.get();
|
|
4561
|
-
const result =
|
|
4646
|
+
const result = this.interceptors?.response?.(docData.data(), intercepted) || docData.data();
|
|
4562
4647
|
logger.log({ req, res: result, identifiers });
|
|
4563
4648
|
return result;
|
|
4564
4649
|
}
|
|
@@ -4574,7 +4659,10 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
|
|
|
4574
4659
|
return this.convertParamsToPlainObject(params);
|
|
4575
4660
|
}
|
|
4576
4661
|
convertParamsToPlainObject(params) {
|
|
4577
|
-
return Object.keys(params).reduce((data, currentKey) => (
|
|
4662
|
+
return Object.keys(params).reduce((data, currentKey) => ({
|
|
4663
|
+
...data,
|
|
4664
|
+
...this.processParamValue(currentKey, params[currentKey]),
|
|
4665
|
+
}), {});
|
|
4578
4666
|
}
|
|
4579
4667
|
processParamValue(key, value) {
|
|
4580
4668
|
const processedValue = getValueByAction(value);
|
|
@@ -4615,12 +4703,11 @@ const createDeleteFirestoreClass = (MixinBase) => {
|
|
|
4615
4703
|
await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
|
|
4616
4704
|
}
|
|
4617
4705
|
async executeDeleteOperation(params) {
|
|
4618
|
-
var _a, _b, _c, _d;
|
|
4619
4706
|
const { instance, collectionName, logger, req } = params;
|
|
4620
|
-
const intercepted = await
|
|
4621
|
-
const builded =
|
|
4707
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4708
|
+
const builded = intercepted?.instance || instance;
|
|
4622
4709
|
await this.operationsHelper.executeDelete(this.collection(collectionName), builded);
|
|
4623
|
-
await
|
|
4710
|
+
await this.interceptors?.response?.(instance, intercepted);
|
|
4624
4711
|
logger.log({ req, res: undefined });
|
|
4625
4712
|
}
|
|
4626
4713
|
buildCollectionPathForRemove(identifiers) {
|
|
@@ -4700,15 +4787,15 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
4700
4787
|
const products = [];
|
|
4701
4788
|
const wheres = [];
|
|
4702
4789
|
for (const productIds of chunks) {
|
|
4703
|
-
if (
|
|
4790
|
+
if (options?.limit && products.length >= options?.limit)
|
|
4704
4791
|
break;
|
|
4705
4792
|
wheres.push(['published', '==', true], ['id', 'in', productIds]);
|
|
4706
|
-
if (options
|
|
4793
|
+
if (options?.hasStock)
|
|
4707
4794
|
wheres.push(['stock.quantity', '>', 0]);
|
|
4708
|
-
if (options
|
|
4709
|
-
wheres.push(['tags', 'array-contains', options
|
|
4795
|
+
if (options?.gender)
|
|
4796
|
+
wheres.push(['tags', 'array-contains', options?.gender]);
|
|
4710
4797
|
const productSnap = await wheres
|
|
4711
|
-
.reduce((collection, where) => collection.where(...where),
|
|
4798
|
+
.reduce((collection, where) => collection.where(...where), options?.limit
|
|
4712
4799
|
? this.collection('productsErpVitrine').limit(options.limit)
|
|
4713
4800
|
: this.collection('productsErpVitrine'))
|
|
4714
4801
|
.getDocs();
|
|
@@ -4773,19 +4860,17 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
4773
4860
|
throw new Error('Method not implemented.');
|
|
4774
4861
|
}
|
|
4775
4862
|
async getBySlug(slug) {
|
|
4776
|
-
var _a;
|
|
4777
4863
|
const result = await this.find({
|
|
4778
4864
|
filters: {
|
|
4779
4865
|
slug: { operator: exports.Where.EQUALS, value: slug },
|
|
4780
4866
|
},
|
|
4781
4867
|
});
|
|
4782
|
-
return
|
|
4868
|
+
return result?.data?.shift();
|
|
4783
4869
|
}
|
|
4784
4870
|
async fetchReviews(status) {
|
|
4785
4871
|
const { data: products } = await this.find();
|
|
4786
4872
|
products.forEach((product) => {
|
|
4787
|
-
|
|
4788
|
-
if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
|
|
4873
|
+
if ([undefined, 0].includes(product.reviews?.length))
|
|
4789
4874
|
return;
|
|
4790
4875
|
const productInfo = {
|
|
4791
4876
|
productId: product.id,
|
|
@@ -4797,11 +4882,11 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
4797
4882
|
this.reviews.rejected = [];
|
|
4798
4883
|
product.reviews.forEach((review) => {
|
|
4799
4884
|
if ([null, undefined].includes(review.status))
|
|
4800
|
-
return this.reviews.pending.push(
|
|
4885
|
+
return this.reviews.pending.push({ ...review, ...productInfo });
|
|
4801
4886
|
if (review.status === false)
|
|
4802
|
-
return this.reviews.rejected.push(
|
|
4887
|
+
return this.reviews.rejected.push({ ...review, ...productInfo });
|
|
4803
4888
|
if (review.status)
|
|
4804
|
-
return this.reviews.approved.push(
|
|
4889
|
+
return this.reviews.approved.push({ ...review, ...productInfo });
|
|
4805
4890
|
return review;
|
|
4806
4891
|
});
|
|
4807
4892
|
});
|
|
@@ -4888,22 +4973,18 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
4888
4973
|
interceptors,
|
|
4889
4974
|
cache,
|
|
4890
4975
|
});
|
|
4891
|
-
this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
|
|
4904
|
-
products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
|
|
4905
|
-
});
|
|
4906
|
-
};
|
|
4976
|
+
this.homeCategoryGroupToPlain = (homeCategoryGroup) => ({
|
|
4977
|
+
category: homeCategoryGroup?.category?.toPlain
|
|
4978
|
+
? homeCategoryGroup?.category?.toPlain()
|
|
4979
|
+
: homeCategoryGroup?.category,
|
|
4980
|
+
products: homeCategoryGroup?.products
|
|
4981
|
+
?.map((product) => (product?.toPlain ? product?.toPlain() : product))
|
|
4982
|
+
.filter(Boolean) || [],
|
|
4983
|
+
});
|
|
4984
|
+
this.plainToHomeCategoryGroup = (homeCategoryGroup) => ({
|
|
4985
|
+
category: Category.toInstance(homeCategoryGroup?.category),
|
|
4986
|
+
products: homeCategoryGroup.products?.map((product) => Product.toInstance(product)),
|
|
4987
|
+
});
|
|
4907
4988
|
}
|
|
4908
4989
|
buildModelInstance() {
|
|
4909
4990
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -4919,17 +5000,15 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
4919
5000
|
};
|
|
4920
5001
|
}
|
|
4921
5002
|
homeToFirestore(home) {
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
home.data.data.
|
|
4925
|
-
home.data.data.
|
|
4926
|
-
home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
|
|
5003
|
+
if (home.data?.data) {
|
|
5004
|
+
home.data.data.discoverProducts = home.data.data.discoverProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
5005
|
+
home.data.data.featuredProducts = home.data.data.featuredProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
5006
|
+
home.data.data.verticalProducts = home.data.data.verticalProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4927
5007
|
}
|
|
4928
5008
|
return home;
|
|
4929
5009
|
}
|
|
4930
5010
|
homeFromFirestore(home) {
|
|
4931
|
-
|
|
4932
|
-
if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
|
|
5011
|
+
if (home.data?.data) {
|
|
4933
5012
|
home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
|
|
4934
5013
|
home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
|
|
4935
5014
|
home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
|
|
@@ -5068,8 +5147,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
5068
5147
|
},
|
|
5069
5148
|
});
|
|
5070
5149
|
this.orderFromFirestore = (order) => {
|
|
5071
|
-
|
|
5072
|
-
if ((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length) {
|
|
5150
|
+
if (order?.lineItems?.length) {
|
|
5073
5151
|
order.lineItems = order.lineItems.map((lineItem) => {
|
|
5074
5152
|
const prices = !!lineItem.price;
|
|
5075
5153
|
const shopPrice = prices[order.shop];
|
|
@@ -5084,7 +5162,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
5084
5162
|
buildModelInstance() {
|
|
5085
5163
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
5086
5164
|
return {
|
|
5087
|
-
toFirestore: (data) => toFirestore(
|
|
5165
|
+
toFirestore: (data) => toFirestore(data?.toPlain ? data.toPlain() : data),
|
|
5088
5166
|
fromFirestore: (snap) => {
|
|
5089
5167
|
const instance = fromFirestore(snap);
|
|
5090
5168
|
return this.orderFromFirestore(instance);
|
|
@@ -5115,18 +5193,20 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
|
|
|
5115
5193
|
});
|
|
5116
5194
|
}
|
|
5117
5195
|
async createBlockedOrderOrPayment(params) {
|
|
5118
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5119
5196
|
const { checkout, blockType, type, limiteRange, card = null } = params;
|
|
5120
5197
|
return this.create(OrderBlocked.toInstance({
|
|
5121
5198
|
customer: {
|
|
5122
|
-
name:
|
|
5123
|
-
cpf:
|
|
5124
|
-
id:
|
|
5125
|
-
email:
|
|
5126
|
-
phoneNumber: '+55' +
|
|
5127
|
-
isSubscriber:
|
|
5128
|
-
subscriptionPlan:
|
|
5129
|
-
shippingAddress:
|
|
5199
|
+
name: checkout.user?.displayName || '',
|
|
5200
|
+
cpf: checkout.user?.cpf || '',
|
|
5201
|
+
id: checkout.user?.id,
|
|
5202
|
+
email: checkout.user?.email || '',
|
|
5203
|
+
phoneNumber: '+55' + checkout.user?.phone,
|
|
5204
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
5205
|
+
subscriptionPlan: checkout.user?.subscriptionPlan || '',
|
|
5206
|
+
shippingAddress: {
|
|
5207
|
+
...checkout.shippingAddress,
|
|
5208
|
+
zip: this.formatZip(checkout.shippingAddress?.zip),
|
|
5209
|
+
},
|
|
5130
5210
|
},
|
|
5131
5211
|
blockType,
|
|
5132
5212
|
limiteRange,
|
|
@@ -5374,7 +5454,7 @@ class ConnectDocumentService {
|
|
|
5374
5454
|
this.reference = firestore.doc(this.firestore, this.path).withConverter({
|
|
5375
5455
|
toFirestore: (data) => data,
|
|
5376
5456
|
fromFirestore: (snapshot) => {
|
|
5377
|
-
return
|
|
5457
|
+
return { id: snapshot.id, ...snapshot.data() };
|
|
5378
5458
|
},
|
|
5379
5459
|
});
|
|
5380
5460
|
}
|
|
@@ -5412,7 +5492,7 @@ class ConnectCollectionService {
|
|
|
5412
5492
|
this.reference = firestore.collection(firestore$1, path).withConverter({
|
|
5413
5493
|
toFirestore: (data) => data,
|
|
5414
5494
|
fromFirestore: (snapshot) => {
|
|
5415
|
-
return
|
|
5495
|
+
return { id: snapshot.id, ...snapshot.data() };
|
|
5416
5496
|
},
|
|
5417
5497
|
});
|
|
5418
5498
|
}
|
|
@@ -5507,10 +5587,10 @@ class FirebaseFileUploaderService {
|
|
|
5507
5587
|
function createCreateHasuraGraphQLClass(MixinBase) {
|
|
5508
5588
|
return class CreateHasuraGraphQLMixin extends MixinBase {
|
|
5509
5589
|
constructor(...params) {
|
|
5510
|
-
const options = params
|
|
5590
|
+
const options = params?.[0];
|
|
5511
5591
|
super(...params);
|
|
5512
|
-
this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options
|
|
5513
|
-
this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options
|
|
5592
|
+
this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options?.insertGraphQLOperation);
|
|
5593
|
+
this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options?.insertGraphQLObjectType);
|
|
5514
5594
|
}
|
|
5515
5595
|
async create(data) {
|
|
5516
5596
|
return HasuraCreateOperationsHelper.executeCreate(data, {
|
|
@@ -5537,9 +5617,9 @@ function createCreateHasuraGraphQLClass(MixinBase) {
|
|
|
5537
5617
|
function createDeleteHasuraGraphQLClass(MixinBase) {
|
|
5538
5618
|
return class DeleteHasuraGraphQLMixin extends MixinBase {
|
|
5539
5619
|
constructor(...params) {
|
|
5540
|
-
const options = params
|
|
5620
|
+
const options = params?.[0];
|
|
5541
5621
|
super(...params);
|
|
5542
|
-
this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options
|
|
5622
|
+
this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options?.deleteGraphQLOperation);
|
|
5543
5623
|
}
|
|
5544
5624
|
async delete(identifiers) {
|
|
5545
5625
|
await HasuraDeleteOperationsHelper.executeDelete({
|
|
@@ -5585,9 +5665,9 @@ function createFindHasuraGraphQLClass(MixinBase) {
|
|
|
5585
5665
|
function createGetHasuraGraphQLClass(MixinBase) {
|
|
5586
5666
|
return class GetHasuraGraphQLMixin extends MixinBase {
|
|
5587
5667
|
constructor(...params) {
|
|
5588
|
-
const options = params
|
|
5668
|
+
const options = params?.[0];
|
|
5589
5669
|
super(...params);
|
|
5590
|
-
this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options
|
|
5670
|
+
this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options?.getGraphQLOperation);
|
|
5591
5671
|
}
|
|
5592
5672
|
generateCacheKey(identifiers) {
|
|
5593
5673
|
return HasuraGetCacheHelper.generateCacheKey(this.model, identifiers);
|
|
@@ -5663,11 +5743,11 @@ function createHasuraGraphQLClass(MixinBase) {
|
|
|
5663
5743
|
function createUpdateHasuraGraphQLClass(MixinBase) {
|
|
5664
5744
|
return class UpdateHasuraGraphQLMixin extends MixinBase {
|
|
5665
5745
|
constructor(...params) {
|
|
5666
|
-
const options = params
|
|
5746
|
+
const options = params?.[0];
|
|
5667
5747
|
super(...params);
|
|
5668
|
-
this.updateGraphQLOperation =
|
|
5669
|
-
this.updateGraphQLObjectType =
|
|
5670
|
-
this.updateGraphQLPKType =
|
|
5748
|
+
this.updateGraphQLOperation = options?.updateGraphQLOperation || `update_${this.tableName}_by_pk`;
|
|
5749
|
+
this.updateGraphQLObjectType = options?.updateGraphQLObjectType || `${this.tableName}_set_input`;
|
|
5750
|
+
this.updateGraphQLPKType = options?.updateGraphQLPKType || `${this.tableName}_pk_columns_input`;
|
|
5671
5751
|
}
|
|
5672
5752
|
getIdentifiersFromData(data) {
|
|
5673
5753
|
return HasuraUpdateDataHelper.getIdentifiersFromData(data, this.model);
|
|
@@ -5857,7 +5937,7 @@ const fieldsConfiguration$5 = [
|
|
|
5857
5937
|
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
5858
5938
|
}),
|
|
5859
5939
|
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
5860
|
-
from: (categories) =>
|
|
5940
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
5861
5941
|
},
|
|
5862
5942
|
},
|
|
5863
5943
|
],
|
|
@@ -5938,8 +6018,7 @@ class CategoryCacheOperationsHelper {
|
|
|
5938
6018
|
logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5939
6019
|
}
|
|
5940
6020
|
static shouldUseCache(cacheAdapter, optionsCache) {
|
|
5941
|
-
|
|
5942
|
-
return !!(cacheAdapter && ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.enabled));
|
|
6021
|
+
return !!(cacheAdapter && optionsCache?.cache?.enabled);
|
|
5943
6022
|
}
|
|
5944
6023
|
}
|
|
5945
6024
|
|
|
@@ -6107,19 +6186,25 @@ class CategoryProductOperationsHelper {
|
|
|
6107
6186
|
}
|
|
6108
6187
|
static buildProductQuery(params) {
|
|
6109
6188
|
const { productIds, fields, hasStock, limit } = params;
|
|
6110
|
-
return
|
|
6189
|
+
return {
|
|
6190
|
+
filters: this.buildProductFilters(productIds, hasStock),
|
|
6191
|
+
...(limit ? { limits: { limit } } : {}),
|
|
6192
|
+
fields,
|
|
6193
|
+
options: { enableCount: false },
|
|
6194
|
+
orderBy: {
|
|
6111
6195
|
stock: 'desc',
|
|
6112
6196
|
shoppingCount: 'desc',
|
|
6113
6197
|
rate: 'desc',
|
|
6114
6198
|
name: 'asc',
|
|
6115
|
-
}
|
|
6199
|
+
},
|
|
6200
|
+
};
|
|
6116
6201
|
}
|
|
6117
6202
|
static getGenderParam(shop) {
|
|
6118
6203
|
return shop === exports.Shops.MENSMARKET ? 'male' : 'female';
|
|
6119
6204
|
}
|
|
6120
6205
|
static async fetchMostRelevantProducts(params) {
|
|
6121
6206
|
const { productRepository, mostRelevantsIds, fields, shop, hasStock, optionsCache } = params;
|
|
6122
|
-
if (!
|
|
6207
|
+
if (!mostRelevantsIds?.length)
|
|
6123
6208
|
return [];
|
|
6124
6209
|
const query = this.buildProductQuery({ productIds: mostRelevantsIds, fields, hasStock });
|
|
6125
6210
|
const { data } = await productRepository.findCatalog(query, this.getGenderParam(shop), optionsCache);
|
|
@@ -6148,9 +6233,8 @@ class CategoryProductOperationsHelper {
|
|
|
6148
6233
|
|
|
6149
6234
|
class CategoryMountOperationsHelper {
|
|
6150
6235
|
static async executeMount(params, dependencies) {
|
|
6151
|
-
var _a;
|
|
6152
6236
|
const { category, shop, options = {}, optionsCache } = params;
|
|
6153
|
-
if (!
|
|
6237
|
+
if (!category?.products?.length)
|
|
6154
6238
|
return [];
|
|
6155
6239
|
const cachedResult = await this.tryGetFromCache({
|
|
6156
6240
|
category,
|
|
@@ -6171,7 +6255,7 @@ class CategoryMountOperationsHelper {
|
|
|
6171
6255
|
optionsCache,
|
|
6172
6256
|
dependencies,
|
|
6173
6257
|
});
|
|
6174
|
-
if (mostRelevantProducts.length >= mostRelevantsIds.length) {
|
|
6258
|
+
if (mostRelevantsIds.length && mostRelevantProducts.length >= mostRelevantsIds.length) {
|
|
6175
6259
|
return this.finalizeMountWithMostRelevants({
|
|
6176
6260
|
mostRelevantProducts,
|
|
6177
6261
|
mostRelevantsIds,
|
|
@@ -6248,7 +6332,6 @@ class CategoryMountOperationsHelper {
|
|
|
6248
6332
|
return result;
|
|
6249
6333
|
}
|
|
6250
6334
|
static async saveToCacheIfNeeded(params) {
|
|
6251
|
-
var _a;
|
|
6252
6335
|
const { category, shop, options, optionsCache, result, dependencies } = params;
|
|
6253
6336
|
const shouldUseCache = CategoryCacheOperationsHelper.shouldUseCache(dependencies.cacheAdapter, optionsCache);
|
|
6254
6337
|
if (!shouldUseCache)
|
|
@@ -6258,7 +6341,7 @@ class CategoryMountOperationsHelper {
|
|
|
6258
6341
|
cacheAdapter: dependencies.cacheAdapter,
|
|
6259
6342
|
cacheKey,
|
|
6260
6343
|
products: result,
|
|
6261
|
-
ttl:
|
|
6344
|
+
ttl: optionsCache?.cache?.ttl || dependencies.defaultCacheTtl,
|
|
6262
6345
|
logger: dependencies.logger,
|
|
6263
6346
|
});
|
|
6264
6347
|
}
|
|
@@ -6284,7 +6367,12 @@ class ProductFetchReviewsHelper {
|
|
|
6284
6367
|
...reviews,
|
|
6285
6368
|
...product.reviews
|
|
6286
6369
|
.filter((review) => this.matchesStatus(review, status))
|
|
6287
|
-
.map((review) => (
|
|
6370
|
+
.map((review) => ({
|
|
6371
|
+
...bindReviewToModel(review),
|
|
6372
|
+
productId: product.id,
|
|
6373
|
+
productName: product.name,
|
|
6374
|
+
productSku: product.sku,
|
|
6375
|
+
})),
|
|
6288
6376
|
], []);
|
|
6289
6377
|
}
|
|
6290
6378
|
static matchesStatus(review, status) {
|
|
@@ -6331,8 +6419,7 @@ class ProductReviewCacheHelper {
|
|
|
6331
6419
|
dependencies.logger.log(`Dados salvos no cache: ${key}`);
|
|
6332
6420
|
}
|
|
6333
6421
|
static shouldUseCache(cacheAdapter, options) {
|
|
6334
|
-
|
|
6335
|
-
return !!(cacheAdapter && ((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled));
|
|
6422
|
+
return !!(cacheAdapter && options?.cache?.enabled);
|
|
6336
6423
|
}
|
|
6337
6424
|
}
|
|
6338
6425
|
|
|
@@ -6343,9 +6430,12 @@ class ProductReviewOperationsHelper {
|
|
|
6343
6430
|
let count = 0;
|
|
6344
6431
|
let offset = 0;
|
|
6345
6432
|
do {
|
|
6346
|
-
const result = await repository.find(
|
|
6347
|
-
|
|
6348
|
-
|
|
6433
|
+
const result = await repository.find({
|
|
6434
|
+
fields: ['id', 'name', 'sku', 'reviews'],
|
|
6435
|
+
...(limit && {
|
|
6436
|
+
limits: { offset, limit },
|
|
6437
|
+
}),
|
|
6438
|
+
});
|
|
6349
6439
|
data = data.concat(result.data);
|
|
6350
6440
|
count = result.data.length;
|
|
6351
6441
|
offset += limit;
|
|
@@ -6356,7 +6446,13 @@ class ProductReviewOperationsHelper {
|
|
|
6356
6446
|
const { data, getReviewStatus } = params;
|
|
6357
6447
|
return data.reduce((reviews, product) => [
|
|
6358
6448
|
...reviews,
|
|
6359
|
-
...product.reviews.map((review) => (
|
|
6449
|
+
...product.reviews.map((review) => ({
|
|
6450
|
+
...review,
|
|
6451
|
+
reviewStatus: getReviewStatus(review),
|
|
6452
|
+
productId: product.id,
|
|
6453
|
+
productName: product.name,
|
|
6454
|
+
productSku: product.sku,
|
|
6455
|
+
})),
|
|
6360
6456
|
], []);
|
|
6361
6457
|
}
|
|
6362
6458
|
static applyReviewFilters(params) {
|
|
@@ -6400,7 +6496,7 @@ class ProductReviewUpdateHelper {
|
|
|
6400
6496
|
const { productId, reviews, dependencies } = params;
|
|
6401
6497
|
const reviewIds = await Promise.all(reviews.value.map(async (reviewData) => {
|
|
6402
6498
|
const review = await dependencies.findReview(reviewData, productId);
|
|
6403
|
-
return review
|
|
6499
|
+
return review?.id;
|
|
6404
6500
|
}));
|
|
6405
6501
|
await dependencies.mutation('delete_product_review', ['affected_rows'], {
|
|
6406
6502
|
where: {
|
|
@@ -6439,7 +6535,7 @@ class ProductReviewUpdateHelper {
|
|
|
6439
6535
|
static async insertNewReview(reviewData, productId, dependencies) {
|
|
6440
6536
|
const result = await dependencies.mutation('insert_product_review_one', dependencies.reviewsFields, {
|
|
6441
6537
|
object: {
|
|
6442
|
-
value: lodash.omit(
|
|
6538
|
+
value: lodash.omit({ ...dependencies.bindReviewToHasura(reviewData), product_id: productId.toString() }, ['id']),
|
|
6443
6539
|
type: 'product_review_insert_input',
|
|
6444
6540
|
required: true,
|
|
6445
6541
|
},
|
|
@@ -6532,11 +6628,14 @@ const fieldsConfiguration$4 = [
|
|
|
6532
6628
|
bindPersistData: (value) => {
|
|
6533
6629
|
return {
|
|
6534
6630
|
brand_condition: value.brand,
|
|
6535
|
-
tag_condition:
|
|
6631
|
+
tag_condition: value?.tags || [],
|
|
6536
6632
|
};
|
|
6537
6633
|
},
|
|
6538
6634
|
bindFindFilter: (sentence) => {
|
|
6539
|
-
return
|
|
6635
|
+
return {
|
|
6636
|
+
...(sentence.brand ? { brand_condition: sentence.brand } : {}),
|
|
6637
|
+
...(sentence.tags ? { tag_condition: sentence.tags } : {}),
|
|
6638
|
+
};
|
|
6540
6639
|
},
|
|
6541
6640
|
},
|
|
6542
6641
|
},
|
|
@@ -6548,7 +6647,7 @@ const fieldsConfiguration$4 = [
|
|
|
6548
6647
|
bindPersistData: (value) => ({
|
|
6549
6648
|
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
6550
6649
|
}),
|
|
6551
|
-
from: (filters) =>
|
|
6650
|
+
from: (filters) => filters?.map((filter) => filter?.filter).filter((filter) => filter.enabled) || [],
|
|
6552
6651
|
},
|
|
6553
6652
|
},
|
|
6554
6653
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -6613,11 +6712,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6613
6712
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
6614
6713
|
}
|
|
6615
6714
|
async create(params) {
|
|
6616
|
-
const { images, mostRelevants, metadatas
|
|
6617
|
-
return super.create(
|
|
6715
|
+
const { images, mostRelevants, metadatas, ...data } = params;
|
|
6716
|
+
return super.create({
|
|
6717
|
+
...data,
|
|
6718
|
+
isWishlist: false,
|
|
6719
|
+
metadatas: metadatas || [{ shop: null, description: null, title: null }],
|
|
6720
|
+
mostRelevants: mostRelevants || {
|
|
6618
6721
|
[exports.Shops.GLAMSHOP]: null,
|
|
6619
6722
|
[exports.Shops.MENSMARKET]: null,
|
|
6620
|
-
},
|
|
6723
|
+
},
|
|
6724
|
+
images: images || {
|
|
6621
6725
|
[exports.Shops.GLAMSHOP]: {
|
|
6622
6726
|
brandBanner: null,
|
|
6623
6727
|
brandBannerMobile: null,
|
|
@@ -6628,17 +6732,18 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6628
6732
|
brandBannerMobile: null,
|
|
6629
6733
|
image: null,
|
|
6630
6734
|
},
|
|
6631
|
-
}
|
|
6735
|
+
},
|
|
6736
|
+
});
|
|
6632
6737
|
}
|
|
6633
6738
|
async get(identifiers, optionsCache) {
|
|
6634
6739
|
const id = await this.getId(identifiers.id);
|
|
6635
6740
|
return super.get({ id }, optionsCache);
|
|
6636
6741
|
}
|
|
6637
6742
|
async update(params) {
|
|
6638
|
-
const { id, products, metadatas, filters
|
|
6743
|
+
const { id, products, metadatas, filters, ...data } = params;
|
|
6639
6744
|
const categoryId = +(await this.getId(id));
|
|
6640
6745
|
const [category] = await Promise.all([
|
|
6641
|
-
super.update(
|
|
6746
|
+
super.update({ id: categoryId?.toString(), ...data }),
|
|
6642
6747
|
...(products ? [this.updateProducts(categoryId, { products })] : []),
|
|
6643
6748
|
...(metadatas ? [this.updateMetadata(categoryId, { metadatas })] : []),
|
|
6644
6749
|
...(filters ? [this.updateFilters(categoryId, { filters })] : []),
|
|
@@ -6678,7 +6783,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6678
6783
|
}
|
|
6679
6784
|
async getCategoriesForHome(params) {
|
|
6680
6785
|
const { categoryIds, shop, limit = 4, optionsCache } = params;
|
|
6681
|
-
if (!
|
|
6786
|
+
if (!categoryIds?.length)
|
|
6682
6787
|
return [];
|
|
6683
6788
|
const { firestore, hasura } = CategoryHomeOperationsHelper.separateCategoryIds(categoryIds);
|
|
6684
6789
|
const categories = [];
|
|
@@ -6699,11 +6804,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6699
6804
|
});
|
|
6700
6805
|
}
|
|
6701
6806
|
async mountCategory(params) {
|
|
6702
|
-
var _a, _b;
|
|
6703
6807
|
return CategoryMountOperationsHelper.executeMount(params, {
|
|
6704
6808
|
productRepository: this.productRepository,
|
|
6705
|
-
cacheAdapter:
|
|
6706
|
-
defaultCacheTtl:
|
|
6809
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
6810
|
+
defaultCacheTtl: this.cache?.ttlDefault,
|
|
6707
6811
|
logger: this.logger,
|
|
6708
6812
|
});
|
|
6709
6813
|
}
|
|
@@ -6722,12 +6826,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6722
6826
|
return categoryTree.some((c) => c.id == id.toString());
|
|
6723
6827
|
}
|
|
6724
6828
|
async getId(id) {
|
|
6725
|
-
var _a, _b;
|
|
6726
6829
|
if (!Number.isNaN(+id))
|
|
6727
6830
|
return id;
|
|
6728
6831
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
6729
|
-
if (
|
|
6730
|
-
return
|
|
6832
|
+
if (data?.[0]?.id)
|
|
6833
|
+
return data?.[0]?.id;
|
|
6731
6834
|
throw new NotFoundError(`Category with id ${id} not found`);
|
|
6732
6835
|
}
|
|
6733
6836
|
async updateProducts(categoryId, { products }) {
|
|
@@ -6781,7 +6884,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6781
6884
|
objects: {
|
|
6782
6885
|
type: '[category_metadata_insert_input!]',
|
|
6783
6886
|
required: true,
|
|
6784
|
-
value: metadatas.map((m) => (
|
|
6887
|
+
value: metadatas.map((m) => ({ category_id: categoryId, ...m })),
|
|
6785
6888
|
},
|
|
6786
6889
|
});
|
|
6787
6890
|
return metadatas;
|
|
@@ -6947,7 +7050,7 @@ const fieldsConfiguration$3 = [
|
|
|
6947
7050
|
bindPersistData: (value) => ({
|
|
6948
7051
|
categories: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
6949
7052
|
}),
|
|
6950
|
-
from: (categories) =>
|
|
7053
|
+
from: (categories) => categories?.map((category) => category?.category) || [],
|
|
6951
7054
|
},
|
|
6952
7055
|
},
|
|
6953
7056
|
];
|
|
@@ -6966,7 +7069,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6966
7069
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
6967
7070
|
}
|
|
6968
7071
|
async update(params) {
|
|
6969
|
-
const { options
|
|
7072
|
+
const { options, ...data } = params;
|
|
6970
7073
|
const filter = await super.update(data);
|
|
6971
7074
|
filter.options = await this.updateOptions(+data.id, { options });
|
|
6972
7075
|
return filter;
|
|
@@ -6988,8 +7091,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6988
7091
|
if (hasFilter)
|
|
6989
7092
|
filterOptions.push(hasFilter);
|
|
6990
7093
|
}
|
|
6991
|
-
catch
|
|
6992
|
-
const newOption = await this.filterOptionRepository.create(
|
|
7094
|
+
catch {
|
|
7095
|
+
const newOption = await this.filterOptionRepository.create({ ...options.value[i], filterId });
|
|
6993
7096
|
filterOptions.push(newOption);
|
|
6994
7097
|
}
|
|
6995
7098
|
}
|
|
@@ -7003,8 +7106,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
7003
7106
|
if (hasFilter)
|
|
7004
7107
|
filterOptions.push(hasFilter);
|
|
7005
7108
|
}
|
|
7006
|
-
catch
|
|
7007
|
-
const newOption = await this.filterOptionRepository.create(
|
|
7109
|
+
catch {
|
|
7110
|
+
const newOption = await this.filterOptionRepository.create({ ...options[i], filterId });
|
|
7008
7111
|
filterOptions.push(newOption);
|
|
7009
7112
|
}
|
|
7010
7113
|
}
|
|
@@ -7125,13 +7228,13 @@ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
|
|
|
7125
7228
|
filters: {
|
|
7126
7229
|
id: {
|
|
7127
7230
|
operator: exports.Where.IN,
|
|
7128
|
-
value: Array.from(new Set(variantsWithNoData.map((item) =>
|
|
7231
|
+
value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
|
|
7129
7232
|
},
|
|
7130
7233
|
},
|
|
7131
7234
|
});
|
|
7132
7235
|
products.forEach((product) => {
|
|
7133
7236
|
result.data
|
|
7134
|
-
.filter((variant) =>
|
|
7237
|
+
.filter((variant) => variant.product.productId?.toString() === product.id.toString())
|
|
7135
7238
|
.forEach((variant) => {
|
|
7136
7239
|
variant.product.name = product.name;
|
|
7137
7240
|
variant.product.group = product.group;
|
|
@@ -7164,21 +7267,37 @@ const commonFields = [
|
|
|
7164
7267
|
purpose: data.purpose,
|
|
7165
7268
|
}),
|
|
7166
7269
|
bindFindFilter: (filters) => {
|
|
7167
|
-
return
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7270
|
+
return {
|
|
7271
|
+
...(filters?.description && { description: filters.description }),
|
|
7272
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
7273
|
+
...(filters.whoMustUse && {
|
|
7274
|
+
who_must_use: filters.whoMustUse,
|
|
7275
|
+
}),
|
|
7276
|
+
...(filters.howToUse && {
|
|
7277
|
+
how_to_use: filters.howToUse,
|
|
7278
|
+
}),
|
|
7279
|
+
...(filters.brand && {
|
|
7280
|
+
brand_description: filters.brand,
|
|
7281
|
+
}),
|
|
7282
|
+
...(filters.ingredients && {
|
|
7283
|
+
ingredients: filters.ingredients,
|
|
7284
|
+
}),
|
|
7285
|
+
...(filters.purpose && {
|
|
7286
|
+
purpose: filters.purpose,
|
|
7287
|
+
}),
|
|
7288
|
+
};
|
|
7178
7289
|
},
|
|
7179
|
-
bindPersistData: (descriptionData) => (
|
|
7180
|
-
|
|
7181
|
-
|
|
7290
|
+
bindPersistData: (descriptionData) => ({
|
|
7291
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
7292
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
7293
|
+
...(descriptionData.whoMustUse && {
|
|
7294
|
+
who_must_use: descriptionData.whoMustUse,
|
|
7295
|
+
}),
|
|
7296
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
7297
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
7298
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
7299
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
7300
|
+
}),
|
|
7182
7301
|
},
|
|
7183
7302
|
},
|
|
7184
7303
|
{ differentials: { columnName: 'differentials' } },
|
|
@@ -7191,13 +7310,13 @@ const commonFields = [
|
|
|
7191
7310
|
{
|
|
7192
7311
|
images: {
|
|
7193
7312
|
columnName: 'images',
|
|
7194
|
-
to: (value) =>
|
|
7313
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7195
7314
|
},
|
|
7196
7315
|
},
|
|
7197
7316
|
{
|
|
7198
7317
|
miniatures: {
|
|
7199
7318
|
columnName: 'miniatures',
|
|
7200
|
-
to: (value) =>
|
|
7319
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7201
7320
|
},
|
|
7202
7321
|
},
|
|
7203
7322
|
'name',
|
|
@@ -7212,19 +7331,31 @@ const commonFields = [
|
|
|
7212
7331
|
subscriberPrice: data.subscriber_price,
|
|
7213
7332
|
}),
|
|
7214
7333
|
bindFindFilter: (filters) => {
|
|
7215
|
-
return
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7334
|
+
return {
|
|
7335
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7336
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7337
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7338
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7339
|
+
}),
|
|
7340
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7341
|
+
subscriber_price: filters.subscriberPrice,
|
|
7342
|
+
}),
|
|
7343
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7344
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7345
|
+
}),
|
|
7346
|
+
};
|
|
7222
7347
|
},
|
|
7223
|
-
bindPersistData: (priceData) => (
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7348
|
+
bindPersistData: (priceData) => ({
|
|
7349
|
+
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
7350
|
+
...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
|
|
7351
|
+
...(priceData.subscriberDiscountPercentage >= 0 && {
|
|
7352
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
7353
|
+
}),
|
|
7354
|
+
...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
7355
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
7356
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
7357
|
+
}),
|
|
7358
|
+
}),
|
|
7228
7359
|
},
|
|
7229
7360
|
},
|
|
7230
7361
|
{ fullPrice: { columnName: 'full_price' } },
|
|
@@ -7239,7 +7370,7 @@ const commonFields = [
|
|
|
7239
7370
|
stock: {
|
|
7240
7371
|
columnName: 'stock',
|
|
7241
7372
|
from: (quantity) => ({ quantity }),
|
|
7242
|
-
to: (value) => (lodash.isNil(value
|
|
7373
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
7243
7374
|
},
|
|
7244
7375
|
},
|
|
7245
7376
|
{ hasStock: { columnName: 'has_stock' } },
|
|
@@ -7278,7 +7409,7 @@ const fieldsConfiguration$2 = [
|
|
|
7278
7409
|
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
7279
7410
|
}),
|
|
7280
7411
|
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
7281
|
-
from: (categories) =>
|
|
7412
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
7282
7413
|
},
|
|
7283
7414
|
},
|
|
7284
7415
|
{
|
|
@@ -7354,12 +7485,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7354
7485
|
fields: fieldsConfiguration$2,
|
|
7355
7486
|
cache,
|
|
7356
7487
|
});
|
|
7357
|
-
this.bindReviewToModel = (plain) => ProductReview.toInstance(
|
|
7358
|
-
|
|
7488
|
+
this.bindReviewToModel = (plain) => ProductReview.toInstance({
|
|
7489
|
+
...is(lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
|
|
7490
|
+
createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
|
|
7491
|
+
updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
|
|
7492
|
+
personId: plain.person_id,
|
|
7493
|
+
orderId: plain.order_id,
|
|
7494
|
+
});
|
|
7495
|
+
this.bindReviewToHasura = (review) => ({
|
|
7496
|
+
...is(lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
|
|
7497
|
+
person_id: review.personId,
|
|
7498
|
+
order_id: review.orderId,
|
|
7499
|
+
});
|
|
7359
7500
|
}
|
|
7360
7501
|
async create(params) {
|
|
7361
|
-
const { metadata
|
|
7362
|
-
const product = await super.create(lodash.omit(
|
|
7502
|
+
const { metadata, ...data } = params;
|
|
7503
|
+
const product = await super.create(lodash.omit({ ...data, metadata: metadata || { description: null, title: null } }, ['reviews']));
|
|
7363
7504
|
try {
|
|
7364
7505
|
product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
|
|
7365
7506
|
}
|
|
@@ -7370,10 +7511,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7370
7511
|
return product;
|
|
7371
7512
|
}
|
|
7372
7513
|
async get(identifiers, options) {
|
|
7373
|
-
var _a;
|
|
7374
7514
|
const product = Number.isNaN(+identifiers.id)
|
|
7375
|
-
? (
|
|
7376
|
-
.data
|
|
7515
|
+
? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
|
|
7516
|
+
.data?.[0]
|
|
7377
7517
|
: await super.get(identifiers, options);
|
|
7378
7518
|
if (product.productId)
|
|
7379
7519
|
throw new NotFoundError('Product not found, it is a variant');
|
|
@@ -7381,19 +7521,21 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7381
7521
|
return product;
|
|
7382
7522
|
}
|
|
7383
7523
|
async find(params, optionsParams) {
|
|
7384
|
-
|
|
7385
|
-
const _o = params || {}, { filters, fields } = _o, options = tslib.__rest(_o, ["filters", "fields"]);
|
|
7524
|
+
const { filters, fields, ...options } = params || {};
|
|
7386
7525
|
const bindFields = fields ||
|
|
7387
7526
|
this.fields
|
|
7388
7527
|
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
7389
7528
|
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
7390
|
-
if (
|
|
7391
|
-
|
|
7392
|
-
if (
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
return super.find(
|
|
7529
|
+
if (options.options?.minimal?.includes('price'))
|
|
7530
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7531
|
+
if (options.options?.maximum?.includes('price'))
|
|
7532
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7533
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
7534
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
7535
|
+
return super.find({
|
|
7536
|
+
...options,
|
|
7537
|
+
filters: { ...filters, productId: { operator: exports.Where.ISNULL } },
|
|
7538
|
+
fields: [
|
|
7397
7539
|
...bindFields,
|
|
7398
7540
|
...(bindFields.includes('price')
|
|
7399
7541
|
? [
|
|
@@ -7402,11 +7544,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7402
7544
|
'fullPrice',
|
|
7403
7545
|
]
|
|
7404
7546
|
: []),
|
|
7405
|
-
]
|
|
7547
|
+
],
|
|
7548
|
+
}, optionsParams);
|
|
7406
7549
|
}
|
|
7407
7550
|
async getBySlug(slug, options) {
|
|
7408
|
-
|
|
7409
|
-
if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
|
|
7551
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7410
7552
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
7411
7553
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7412
7554
|
if (cachedData) {
|
|
@@ -7425,70 +7567,68 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7425
7567
|
});
|
|
7426
7568
|
if (!result.data.length)
|
|
7427
7569
|
return null;
|
|
7428
|
-
const product =
|
|
7570
|
+
const product = result?.data?.shift();
|
|
7429
7571
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
7430
|
-
if (
|
|
7572
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7431
7573
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
7432
7574
|
await this.cache.cacheAdapter.set({
|
|
7433
7575
|
key: cacheKey,
|
|
7434
7576
|
data: serialize(product),
|
|
7435
|
-
expirationInSeconds:
|
|
7577
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7436
7578
|
});
|
|
7437
7579
|
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7438
7580
|
}
|
|
7439
7581
|
return product;
|
|
7440
7582
|
}
|
|
7441
7583
|
async update(params) {
|
|
7442
|
-
const
|
|
7584
|
+
const { kitProducts, reviews, id: checkId, metadata, ...data } = lodash.omit(params, ['categories', 'rate']);
|
|
7443
7585
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
7444
7586
|
const id = await this.getId(plainData.id);
|
|
7445
|
-
const product = await super.update(
|
|
7587
|
+
const product = await super.update({ id, ...data });
|
|
7446
7588
|
product.kitProducts = kitProducts && (await this.updateKitProducts(+id, { kitProducts }));
|
|
7447
7589
|
product.reviews = reviews && (await this.updateReviews(+id, { reviews }));
|
|
7448
7590
|
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
7449
7591
|
return product;
|
|
7450
7592
|
}
|
|
7451
7593
|
async fetchProductReviews(filters, options) {
|
|
7452
|
-
var _a, _b, _c, _d, _e;
|
|
7453
7594
|
const cacheKey = ProductReviewCacheHelper.generateProductReviewsCacheKey(filters, this.model.name);
|
|
7454
7595
|
const dependencies = {
|
|
7455
|
-
cacheAdapter:
|
|
7596
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
7456
7597
|
logger: this.logger,
|
|
7457
7598
|
modelName: this.model.name,
|
|
7458
|
-
defaultTtl:
|
|
7599
|
+
defaultTtl: this.cache?.ttlDefault,
|
|
7459
7600
|
};
|
|
7460
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7601
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7461
7602
|
const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
|
|
7462
7603
|
if (cachedData)
|
|
7463
7604
|
return cachedData;
|
|
7464
7605
|
}
|
|
7465
|
-
const limit =
|
|
7606
|
+
const limit = filters?.limit || 500;
|
|
7466
7607
|
const data = await ProductReviewOperationsHelper.fetchAllProductsWithReviews({ repository: this, limit });
|
|
7467
7608
|
const reviews = ProductReviewOperationsHelper.processProductsToReviews({
|
|
7468
7609
|
data,
|
|
7469
7610
|
getReviewStatus: this.getReviewStatus.bind(this),
|
|
7470
7611
|
});
|
|
7471
7612
|
const filteredReviews = ProductReviewOperationsHelper.applyReviewFilters({ reviews, filters });
|
|
7472
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7613
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7473
7614
|
await ProductReviewCacheHelper.saveToCache({
|
|
7474
7615
|
key: cacheKey,
|
|
7475
7616
|
data: filteredReviews,
|
|
7476
|
-
ttl:
|
|
7617
|
+
ttl: options?.cache?.ttl,
|
|
7477
7618
|
dependencies,
|
|
7478
7619
|
});
|
|
7479
7620
|
}
|
|
7480
7621
|
return filteredReviews;
|
|
7481
7622
|
}
|
|
7482
7623
|
async fetchReviews(status, options) {
|
|
7483
|
-
var _a, _b, _c, _d, _e;
|
|
7484
7624
|
const cacheKey = ProductReviewCacheHelper.generateReviewsStatusCacheKey(status, this.model.name);
|
|
7485
7625
|
const dependencies = {
|
|
7486
|
-
cacheAdapter:
|
|
7626
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
7487
7627
|
logger: this.logger,
|
|
7488
7628
|
modelName: this.model.name,
|
|
7489
|
-
defaultTtl:
|
|
7629
|
+
defaultTtl: this.cache?.ttlDefault,
|
|
7490
7630
|
};
|
|
7491
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7631
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7492
7632
|
const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
|
|
7493
7633
|
if (cachedData)
|
|
7494
7634
|
return cachedData;
|
|
@@ -7499,18 +7639,26 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7499
7639
|
reviewsFields: this.reviewsFields,
|
|
7500
7640
|
};
|
|
7501
7641
|
const reviews = await ProductFetchReviewsHelper.executeQuery(status, fetchDependencies);
|
|
7502
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7642
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7503
7643
|
await ProductReviewCacheHelper.saveToCache({
|
|
7504
7644
|
key: cacheKey,
|
|
7505
7645
|
data: reviews,
|
|
7506
|
-
ttl:
|
|
7646
|
+
ttl: options?.cache?.ttl,
|
|
7507
7647
|
dependencies,
|
|
7508
7648
|
});
|
|
7509
7649
|
}
|
|
7510
7650
|
return reviews;
|
|
7511
7651
|
}
|
|
7512
7652
|
async findCatalog(params, mainGender, options) {
|
|
7513
|
-
const result = await this.find(
|
|
7653
|
+
const result = await this.find({
|
|
7654
|
+
...params,
|
|
7655
|
+
filters: { ...params.filters, published: true },
|
|
7656
|
+
orderBy: {
|
|
7657
|
+
hasStock: 'desc',
|
|
7658
|
+
...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
|
|
7659
|
+
...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
|
|
7660
|
+
},
|
|
7661
|
+
}, options);
|
|
7514
7662
|
return result;
|
|
7515
7663
|
}
|
|
7516
7664
|
async cleanShoppingCountFromIds(ids) {
|
|
@@ -7581,17 +7729,15 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7581
7729
|
return plainData.metadata;
|
|
7582
7730
|
}
|
|
7583
7731
|
async getId(id) {
|
|
7584
|
-
var _a, _b;
|
|
7585
7732
|
if (!Number.isNaN(+id))
|
|
7586
7733
|
return id;
|
|
7587
7734
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
7588
|
-
if (
|
|
7589
|
-
return
|
|
7735
|
+
if (data?.[0]?.id)
|
|
7736
|
+
return data?.[0]?.id;
|
|
7590
7737
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7591
7738
|
}
|
|
7592
7739
|
async findReviewsByProduct(productId, options) {
|
|
7593
|
-
|
|
7594
|
-
if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
|
|
7740
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7595
7741
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7596
7742
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7597
7743
|
if (cachedData) {
|
|
@@ -7608,13 +7754,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7608
7754
|
required: true,
|
|
7609
7755
|
},
|
|
7610
7756
|
});
|
|
7611
|
-
const reviews = data
|
|
7612
|
-
if (
|
|
7757
|
+
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
7758
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
7613
7759
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7614
7760
|
await this.cache.cacheAdapter.set({
|
|
7615
7761
|
key: cacheKey,
|
|
7616
7762
|
data: serialize(reviews),
|
|
7617
|
-
expirationInSeconds:
|
|
7763
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7618
7764
|
});
|
|
7619
7765
|
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7620
7766
|
}
|
|
@@ -7638,23 +7784,32 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7638
7784
|
async getReviewByPersonId(personId, productId, orderId) {
|
|
7639
7785
|
const { product_review: data } = await this.query('product_review', this.reviewsFields, {
|
|
7640
7786
|
where: {
|
|
7641
|
-
value:
|
|
7787
|
+
value: {
|
|
7788
|
+
product_id: { _eq: productId },
|
|
7789
|
+
person_id: { _eq: personId },
|
|
7790
|
+
...(orderId && { order_id: { _eq: orderId } }),
|
|
7791
|
+
},
|
|
7642
7792
|
type: 'product_review_bool_exp',
|
|
7643
7793
|
required: true,
|
|
7644
7794
|
},
|
|
7645
7795
|
});
|
|
7646
|
-
return
|
|
7796
|
+
return data?.[0] && this.bindReviewToModel(data[0]);
|
|
7647
7797
|
}
|
|
7648
7798
|
async getReviewByAuthorAndEmail(params) {
|
|
7649
7799
|
const { author, email, productId, orderId } = params;
|
|
7650
7800
|
const { product_review: data } = await this.query('product_review', this.reviewsFields, {
|
|
7651
7801
|
where: {
|
|
7652
|
-
value:
|
|
7802
|
+
value: {
|
|
7803
|
+
product_id: { _eq: productId },
|
|
7804
|
+
author: { _eq: author },
|
|
7805
|
+
email: { _eq: email },
|
|
7806
|
+
...(orderId && { order_id: { _eq: orderId } }),
|
|
7807
|
+
},
|
|
7653
7808
|
type: 'product_review_bool_exp',
|
|
7654
7809
|
required: true,
|
|
7655
7810
|
},
|
|
7656
7811
|
});
|
|
7657
|
-
return
|
|
7812
|
+
return data?.[0] && this.bindReviewToModel(data[0]);
|
|
7658
7813
|
}
|
|
7659
7814
|
async productVariantFullReport() {
|
|
7660
7815
|
const dependencies = {
|
|
@@ -7803,7 +7958,16 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
|
|
|
7803
7958
|
});
|
|
7804
7959
|
}
|
|
7805
7960
|
async getNotificationsReport(params, orderBy, pagination) {
|
|
7806
|
-
const query =
|
|
7961
|
+
const query = {
|
|
7962
|
+
...(params.productId && { product_id: { _eq: params.productId } }),
|
|
7963
|
+
...(params.ean && { ean: { _eq: params.ean } }),
|
|
7964
|
+
...(params.sku && { sku: { _eq: params.sku } }),
|
|
7965
|
+
...(params.name && { name: { _iregex: params.name } }),
|
|
7966
|
+
...(params.categoryId && { category_id: { _eq: params.categoryId } }),
|
|
7967
|
+
...(params.category && { category: { _iregex: params.category } }),
|
|
7968
|
+
...(params.reference && { category_reference: { _eq: params.reference } }),
|
|
7969
|
+
...(params.emailsCount && { emails_registered: { _eq: params.emailsCount } }),
|
|
7970
|
+
};
|
|
7807
7971
|
const orderByField = {
|
|
7808
7972
|
[orderBy.field]: orderBy.direction,
|
|
7809
7973
|
};
|
|
@@ -7819,8 +7983,8 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
|
|
|
7819
7983
|
required: true,
|
|
7820
7984
|
},
|
|
7821
7985
|
});
|
|
7822
|
-
const data =
|
|
7823
|
-
? reportStockNotification.slice(pagination
|
|
7986
|
+
const data = pagination?.limit
|
|
7987
|
+
? reportStockNotification.slice(pagination?.offset, pagination?.offset + pagination?.limit)
|
|
7824
7988
|
: reportStockNotification;
|
|
7825
7989
|
return {
|
|
7826
7990
|
data,
|
|
@@ -7836,7 +8000,7 @@ const fieldsConfiguration$1 = [
|
|
|
7836
8000
|
productId: {
|
|
7837
8001
|
columnName: 'main_product_id',
|
|
7838
8002
|
to: (value) => +value,
|
|
7839
|
-
from: (value) => value
|
|
8003
|
+
from: (value) => value?.toString(),
|
|
7840
8004
|
},
|
|
7841
8005
|
},
|
|
7842
8006
|
{ EAN: { columnName: 'ean' } },
|
|
@@ -7853,19 +8017,31 @@ const fieldsConfiguration$1 = [
|
|
|
7853
8017
|
}),
|
|
7854
8018
|
bindFindFilter: (sentence) => {
|
|
7855
8019
|
const filters = Object.values(sentence).shift();
|
|
7856
|
-
return
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
8020
|
+
return {
|
|
8021
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
8022
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
8023
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
8024
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
8025
|
+
}),
|
|
8026
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
8027
|
+
subscriber_price: filters.subscriberPrice,
|
|
8028
|
+
}),
|
|
8029
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
8030
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
8031
|
+
}),
|
|
8032
|
+
};
|
|
7863
8033
|
},
|
|
7864
|
-
bindPersistData: (priceData) => (
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
8034
|
+
bindPersistData: (priceData) => ({
|
|
8035
|
+
...((priceData?.price || 0) >= 0 && { price: priceData.price }),
|
|
8036
|
+
...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
|
|
8037
|
+
...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
|
|
8038
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
8039
|
+
}),
|
|
8040
|
+
...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
8041
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
8042
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
8043
|
+
}),
|
|
8044
|
+
}),
|
|
7869
8045
|
},
|
|
7870
8046
|
},
|
|
7871
8047
|
{ fullPrice: { columnName: 'full_price' } },
|
|
@@ -7877,7 +8053,7 @@ const fieldsConfiguration$1 = [
|
|
|
7877
8053
|
stock: {
|
|
7878
8054
|
columnName: 'stock',
|
|
7879
8055
|
from: (quantity) => ({ quantity }),
|
|
7880
|
-
to: (value) => (lodash.isNil(value
|
|
8056
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
7881
8057
|
},
|
|
7882
8058
|
},
|
|
7883
8059
|
{ hasStock: { columnName: 'has_stock' } },
|
|
@@ -7910,41 +8086,39 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7910
8086
|
});
|
|
7911
8087
|
}
|
|
7912
8088
|
async get(identifiers) {
|
|
7913
|
-
var _a;
|
|
7914
8089
|
if (!identifiers.id) {
|
|
7915
8090
|
throw new NotFoundError('Variant ID is required');
|
|
7916
8091
|
}
|
|
7917
8092
|
const variant = Number.isNaN(+identifiers.id)
|
|
7918
|
-
? (
|
|
8093
|
+
? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
|
|
7919
8094
|
: await super.get(identifiers);
|
|
7920
8095
|
if (!variant.productId)
|
|
7921
8096
|
throw new NotFoundError('Variant not found, it is a product');
|
|
7922
8097
|
return variant;
|
|
7923
8098
|
}
|
|
7924
8099
|
async find(params) {
|
|
7925
|
-
const
|
|
7926
|
-
return super.find(
|
|
8100
|
+
const { filters, ...options } = params || {};
|
|
8101
|
+
return super.find({ ...options, filters: { productId: { operator: exports.Where.ISNOTNULL }, ...filters } });
|
|
7927
8102
|
}
|
|
7928
8103
|
async update(params) {
|
|
7929
|
-
const { productId, id: checkId
|
|
8104
|
+
const { productId, id: checkId, ...data } = params;
|
|
7930
8105
|
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
7931
8106
|
if (!dataWithProductId.id) {
|
|
7932
8107
|
throw new NotFoundError('Variant ID is required for update');
|
|
7933
8108
|
}
|
|
7934
8109
|
const id = await this.getId(dataWithProductId.id);
|
|
7935
|
-
const product = await super.update(
|
|
8110
|
+
const product = await super.update({ id, ...data });
|
|
7936
8111
|
if (dataWithProductId.productId) {
|
|
7937
8112
|
product.productId = dataWithProductId.productId;
|
|
7938
8113
|
}
|
|
7939
8114
|
return product;
|
|
7940
8115
|
}
|
|
7941
8116
|
async getId(id) {
|
|
7942
|
-
var _a, _b;
|
|
7943
8117
|
if (!Number.isNaN(+id))
|
|
7944
8118
|
return id;
|
|
7945
8119
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
7946
|
-
if (
|
|
7947
|
-
return
|
|
8120
|
+
if (data?.[0]?.id)
|
|
8121
|
+
return data?.[0]?.id;
|
|
7948
8122
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7949
8123
|
}
|
|
7950
8124
|
}
|
|
@@ -7975,11 +8149,14 @@ const fieldsConfiguration = [
|
|
|
7975
8149
|
bindPersistData: (value) => {
|
|
7976
8150
|
return {
|
|
7977
8151
|
brand_condition: value.brand,
|
|
7978
|
-
tag_condition:
|
|
8152
|
+
tag_condition: value?.tags || [],
|
|
7979
8153
|
};
|
|
7980
8154
|
},
|
|
7981
8155
|
bindFindFilter: (sentence) => {
|
|
7982
|
-
return
|
|
8156
|
+
return {
|
|
8157
|
+
...(sentence.brand ? { brand_condition: sentence.brand } : {}),
|
|
8158
|
+
...(sentence.tags ? { tag_condition: sentence.tags } : {}),
|
|
8159
|
+
};
|
|
7983
8160
|
},
|
|
7984
8161
|
},
|
|
7985
8162
|
},
|
|
@@ -7991,7 +8168,7 @@ const fieldsConfiguration = [
|
|
|
7991
8168
|
bindPersistData: (value) => ({
|
|
7992
8169
|
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
7993
8170
|
}),
|
|
7994
|
-
from: (filters) =>
|
|
8171
|
+
from: (filters) => filters?.map((filter) => filter?.filter) || [],
|
|
7995
8172
|
},
|
|
7996
8173
|
},
|
|
7997
8174
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -8059,12 +8236,18 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8059
8236
|
this.categoryProductRepository = categoryProductRepository;
|
|
8060
8237
|
}
|
|
8061
8238
|
async create(params) {
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
|
|
8239
|
+
const { images, mostRelevants, metadatas, ...data } = params;
|
|
8240
|
+
return super.create({
|
|
8241
|
+
...data,
|
|
8242
|
+
isWishlist: true,
|
|
8243
|
+
isCollection: true,
|
|
8244
|
+
brandCategory: false,
|
|
8245
|
+
metadatas: metadatas || [{ shop: data.shop ?? null, description: data.description, title: data.name }],
|
|
8246
|
+
mostRelevants: mostRelevants || {
|
|
8065
8247
|
[exports.Shops.GLAMSHOP]: null,
|
|
8066
8248
|
[exports.Shops.MENSMARKET]: null,
|
|
8067
|
-
},
|
|
8249
|
+
},
|
|
8250
|
+
images: images || {
|
|
8068
8251
|
[exports.Shops.GLAMSHOP]: {
|
|
8069
8252
|
brandBanner: null,
|
|
8070
8253
|
brandBannerMobile: null,
|
|
@@ -8075,7 +8258,8 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8075
8258
|
brandBannerMobile: null,
|
|
8076
8259
|
image: null,
|
|
8077
8260
|
},
|
|
8078
|
-
}
|
|
8261
|
+
},
|
|
8262
|
+
});
|
|
8079
8263
|
}
|
|
8080
8264
|
async get(identifiers) {
|
|
8081
8265
|
const data = await super.get(identifiers);
|
|
@@ -8084,14 +8268,20 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8084
8268
|
return data;
|
|
8085
8269
|
}
|
|
8086
8270
|
async find(params) {
|
|
8087
|
-
const { filters
|
|
8088
|
-
return await super.find(
|
|
8271
|
+
const { filters, ...rest } = params;
|
|
8272
|
+
return await super.find({
|
|
8273
|
+
...rest,
|
|
8274
|
+
filters: {
|
|
8275
|
+
...filters,
|
|
8276
|
+
isWishlist: { operator: exports.Where.EQUALS, value: true },
|
|
8277
|
+
},
|
|
8278
|
+
});
|
|
8089
8279
|
}
|
|
8090
8280
|
async update(params) {
|
|
8091
|
-
const
|
|
8281
|
+
const { id: checkId, metadatas, ...data } = lodash.omit(params, ['products', 'filters']);
|
|
8092
8282
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
8093
8283
|
const id = plainData.id;
|
|
8094
|
-
const category = await super.update(
|
|
8284
|
+
const category = await super.update({ id, ...data, isWishlist: true, isCollection: true, brandCategory: false });
|
|
8095
8285
|
category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
|
|
8096
8286
|
return category;
|
|
8097
8287
|
}
|
|
@@ -8154,11 +8344,22 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8154
8344
|
return data;
|
|
8155
8345
|
}
|
|
8156
8346
|
async findBfluOrGlamgirlWishlists(params, shops) {
|
|
8157
|
-
|
|
8158
|
-
|
|
8347
|
+
return this.find({
|
|
8348
|
+
...params,
|
|
8349
|
+
filters: {
|
|
8350
|
+
...params.filters,
|
|
8351
|
+
published: true,
|
|
8352
|
+
shops: { operator: exports.Where.LIKE, value: shops },
|
|
8353
|
+
personType: params.filters?.personType ?? {
|
|
8159
8354
|
operator: exports.Where.IN,
|
|
8160
8355
|
value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
|
|
8161
|
-
}
|
|
8356
|
+
},
|
|
8357
|
+
},
|
|
8358
|
+
orderBy: {
|
|
8359
|
+
personHasPhoto: 'desc',
|
|
8360
|
+
...lodash.omit(params.orderBy, ['personHasPhoto']),
|
|
8361
|
+
},
|
|
8362
|
+
});
|
|
8162
8363
|
}
|
|
8163
8364
|
getCategoriesForHome() {
|
|
8164
8365
|
return;
|
|
@@ -8366,7 +8567,7 @@ class PagarmePaymentFactoryHelper {
|
|
|
8366
8567
|
checkoutId: checkout.id,
|
|
8367
8568
|
totalPrice: checkout.totalPrice,
|
|
8368
8569
|
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
8369
|
-
transaction:
|
|
8570
|
+
transaction: { ...resultData, paidAt: new Date() },
|
|
8370
8571
|
});
|
|
8371
8572
|
return payment;
|
|
8372
8573
|
}
|
|
@@ -8386,6 +8587,178 @@ class PagarmePaymentOperationsHelper {
|
|
|
8386
8587
|
}
|
|
8387
8588
|
}
|
|
8388
8589
|
|
|
8590
|
+
class PagarMeV5RequestHelper {
|
|
8591
|
+
static build(checkout, type, card) {
|
|
8592
|
+
return {
|
|
8593
|
+
items: this.buildItems(checkout),
|
|
8594
|
+
customer: this.buildCustomer(checkout),
|
|
8595
|
+
shipping: this.buildShipping(checkout),
|
|
8596
|
+
payments: this.buildPayment(checkout, type, card),
|
|
8597
|
+
};
|
|
8598
|
+
}
|
|
8599
|
+
static buildItems(checkout) {
|
|
8600
|
+
return checkout.lineItems.map((item) => {
|
|
8601
|
+
return {
|
|
8602
|
+
amount: Math.floor(item.pricePaid * 100),
|
|
8603
|
+
description: item.name,
|
|
8604
|
+
quantity: item.quantity,
|
|
8605
|
+
};
|
|
8606
|
+
});
|
|
8607
|
+
}
|
|
8608
|
+
static buildCustomer(checkout) {
|
|
8609
|
+
return {
|
|
8610
|
+
name: checkout.user.displayName,
|
|
8611
|
+
email: checkout.user.email,
|
|
8612
|
+
type: 'individual',
|
|
8613
|
+
document: checkout.user.cpf,
|
|
8614
|
+
phones: {
|
|
8615
|
+
mobile_phone: {
|
|
8616
|
+
country_code: '55',
|
|
8617
|
+
number: checkout.user.phone.slice(2),
|
|
8618
|
+
area_code: checkout.user.phone.slice(0, 1),
|
|
8619
|
+
},
|
|
8620
|
+
},
|
|
8621
|
+
address: {
|
|
8622
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
8623
|
+
line_2: `${checkout.billingAddress.extension}`,
|
|
8624
|
+
zip_code: checkout.shippingAddress.zip,
|
|
8625
|
+
city: checkout.billingAddress.city,
|
|
8626
|
+
state: checkout.billingAddress.state,
|
|
8627
|
+
country: checkout.billingAddress.country,
|
|
8628
|
+
},
|
|
8629
|
+
};
|
|
8630
|
+
}
|
|
8631
|
+
static buildShipping(checkout) {
|
|
8632
|
+
return {
|
|
8633
|
+
amount: checkout.shipping.ShippingPrice,
|
|
8634
|
+
description: '',
|
|
8635
|
+
recipient_name: checkout.shippingAddress.recipient,
|
|
8636
|
+
recipient_phone: checkout.user.phone,
|
|
8637
|
+
address: {
|
|
8638
|
+
line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
8639
|
+
line_2: `${checkout.shippingAddress.extension}`,
|
|
8640
|
+
zip_code: checkout.shippingAddress.zip,
|
|
8641
|
+
city: checkout.shippingAddress.city,
|
|
8642
|
+
state: checkout.shippingAddress.state,
|
|
8643
|
+
country: checkout.shippingAddress.country,
|
|
8644
|
+
},
|
|
8645
|
+
};
|
|
8646
|
+
}
|
|
8647
|
+
static buildPayment(checkout, type, card) {
|
|
8648
|
+
return [
|
|
8649
|
+
{
|
|
8650
|
+
payment_method: type,
|
|
8651
|
+
amount: Math.floor(checkout.totalPrice * 100),
|
|
8652
|
+
...(type === 'pix' && {
|
|
8653
|
+
pix: this.getPixOrder(),
|
|
8654
|
+
}),
|
|
8655
|
+
...(type === 'boleto' && {
|
|
8656
|
+
boleto: this.getBoletoOrder(),
|
|
8657
|
+
}),
|
|
8658
|
+
...(type === 'credit_card' && {
|
|
8659
|
+
credit_card: this.getCardOrder(checkout, card),
|
|
8660
|
+
}),
|
|
8661
|
+
},
|
|
8662
|
+
];
|
|
8663
|
+
}
|
|
8664
|
+
static getPixOrder() {
|
|
8665
|
+
return {
|
|
8666
|
+
expires_at: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
|
|
8667
|
+
};
|
|
8668
|
+
}
|
|
8669
|
+
static getBoletoOrder() {
|
|
8670
|
+
return {
|
|
8671
|
+
due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
|
|
8672
|
+
instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
|
|
8673
|
+
type: 'DM',
|
|
8674
|
+
document_number: new Date().getTime().toString(),
|
|
8675
|
+
};
|
|
8676
|
+
}
|
|
8677
|
+
static getCardOrder(checkout, card) {
|
|
8678
|
+
return {
|
|
8679
|
+
installments: card.installments,
|
|
8680
|
+
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : "Men's Market",
|
|
8681
|
+
card_id: card.cardId,
|
|
8682
|
+
card: {
|
|
8683
|
+
cvv: card.cardCvv,
|
|
8684
|
+
},
|
|
8685
|
+
};
|
|
8686
|
+
}
|
|
8687
|
+
}
|
|
8688
|
+
|
|
8689
|
+
class PagarMeV5ResponseHelper {
|
|
8690
|
+
static build(checkout, response) {
|
|
8691
|
+
return Payment.toInstance({
|
|
8692
|
+
createdAt: new Date(),
|
|
8693
|
+
updatedAt: new Date(),
|
|
8694
|
+
userId: checkout.user.id,
|
|
8695
|
+
checkoutId: checkout.id,
|
|
8696
|
+
totalPrice: checkout.totalPrice,
|
|
8697
|
+
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
8698
|
+
pagarMeOrderId: response.id,
|
|
8699
|
+
transaction: this.buildPaymentTransaction(response),
|
|
8700
|
+
});
|
|
8701
|
+
}
|
|
8702
|
+
static buildPaymentTransaction(response) {
|
|
8703
|
+
const charger = response.charges.at(0);
|
|
8704
|
+
const transaction = charger.last_transaction;
|
|
8705
|
+
return PaymentTransaction.toInstance({
|
|
8706
|
+
acquirer_name: 'pagar_me',
|
|
8707
|
+
amount: charger.amount,
|
|
8708
|
+
currency: charger.currency,
|
|
8709
|
+
gateway_id: charger.gateway_id,
|
|
8710
|
+
status: charger.status,
|
|
8711
|
+
payment_method: charger.payment_method,
|
|
8712
|
+
date_created: charger.created_at,
|
|
8713
|
+
date_updated: charger.updated_at,
|
|
8714
|
+
paid_amount: charger.paid_amount,
|
|
8715
|
+
paid_at: charger.paid_at,
|
|
8716
|
+
order_id: response.id,
|
|
8717
|
+
tid: +transaction.id,
|
|
8718
|
+
id: +transaction.id,
|
|
8719
|
+
...this.getBoletoReponse(transaction),
|
|
8720
|
+
...this.getPixReponse(transaction),
|
|
8721
|
+
...this.getCardReponse(transaction),
|
|
8722
|
+
});
|
|
8723
|
+
}
|
|
8724
|
+
static getBoletoReponse(transaction) {
|
|
8725
|
+
return {
|
|
8726
|
+
boleto_url: transaction.url?.toString(),
|
|
8727
|
+
boleto_barcode: transaction.barcode?.toString(),
|
|
8728
|
+
boleto_qr_code: transaction.qr_code?.toString(),
|
|
8729
|
+
boleto_expiration_date: transaction.due_at?.toString(),
|
|
8730
|
+
boleto_instructions: transaction.instructions?.toString(),
|
|
8731
|
+
boleto_nosso_numero: transaction.nosso_numero?.toString(),
|
|
8732
|
+
boleto_type: transaction.type?.toString(),
|
|
8733
|
+
boleto_document_number: transaction.document_number?.toString(),
|
|
8734
|
+
};
|
|
8735
|
+
}
|
|
8736
|
+
static getPixReponse(transaction) {
|
|
8737
|
+
return {
|
|
8738
|
+
pix_qr_code: transaction.qr_code?.toString(),
|
|
8739
|
+
pix_qr_code_url: transaction.qr_code_url?.toString(),
|
|
8740
|
+
pix_expiration_date: transaction.expires_at?.toString(),
|
|
8741
|
+
};
|
|
8742
|
+
}
|
|
8743
|
+
static getCardReponse(transaction) {
|
|
8744
|
+
return {
|
|
8745
|
+
soft_descriptor: transaction.statement_descriptor?.toString(),
|
|
8746
|
+
acquirer_name: transaction.acquirer_name?.toString(),
|
|
8747
|
+
acquirer_id: transaction.acquirer_tid?.toString(),
|
|
8748
|
+
acquirer_nsu: transaction.acquirer_nsu?.toString(),
|
|
8749
|
+
acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
|
|
8750
|
+
acquirer_message: transaction.acquirer_message?.toString(),
|
|
8751
|
+
acquirer_return_code: transaction.acquirer_return_code?.toString(),
|
|
8752
|
+
installments: transaction.installments ?? null,
|
|
8753
|
+
card_holder_name: transaction.card.holder_name?.toString(),
|
|
8754
|
+
card_last_digits: transaction.card.last_four_digits?.toString(),
|
|
8755
|
+
card_first_digits: transaction.card.first_six_digits?.toString(),
|
|
8756
|
+
card_brand: transaction.card.brand?.toString(),
|
|
8757
|
+
card_id: transaction.card.id?.toString(),
|
|
8758
|
+
};
|
|
8759
|
+
}
|
|
8760
|
+
}
|
|
8761
|
+
|
|
8389
8762
|
class PagarmeCardAxiosAdapter {
|
|
8390
8763
|
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
8391
8764
|
this.credentials = credentials;
|
|
@@ -8393,7 +8766,6 @@ class PagarmeCardAxiosAdapter {
|
|
|
8393
8766
|
this.orderBlockedRepository = orderBlockedRepository;
|
|
8394
8767
|
}
|
|
8395
8768
|
async pay(checkout, card) {
|
|
8396
|
-
var _a;
|
|
8397
8769
|
try {
|
|
8398
8770
|
const result = await PagarmePaymentOperationsHelper.executePaymentRequest({
|
|
8399
8771
|
checkout,
|
|
@@ -8419,7 +8791,7 @@ class PagarmeCardAxiosAdapter {
|
|
|
8419
8791
|
if (error instanceof PaymentError) {
|
|
8420
8792
|
throw error;
|
|
8421
8793
|
}
|
|
8422
|
-
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout,
|
|
8794
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
8423
8795
|
}
|
|
8424
8796
|
}
|
|
8425
8797
|
async addCard(card) {
|
|
@@ -8486,7 +8858,10 @@ class PagarmeCardAxiosAdapter {
|
|
|
8486
8858
|
const { data } = await axios__default["default"]({
|
|
8487
8859
|
method: 'POST',
|
|
8488
8860
|
url: `${this.credentials.URL}/transactions`,
|
|
8489
|
-
data:
|
|
8861
|
+
data: {
|
|
8862
|
+
...info,
|
|
8863
|
+
api_key: this.credentials.API_KEY,
|
|
8864
|
+
},
|
|
8490
8865
|
});
|
|
8491
8866
|
return data;
|
|
8492
8867
|
}
|
|
@@ -8497,7 +8872,6 @@ class PagarmeCardAxiosAdapter {
|
|
|
8497
8872
|
}
|
|
8498
8873
|
}
|
|
8499
8874
|
createCardPayment(checkout, card) {
|
|
8500
|
-
var _a, _b, _c, _d, _e, _f;
|
|
8501
8875
|
return {
|
|
8502
8876
|
api_key: this.credentials.API_KEY,
|
|
8503
8877
|
amount: Math.floor(checkout.totalPrice * 100),
|
|
@@ -8524,14 +8898,14 @@ class PagarmeCardAxiosAdapter {
|
|
|
8524
8898
|
name: checkout.user.displayName,
|
|
8525
8899
|
address: {
|
|
8526
8900
|
country: 'br',
|
|
8527
|
-
state: checkout.billingAddress ? checkout.billingAddress.state :
|
|
8528
|
-
city: checkout.billingAddress ? checkout.billingAddress.city :
|
|
8529
|
-
neighborhood: checkout.billingAddress ? checkout.billingAddress.district :
|
|
8530
|
-
street: checkout.billingAddress ? checkout.billingAddress.street :
|
|
8531
|
-
street_number: checkout.billingAddress ? checkout.billingAddress.number :
|
|
8901
|
+
state: checkout.billingAddress ? checkout.billingAddress.state : checkout.shippingAddress?.state,
|
|
8902
|
+
city: checkout.billingAddress ? checkout.billingAddress.city : checkout.shippingAddress?.city,
|
|
8903
|
+
neighborhood: checkout.billingAddress ? checkout.billingAddress.district : checkout.shippingAddress?.district,
|
|
8904
|
+
street: checkout.billingAddress ? checkout.billingAddress.street : checkout.shippingAddress?.street,
|
|
8905
|
+
street_number: checkout.billingAddress ? checkout.billingAddress.number : checkout.shippingAddress?.number,
|
|
8532
8906
|
zipcode: checkout.billingAddress
|
|
8533
8907
|
? checkout.billingAddress.zip.replace('-', '')
|
|
8534
|
-
:
|
|
8908
|
+
: checkout.shippingAddress?.zip.replace('-', ''),
|
|
8535
8909
|
},
|
|
8536
8910
|
},
|
|
8537
8911
|
items: checkout.lineItems.map((item) => {
|
|
@@ -8553,7 +8927,6 @@ class PagarmePixAxiosAdapter {
|
|
|
8553
8927
|
this.paymentRepository = paymentRepository;
|
|
8554
8928
|
}
|
|
8555
8929
|
async pay(checkout) {
|
|
8556
|
-
var _a;
|
|
8557
8930
|
try {
|
|
8558
8931
|
const payload = this.createPixPayment(checkout);
|
|
8559
8932
|
const result = await axios__default["default"]({
|
|
@@ -8577,7 +8950,7 @@ class PagarmePixAxiosAdapter {
|
|
|
8577
8950
|
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
8578
8951
|
checkoutId: checkout.id,
|
|
8579
8952
|
userEmail: checkout.user.email,
|
|
8580
|
-
info:
|
|
8953
|
+
info: error.response?.data,
|
|
8581
8954
|
});
|
|
8582
8955
|
}
|
|
8583
8956
|
}
|
|
@@ -8606,6 +8979,251 @@ class PagarmePixAxiosAdapter {
|
|
|
8606
8979
|
}
|
|
8607
8980
|
}
|
|
8608
8981
|
|
|
8982
|
+
/* eslint-disable no-console */
|
|
8983
|
+
class PagarmeV5BankSlipAxiosAdapter {
|
|
8984
|
+
constructor(credentials, paymentRepository) {
|
|
8985
|
+
this.credentials = credentials;
|
|
8986
|
+
this.paymentRepository = paymentRepository;
|
|
8987
|
+
}
|
|
8988
|
+
async pay(checkout) {
|
|
8989
|
+
try {
|
|
8990
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
|
|
8991
|
+
console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
8992
|
+
const { data } = await axios__default["default"]({
|
|
8993
|
+
method: 'POST',
|
|
8994
|
+
url: `${this.credentials.URL}/orders`,
|
|
8995
|
+
headers: {
|
|
8996
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
8997
|
+
'Content-Type': 'application/json',
|
|
8998
|
+
},
|
|
8999
|
+
data: payload,
|
|
9000
|
+
});
|
|
9001
|
+
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
9002
|
+
if (data.charges.at(0).status !== exports.PagarMeV5OrderStatus['Em processamento'] ||
|
|
9003
|
+
data.charges.at(0).status !== exports.PagarMeV5PaymentStatus['Falha']) {
|
|
9004
|
+
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9005
|
+
checkoutId: checkout.id,
|
|
9006
|
+
userEmail: checkout.user.email,
|
|
9007
|
+
info: data,
|
|
9008
|
+
}));
|
|
9009
|
+
}
|
|
9010
|
+
const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
|
|
9011
|
+
const payment = await this.paymentRepository.create(paymentData);
|
|
9012
|
+
return payment;
|
|
9013
|
+
}
|
|
9014
|
+
catch (error) {
|
|
9015
|
+
console.log(error.response?.data?.errors);
|
|
9016
|
+
console.log(error.response?.data?.request);
|
|
9017
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9018
|
+
checkoutId: checkout.id,
|
|
9019
|
+
userEmail: checkout.user.email,
|
|
9020
|
+
info: error.response.data,
|
|
9021
|
+
});
|
|
9022
|
+
}
|
|
9023
|
+
}
|
|
9024
|
+
async getBoletoTransaction(paymentId) {
|
|
9025
|
+
try {
|
|
9026
|
+
const { data } = await axios__default["default"]({
|
|
9027
|
+
method: 'GET',
|
|
9028
|
+
url: `${this.credentials.URL}/charges/${paymentId}`,
|
|
9029
|
+
headers: {
|
|
9030
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9031
|
+
'Content-Type': 'application/json',
|
|
9032
|
+
},
|
|
9033
|
+
});
|
|
9034
|
+
const payment = await this.paymentRepository.get({
|
|
9035
|
+
id: +data.id,
|
|
9036
|
+
});
|
|
9037
|
+
return payment.transaction;
|
|
9038
|
+
}
|
|
9039
|
+
catch (error) {
|
|
9040
|
+
throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
|
|
9041
|
+
paymentId,
|
|
9042
|
+
info: error.response.data,
|
|
9043
|
+
});
|
|
9044
|
+
}
|
|
9045
|
+
}
|
|
9046
|
+
}
|
|
9047
|
+
|
|
9048
|
+
class PagarmeV5CardAxiosAdapter {
|
|
9049
|
+
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
9050
|
+
this.credentials = credentials;
|
|
9051
|
+
this.paymentRepository = paymentRepository;
|
|
9052
|
+
this.orderBlockedRepository = orderBlockedRepository;
|
|
9053
|
+
}
|
|
9054
|
+
async pay(checkout, card) {
|
|
9055
|
+
try {
|
|
9056
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
|
|
9057
|
+
console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
|
|
9058
|
+
const { data } = await axios__default["default"]({
|
|
9059
|
+
method: 'POST',
|
|
9060
|
+
url: `${this.credentials.URL}/orders`,
|
|
9061
|
+
headers: {
|
|
9062
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9063
|
+
'Content-Type': 'application/json',
|
|
9064
|
+
},
|
|
9065
|
+
data: payload,
|
|
9066
|
+
});
|
|
9067
|
+
console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
|
|
9068
|
+
if (data.charges.at(0).status !== exports.PagarMeV5PaymentStatus.Pago ||
|
|
9069
|
+
data.charges.at(0).status !== exports.PagarMeV5PaymentStatus.Capturada) {
|
|
9070
|
+
await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
|
|
9071
|
+
checkout,
|
|
9072
|
+
card,
|
|
9073
|
+
orderBlockedRepository: this.orderBlockedRepository,
|
|
9074
|
+
});
|
|
9075
|
+
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
|
|
9076
|
+
}
|
|
9077
|
+
const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
|
|
9078
|
+
const payment = await this.paymentRepository.create(paymentData);
|
|
9079
|
+
return payment;
|
|
9080
|
+
}
|
|
9081
|
+
catch (error) {
|
|
9082
|
+
if (error instanceof PaymentError) {
|
|
9083
|
+
throw error;
|
|
9084
|
+
}
|
|
9085
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9086
|
+
}
|
|
9087
|
+
}
|
|
9088
|
+
// Dúvidas: preciso criar um cliente? como faz na mens?
|
|
9089
|
+
async addCard(card) {
|
|
9090
|
+
try {
|
|
9091
|
+
const { data } = await axios__default["default"]({
|
|
9092
|
+
method: 'POST',
|
|
9093
|
+
url: `${this.credentials.URL}/cards`,
|
|
9094
|
+
data: {
|
|
9095
|
+
api_key: this.credentials.API_KEY,
|
|
9096
|
+
card_number: card.number,
|
|
9097
|
+
card_expiration_date: card.expirationDate.replace('/', ''),
|
|
9098
|
+
card_holder_name: card.name,
|
|
9099
|
+
card_cvv: card.cvv,
|
|
9100
|
+
// number: '4000000000000010',
|
|
9101
|
+
// holder_name: 'Tony Stark',
|
|
9102
|
+
// holder_document: '93095135270',
|
|
9103
|
+
// exp_month: 1,
|
|
9104
|
+
// exp_year: 30,
|
|
9105
|
+
// cvv: '351',
|
|
9106
|
+
// brand: 'Mastercard',
|
|
9107
|
+
// label: 'Sua bandeira',
|
|
9108
|
+
// billing_address: {
|
|
9109
|
+
// line_1: '375, Av. General Osorio, Centro',
|
|
9110
|
+
// line_2: '7º Andar',
|
|
9111
|
+
// zip_code: '220000111',
|
|
9112
|
+
// city: 'Rio de Janeiro',
|
|
9113
|
+
// state: 'RJ',
|
|
9114
|
+
// country: 'BR',
|
|
9115
|
+
// },
|
|
9116
|
+
// options: {
|
|
9117
|
+
// verify_card: true,
|
|
9118
|
+
// },
|
|
9119
|
+
},
|
|
9120
|
+
});
|
|
9121
|
+
return data;
|
|
9122
|
+
}
|
|
9123
|
+
catch (error) {
|
|
9124
|
+
throw new BusinessError('Houve uma falha adicionar o cartão', {
|
|
9125
|
+
info: error.response.data,
|
|
9126
|
+
});
|
|
9127
|
+
}
|
|
9128
|
+
}
|
|
9129
|
+
async createCardHash(bu) {
|
|
9130
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
|
|
9131
|
+
try {
|
|
9132
|
+
const { data } = await axios__default["default"]({
|
|
9133
|
+
method: 'GET',
|
|
9134
|
+
headers: {
|
|
9135
|
+
'content-type': 'application/json',
|
|
9136
|
+
},
|
|
9137
|
+
url: `${this.credentials.URL}/transactions/card_hash_key`,
|
|
9138
|
+
data: JSON.stringify({
|
|
9139
|
+
api_key: key,
|
|
9140
|
+
}),
|
|
9141
|
+
});
|
|
9142
|
+
return data;
|
|
9143
|
+
}
|
|
9144
|
+
catch (error) {
|
|
9145
|
+
throw new BusinessError('Houve uma falha gerar o hash', {
|
|
9146
|
+
info: error.response.data,
|
|
9147
|
+
});
|
|
9148
|
+
}
|
|
9149
|
+
}
|
|
9150
|
+
async getCardByToken(id) {
|
|
9151
|
+
try {
|
|
9152
|
+
const { data } = await axios__default["default"]({
|
|
9153
|
+
method: 'POST',
|
|
9154
|
+
url: `${this.credentials.URL}/cards/${id}`,
|
|
9155
|
+
data: {
|
|
9156
|
+
api_key: this.credentials.API_KEY,
|
|
9157
|
+
},
|
|
9158
|
+
});
|
|
9159
|
+
return data;
|
|
9160
|
+
}
|
|
9161
|
+
catch (error) {
|
|
9162
|
+
throw new BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
|
|
9163
|
+
info: error.response.data,
|
|
9164
|
+
});
|
|
9165
|
+
}
|
|
9166
|
+
}
|
|
9167
|
+
async createTransaction(info) {
|
|
9168
|
+
try {
|
|
9169
|
+
const { data } = await axios__default["default"]({
|
|
9170
|
+
method: 'POST',
|
|
9171
|
+
url: `${this.credentials.URL}/transactions`,
|
|
9172
|
+
headers: {
|
|
9173
|
+
Authorization: 'Basic ' + Buffer.from(this.credentials.API_KEY).toString('base64'),
|
|
9174
|
+
'Content-Type': 'application/json',
|
|
9175
|
+
},
|
|
9176
|
+
data: {
|
|
9177
|
+
...info,
|
|
9178
|
+
api_key: this.credentials.API_KEY,
|
|
9179
|
+
},
|
|
9180
|
+
});
|
|
9181
|
+
return data;
|
|
9182
|
+
}
|
|
9183
|
+
catch (error) {
|
|
9184
|
+
throw new BusinessError('Houve uma falha ao criar a transação', {
|
|
9185
|
+
info: error.response.data,
|
|
9186
|
+
});
|
|
9187
|
+
}
|
|
9188
|
+
}
|
|
9189
|
+
}
|
|
9190
|
+
|
|
9191
|
+
/* eslint-disable no-console */
|
|
9192
|
+
class PagarmeV5PixAxiosAdapter {
|
|
9193
|
+
constructor(credentials, paymentRepository) {
|
|
9194
|
+
this.credentials = credentials;
|
|
9195
|
+
this.paymentRepository = paymentRepository;
|
|
9196
|
+
}
|
|
9197
|
+
async pay(checkout) {
|
|
9198
|
+
try {
|
|
9199
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
|
|
9200
|
+
console.warn('[PAGARME PIX DATA TO SEND]', payload);
|
|
9201
|
+
const { data } = await axios__default["default"]({
|
|
9202
|
+
method: 'POST',
|
|
9203
|
+
url: `${this.credentials.URL}/orders`,
|
|
9204
|
+
headers: {
|
|
9205
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9206
|
+
'Content-Type': 'application/json',
|
|
9207
|
+
},
|
|
9208
|
+
data: payload,
|
|
9209
|
+
});
|
|
9210
|
+
console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
|
|
9211
|
+
const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
|
|
9212
|
+
const payment = await this.paymentRepository.create(paymentData);
|
|
9213
|
+
return payment;
|
|
9214
|
+
}
|
|
9215
|
+
catch (error) {
|
|
9216
|
+
console.log(error.response?.data?.errors);
|
|
9217
|
+
console.log(error.response?.data?.request);
|
|
9218
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9219
|
+
checkoutId: checkout.id,
|
|
9220
|
+
userEmail: checkout.user.email,
|
|
9221
|
+
info: error.response?.data,
|
|
9222
|
+
});
|
|
9223
|
+
}
|
|
9224
|
+
}
|
|
9225
|
+
}
|
|
9226
|
+
|
|
8609
9227
|
class VertexAxiosAdapter {
|
|
8610
9228
|
constructor(config) {
|
|
8611
9229
|
this.config = config;
|
|
@@ -8962,6 +9580,9 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
|
|
|
8962
9580
|
exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
|
|
8963
9581
|
exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
|
|
8964
9582
|
exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
|
|
9583
|
+
exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
|
|
9584
|
+
exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
|
|
9585
|
+
exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
|
|
8965
9586
|
exports.Payment = Payment;
|
|
8966
9587
|
exports.PaymentError = PaymentError;
|
|
8967
9588
|
exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|