@infrab4a/connect 5.0.0-alpha.10 → 5.0.0-alpha.11
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 +689 -508
- package/index.esm.js +690 -509
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -216,7 +216,7 @@ class ReflectHelper {
|
|
|
216
216
|
return Reflect.getMetadata(key, target, property) || null;
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
catch
|
|
219
|
+
catch {
|
|
220
220
|
return null;
|
|
221
221
|
}
|
|
222
222
|
}
|
|
@@ -526,7 +526,7 @@ function Debug(opts) {
|
|
|
526
526
|
|
|
527
527
|
const ASYNC_IDENTIFIER = 'async';
|
|
528
528
|
function Log(options = {}) {
|
|
529
|
-
return Trace(
|
|
529
|
+
return Trace({ level: 'log', ...options });
|
|
530
530
|
}
|
|
531
531
|
function Trace(options = {}) {
|
|
532
532
|
return function (target, propertyKey, propertyDescriptor) {
|
|
@@ -626,7 +626,7 @@ class BaseModel {
|
|
|
626
626
|
get identifier() {
|
|
627
627
|
const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
|
|
628
628
|
const data = this;
|
|
629
|
-
return fields.reduce((object, field) => (
|
|
629
|
+
return fields.reduce((object, field) => ({ ...object, [field]: data[field] }), {});
|
|
630
630
|
}
|
|
631
631
|
get identifiersFields() {
|
|
632
632
|
return this.constructor.identifiersFields;
|
|
@@ -691,8 +691,7 @@ class Category extends BaseModel {
|
|
|
691
691
|
return ['id'];
|
|
692
692
|
}
|
|
693
693
|
get glamImages() {
|
|
694
|
-
|
|
695
|
-
return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[exports.Shops.GLAMSHOP])
|
|
694
|
+
return this.images?.[exports.Shops.GLAMSHOP]
|
|
696
695
|
? this.images[exports.Shops.GLAMSHOP]
|
|
697
696
|
: {
|
|
698
697
|
brandBanner: null,
|
|
@@ -701,8 +700,7 @@ class Category extends BaseModel {
|
|
|
701
700
|
};
|
|
702
701
|
}
|
|
703
702
|
get mensImages() {
|
|
704
|
-
|
|
705
|
-
return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[exports.Shops.MENSMARKET])
|
|
703
|
+
return this.images?.[exports.Shops.MENSMARKET]
|
|
706
704
|
? this.images[exports.Shops.MENSMARKET]
|
|
707
705
|
: {
|
|
708
706
|
brandBanner: null,
|
|
@@ -717,8 +715,7 @@ class Category extends BaseModel {
|
|
|
717
715
|
return this.metadatas.find((metadata) => metadata.shop === exports.Shops.MENSMARKET);
|
|
718
716
|
}
|
|
719
717
|
getMostRelevantByShop(shop) {
|
|
720
|
-
|
|
721
|
-
return ((_a = this.mostRelevants) === null || _a === void 0 ? void 0 : _a[shop]) || [];
|
|
718
|
+
return this.mostRelevants?.[shop] || [];
|
|
722
719
|
}
|
|
723
720
|
}
|
|
724
721
|
tslib.__decorate([
|
|
@@ -1451,10 +1448,18 @@ class Authentication {
|
|
|
1451
1448
|
return signInMethod === exports.SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
|
|
1452
1449
|
}
|
|
1453
1450
|
async createsUserByCredential(user) {
|
|
1454
|
-
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1457
|
-
|
|
1451
|
+
const [firstName, lastName] = user.displayName?.split(/\s/) ?? [];
|
|
1452
|
+
const person = User.toInstance({
|
|
1453
|
+
...user,
|
|
1454
|
+
cpf: '',
|
|
1455
|
+
birthday: new Date(),
|
|
1456
|
+
firstName,
|
|
1457
|
+
lastName,
|
|
1458
|
+
acceptsNewsletter: false,
|
|
1459
|
+
area: exports.Area.Transactional,
|
|
1460
|
+
officePosition: exports.OfficePosition.Intern,
|
|
1461
|
+
type: exports.UserType.Collaborator,
|
|
1462
|
+
});
|
|
1458
1463
|
return this.userRepository.create(person);
|
|
1459
1464
|
}
|
|
1460
1465
|
}
|
|
@@ -1503,8 +1508,15 @@ class Register {
|
|
|
1503
1508
|
password: params.password,
|
|
1504
1509
|
});
|
|
1505
1510
|
delete params.password;
|
|
1506
|
-
const user = await this.userRepository.create(
|
|
1507
|
-
|
|
1511
|
+
const user = await this.userRepository.create({
|
|
1512
|
+
...params,
|
|
1513
|
+
id: auth.id,
|
|
1514
|
+
email,
|
|
1515
|
+
displayName,
|
|
1516
|
+
type: exports.UserType.B2C,
|
|
1517
|
+
dateCreated: new Date(),
|
|
1518
|
+
dateModified: new Date(),
|
|
1519
|
+
});
|
|
1508
1520
|
return user;
|
|
1509
1521
|
}
|
|
1510
1522
|
}
|
|
@@ -1698,8 +1710,7 @@ class AntifraudBankSlipService {
|
|
|
1698
1710
|
this.MAX_ORDER_VALUE = 5000;
|
|
1699
1711
|
}
|
|
1700
1712
|
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)) {
|
|
1713
|
+
if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !checkout.user?.isSubscriber) {
|
|
1703
1714
|
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
1704
1715
|
checkout,
|
|
1705
1716
|
blockType: 'Boleto not authorized',
|
|
@@ -1710,7 +1721,7 @@ class AntifraudBankSlipService {
|
|
|
1710
1721
|
checkoutId: checkout.id,
|
|
1711
1722
|
userEmail: checkout.user.email,
|
|
1712
1723
|
info: {
|
|
1713
|
-
isSubscriber:
|
|
1724
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1714
1725
|
subtotal: checkout.subTotalPrice,
|
|
1715
1726
|
total: checkout.totalPrice,
|
|
1716
1727
|
},
|
|
@@ -1734,14 +1745,13 @@ class AntifraudCardService {
|
|
|
1734
1745
|
return true;
|
|
1735
1746
|
}
|
|
1736
1747
|
async validateBlockedOrderAttempts(checkout, card) {
|
|
1737
|
-
var _a;
|
|
1738
1748
|
const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
|
|
1739
1749
|
if (!isValid) {
|
|
1740
1750
|
throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
|
|
1741
1751
|
checkoutId: checkout.id,
|
|
1742
1752
|
userEmail: checkout.user.email,
|
|
1743
1753
|
info: {
|
|
1744
|
-
isSubscriber:
|
|
1754
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1745
1755
|
subtotal: checkout.subTotalPrice,
|
|
1746
1756
|
total: checkout.totalPrice,
|
|
1747
1757
|
},
|
|
@@ -1749,14 +1759,13 @@ class AntifraudCardService {
|
|
|
1749
1759
|
}
|
|
1750
1760
|
}
|
|
1751
1761
|
async validateDayAndWeekOrderLimits(checkout, card) {
|
|
1752
|
-
var _a;
|
|
1753
1762
|
const isValid = await this.verifyDayAndWeekOrders(checkout, card);
|
|
1754
1763
|
if (!isValid) {
|
|
1755
1764
|
throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
|
|
1756
1765
|
checkoutId: checkout.id,
|
|
1757
1766
|
userEmail: checkout.user.email,
|
|
1758
1767
|
info: {
|
|
1759
|
-
isSubscriber:
|
|
1768
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1760
1769
|
subtotal: checkout.subTotalPrice,
|
|
1761
1770
|
total: checkout.totalPrice,
|
|
1762
1771
|
},
|
|
@@ -1785,17 +1794,16 @@ class AntifraudCardService {
|
|
|
1785
1794
|
return { day, endOfDay };
|
|
1786
1795
|
}
|
|
1787
1796
|
async getBlockedOrdersByMultipleCriteria(checkout, dateRange) {
|
|
1788
|
-
var _a, _b, _c, _d;
|
|
1789
1797
|
const { day, endOfDay } = dateRange;
|
|
1790
1798
|
const dateFilter = [
|
|
1791
1799
|
{ operator: exports.Where.GTE, value: new Date(day) },
|
|
1792
1800
|
{ operator: exports.Where.LTE, value: new Date(endOfDay) },
|
|
1793
1801
|
];
|
|
1794
1802
|
const [ordersBlockedWithCpf, ordersBlockedWithEmail, ordersBlockedWithCep, ordersBlockedWithPhone] = await Promise.all([
|
|
1795
|
-
this.getBlockedOrdersByCpf(
|
|
1796
|
-
this.getBlockedOrdersByEmail(
|
|
1797
|
-
this.getBlockedOrdersByZip(
|
|
1798
|
-
this.getBlockedOrdersByPhone(
|
|
1803
|
+
this.getBlockedOrdersByCpf(checkout.user?.cpf, dateFilter),
|
|
1804
|
+
this.getBlockedOrdersByEmail(checkout.user?.email, dateFilter),
|
|
1805
|
+
this.getBlockedOrdersByZip(checkout.shippingAddress?.zip, dateFilter),
|
|
1806
|
+
this.getBlockedOrdersByPhone(checkout.user?.phone, dateFilter),
|
|
1799
1807
|
]);
|
|
1800
1808
|
return {
|
|
1801
1809
|
ordersBlockedWithCpf,
|
|
@@ -1852,18 +1860,15 @@ class AntifraudCardService {
|
|
|
1852
1860
|
return ordersBlockedWithCpf.concat(blockedUniqueEmails).concat(blockedUniqueCeps).concat(blockedUniquePhone).length;
|
|
1853
1861
|
}
|
|
1854
1862
|
filterUniqueEmailBlocked(ordersBlockedWithEmail, checkout) {
|
|
1855
|
-
return ordersBlockedWithEmail.filter((e) =>
|
|
1863
|
+
return ordersBlockedWithEmail.filter((e) => e.customer.cpf !== checkout.user?.cpf);
|
|
1856
1864
|
}
|
|
1857
1865
|
filterUniqueZipBlocked(ordersBlockedWithCep, checkout) {
|
|
1858
|
-
return ordersBlockedWithCep.filter((e) =>
|
|
1866
|
+
return ordersBlockedWithCep.filter((e) => e.customer.cpf !== checkout.user?.cpf && e.customer.email !== checkout.user?.email);
|
|
1859
1867
|
}
|
|
1860
1868
|
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
|
-
});
|
|
1869
|
+
return ordersBlockedWithPhone.filter((e) => e.customer.cpf !== checkout.user?.cpf &&
|
|
1870
|
+
e.customer.email !== checkout.user?.email &&
|
|
1871
|
+
e.customer.shippingAddress?.zip?.toString() !== checkout.shippingAddress?.zip?.toString());
|
|
1867
1872
|
}
|
|
1868
1873
|
async createBlockedOrderRecord(params) {
|
|
1869
1874
|
const { checkout, card, reason, key, period } = params;
|
|
@@ -1884,12 +1889,11 @@ class AntifraudCardService {
|
|
|
1884
1889
|
return isWeekLimitValid;
|
|
1885
1890
|
}
|
|
1886
1891
|
buildValidationParams(checkout, card) {
|
|
1887
|
-
var _a, _b, _c, _d;
|
|
1888
1892
|
return {
|
|
1889
|
-
cpf:
|
|
1890
|
-
email:
|
|
1891
|
-
phone:
|
|
1892
|
-
zip:
|
|
1893
|
+
cpf: checkout.user?.cpf,
|
|
1894
|
+
email: checkout.user?.email,
|
|
1895
|
+
phone: checkout.user?.phone,
|
|
1896
|
+
zip: checkout.shippingAddress?.zip,
|
|
1893
1897
|
card,
|
|
1894
1898
|
};
|
|
1895
1899
|
}
|
|
@@ -2025,10 +2029,9 @@ class GlampointsPaymentService {
|
|
|
2025
2029
|
return payment;
|
|
2026
2030
|
}
|
|
2027
2031
|
async rewardByOrder(order, user) {
|
|
2028
|
-
var _a;
|
|
2029
2032
|
try {
|
|
2030
2033
|
const points = order.lineItems.filter((item) => !item.isGift).reduce((acc, li) => acc + li.quantity, 0);
|
|
2031
|
-
const hasGlambeauty =
|
|
2034
|
+
const hasGlambeauty = order.lineItems?.some((doc) => doc.brand && doc.brand.toUpperCase() === 'GLAM BEAUTY');
|
|
2032
2035
|
const result = await axios__default["default"]({
|
|
2033
2036
|
method: 'POST',
|
|
2034
2037
|
url: `${this.glamCredentials.baseUrl}/integration/win/reward`,
|
|
@@ -2289,7 +2292,7 @@ class AdyenPaymentFactoryHelper {
|
|
|
2289
2292
|
checkoutId: checkout.id,
|
|
2290
2293
|
totalPrice: checkout.totalPrice,
|
|
2291
2294
|
paymentProvider: 'adyen',
|
|
2292
|
-
transaction:
|
|
2295
|
+
transaction: { ...adyenResponse, status: 'paid' },
|
|
2293
2296
|
});
|
|
2294
2297
|
return paymentRepository.create(paymentData);
|
|
2295
2298
|
}
|
|
@@ -2300,7 +2303,7 @@ class AdyenPaymentOperationsHelper {
|
|
|
2300
2303
|
return {
|
|
2301
2304
|
amount: {
|
|
2302
2305
|
currency: 'BRL',
|
|
2303
|
-
value: (
|
|
2306
|
+
value: (checkout?.totalPrice || 0) * 100,
|
|
2304
2307
|
},
|
|
2305
2308
|
paymentMethod: {
|
|
2306
2309
|
type: 'scheme',
|
|
@@ -2385,7 +2388,11 @@ class RestCacheAdapter {
|
|
|
2385
2388
|
this.logger = new DebugHelper('RestCacheAdapter');
|
|
2386
2389
|
this.client = axios__default["default"].create({
|
|
2387
2390
|
baseURL: config.baseURL,
|
|
2388
|
-
headers:
|
|
2391
|
+
headers: {
|
|
2392
|
+
'Content-Type': 'application/json',
|
|
2393
|
+
...(lodash.isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` }),
|
|
2394
|
+
...(lodash.isNil(config.mobileApiKey) ? {} : { 'X-Mobile-API-Key': config.mobileApiKey }),
|
|
2395
|
+
},
|
|
2389
2396
|
});
|
|
2390
2397
|
}
|
|
2391
2398
|
async set(options) {
|
|
@@ -2641,7 +2648,10 @@ class ElasticSearchResultProcessorHelper {
|
|
|
2641
2648
|
});
|
|
2642
2649
|
}
|
|
2643
2650
|
static transformHitsToProducts(hits) {
|
|
2644
|
-
return hits.map((hit) => (
|
|
2651
|
+
return hits.map((hit) => ({
|
|
2652
|
+
...hit._source,
|
|
2653
|
+
stock: hit._source.stock.quantity,
|
|
2654
|
+
}));
|
|
2645
2655
|
}
|
|
2646
2656
|
}
|
|
2647
2657
|
|
|
@@ -2784,11 +2794,11 @@ class FirestoreDataConverterHelper {
|
|
|
2784
2794
|
return (data &&
|
|
2785
2795
|
!Array.isArray(data) &&
|
|
2786
2796
|
typeof data === 'object' &&
|
|
2787
|
-
|
|
2797
|
+
data?.constructor.name !== 'Timestamp' &&
|
|
2788
2798
|
!('seconds' in data));
|
|
2789
2799
|
}
|
|
2790
2800
|
static convertToDate(data, keyName) {
|
|
2791
|
-
if (
|
|
2801
|
+
if (data?.constructor.name === 'Timestamp')
|
|
2792
2802
|
return data.toDate();
|
|
2793
2803
|
if (data && typeof data === 'object' && 'seconds' in data)
|
|
2794
2804
|
return new Date(data.seconds * 1000);
|
|
@@ -2833,7 +2843,7 @@ class FirestoreModelConverterHelper {
|
|
|
2833
2843
|
}
|
|
2834
2844
|
buildToFirestoreConverter() {
|
|
2835
2845
|
return (data) => {
|
|
2836
|
-
const plain =
|
|
2846
|
+
const plain = data?.toPlain ? data.toPlain() : data;
|
|
2837
2847
|
return FirestoreModelConverterHelper.omitByRecursivelyInPlace(plain, (value) => value === undefined);
|
|
2838
2848
|
};
|
|
2839
2849
|
}
|
|
@@ -2843,7 +2853,7 @@ class FirestoreModelConverterHelper {
|
|
|
2843
2853
|
const data = snap.data();
|
|
2844
2854
|
const ids = { id: snap.id };
|
|
2845
2855
|
const bindedData = FirestoreDataConverterHelper.bindAllDateFromObject(data);
|
|
2846
|
-
return this.model.toInstance(
|
|
2856
|
+
return this.model.toInstance({ ...bindedData, ...ids });
|
|
2847
2857
|
}
|
|
2848
2858
|
catch (error) {
|
|
2849
2859
|
this.handleConversionError(snap.id, snap.data(), error);
|
|
@@ -2911,18 +2921,17 @@ const withHelpers = (MixinBase) => {
|
|
|
2911
2921
|
class AttributeOptionHelper {
|
|
2912
2922
|
}
|
|
2913
2923
|
AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
2914
|
-
var _a;
|
|
2915
2924
|
if (fields.includes(attributeName))
|
|
2916
2925
|
return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
|
|
2917
2926
|
const field = fields.find((columnOption) => lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
2918
|
-
const fieldOption =
|
|
2927
|
+
const fieldOption = is(field)?.[attributeName];
|
|
2919
2928
|
if (lodash.isNil(fieldOption))
|
|
2920
2929
|
return { columnName: attributeName.toString(), attributeName };
|
|
2921
2930
|
if (Array.isArray(fieldOption))
|
|
2922
2931
|
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
2923
|
-
return
|
|
2932
|
+
return { attributeName, columnName: attributeName.toString(), ...fieldOption };
|
|
2924
2933
|
};
|
|
2925
|
-
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!
|
|
2934
|
+
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
|
|
2926
2935
|
AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
2927
2936
|
if (fields.includes(columnName))
|
|
2928
2937
|
return { columnName, attributeName: columnName };
|
|
@@ -2930,13 +2939,17 @@ AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
|
2930
2939
|
if (!lodash.isObject(field))
|
|
2931
2940
|
return false;
|
|
2932
2941
|
const columnOption = Object.values(field).find((option) => AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName ? option : {});
|
|
2933
|
-
return AttributeOptionHelper.CheckIsColumnOption(columnOption) &&
|
|
2942
|
+
return AttributeOptionHelper.CheckIsColumnOption(columnOption) && columnOption?.columnName === columnName;
|
|
2934
2943
|
}) || {});
|
|
2935
2944
|
const attributeName = Object.keys(field).find((fieldOptionFromList) => AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) || Array.isArray(field[fieldOptionFromList]));
|
|
2936
|
-
const fieldOption = field
|
|
2945
|
+
const fieldOption = field?.[attributeName];
|
|
2937
2946
|
if (Array.isArray(fieldOption))
|
|
2938
2947
|
return { attributeName: attributeName, fields: fieldOption };
|
|
2939
|
-
return
|
|
2948
|
+
return {
|
|
2949
|
+
attributeName: attributeName || columnName,
|
|
2950
|
+
columnName,
|
|
2951
|
+
...fieldOption,
|
|
2952
|
+
};
|
|
2940
2953
|
};
|
|
2941
2954
|
|
|
2942
2955
|
var HasuraGraphQLWhere;
|
|
@@ -2974,7 +2987,7 @@ var HasuraGraphQLColumnType;
|
|
|
2974
2987
|
|
|
2975
2988
|
class FilterOptionHelper {
|
|
2976
2989
|
}
|
|
2977
|
-
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !lodash.isNil(filter
|
|
2990
|
+
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !lodash.isNil(filter?.operator);
|
|
2978
2991
|
FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
|
|
2979
2992
|
if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
|
|
2980
2993
|
return filter;
|
|
@@ -3035,25 +3048,37 @@ class BindFilterQueryHelper {
|
|
|
3035
3048
|
BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => {
|
|
3036
3049
|
const columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
|
|
3037
3050
|
if (!columnOption.bindFindFilter)
|
|
3038
|
-
return
|
|
3039
|
-
|
|
3040
|
-
|
|
3051
|
+
return {
|
|
3052
|
+
...variables,
|
|
3053
|
+
...{
|
|
3054
|
+
[columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
|
|
3055
|
+
},
|
|
3056
|
+
};
|
|
3041
3057
|
const builtFilter = columnOption.bindFindFilter(filter[fieldName]);
|
|
3042
|
-
return
|
|
3058
|
+
return {
|
|
3059
|
+
...variables,
|
|
3060
|
+
...Object.keys(builtFilter).reduce((variablesList, columnName) => ({
|
|
3061
|
+
...variablesList,
|
|
3062
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields),
|
|
3063
|
+
}), {}),
|
|
3064
|
+
};
|
|
3043
3065
|
}, {});
|
|
3044
3066
|
BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
3045
3067
|
const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
3046
3068
|
const isNestedField = !Array.isArray(options) &&
|
|
3047
3069
|
lodash.isObject(options) &&
|
|
3048
|
-
lodash.isNil(options
|
|
3049
|
-
lodash.isNil(options
|
|
3050
|
-
lodash.isNil(fieldSentenceOptions
|
|
3070
|
+
lodash.isNil(options?.operator) &&
|
|
3071
|
+
lodash.isNil(options?.value) &&
|
|
3072
|
+
lodash.isNil(fieldSentenceOptions?.to);
|
|
3051
3073
|
if (isNestedField)
|
|
3052
3074
|
return Object.keys(options).reduce((variables, key) => {
|
|
3053
|
-
const fieldOptions = AttributeOptionHelper.FindByAttribute(key,
|
|
3075
|
+
const fieldOptions = AttributeOptionHelper.FindByAttribute(key, fieldSentenceOptions?.fields || fields);
|
|
3054
3076
|
const columnName = fieldOptions.columnName;
|
|
3055
3077
|
const columnFields = fieldOptions.fields;
|
|
3056
|
-
return
|
|
3078
|
+
return {
|
|
3079
|
+
...variables,
|
|
3080
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), fieldSentenceOptions?.fields || columnFields || fields),
|
|
3081
|
+
};
|
|
3057
3082
|
}, {});
|
|
3058
3083
|
if (!Array.isArray(options) && !lodash.isNil(fieldSentenceOptions.fields))
|
|
3059
3084
|
return {
|
|
@@ -3062,7 +3087,10 @@ BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
|
3062
3087
|
if (!Array.isArray(options) && lodash.isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
3063
3088
|
options = Object.values(options)[0];
|
|
3064
3089
|
return Array.isArray(options)
|
|
3065
|
-
? options.reduce((whereSentence, option) => (
|
|
3090
|
+
? options.reduce((whereSentence, option) => ({
|
|
3091
|
+
...whereSentence,
|
|
3092
|
+
...BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions),
|
|
3093
|
+
}), {})
|
|
3066
3094
|
: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions);
|
|
3067
3095
|
};
|
|
3068
3096
|
BindFilterQueryHelper.BuildOperatorSentence = (options, fieldOption) => ({
|
|
@@ -3078,14 +3106,14 @@ BindFilterQueryHelper.GetHasuraOperator = (options, fieldOption) => FilterOption
|
|
|
3078
3106
|
: options.operator === exports.Where.LIKE && options.ignoreCase
|
|
3079
3107
|
? HasuraGraphQLWhere.ILIKE
|
|
3080
3108
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3081
|
-
Object.keys(exports.Where).find((operator) => exports.Where[operator] ===
|
|
3109
|
+
Object.keys(exports.Where).find((operator) => exports.Where[operator] === options?.operator))]
|
|
3082
3110
|
: HasuraGraphQLWhere.EQUALS;
|
|
3083
3111
|
BindFilterQueryHelper.GetHasuraJsonbOperator = (options) => options.operator === exports.Where.IN
|
|
3084
3112
|
? HasuraGraphQLWhere.JSON_CONTAINS
|
|
3085
3113
|
: options.operator === exports.Where.LIKE
|
|
3086
3114
|
? HasuraGraphQLWhere.JSON_HAS_KEYS_ANY
|
|
3087
3115
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3088
|
-
Object.keys(exports.Where).find((operator) => exports.Where[operator] ===
|
|
3116
|
+
Object.keys(exports.Where).find((operator) => exports.Where[operator] === options?.operator))];
|
|
3089
3117
|
|
|
3090
3118
|
class CacheKeyGeneratorHelper {
|
|
3091
3119
|
static generateCacheKeyFromIdentifiers(modelOrModelName, identifiers) {
|
|
@@ -3100,7 +3128,8 @@ class GraphQLFieldHelper {
|
|
|
3100
3128
|
}
|
|
3101
3129
|
GraphQLFieldHelper.CheckIsGraphQLParams = (params) => !lodash.isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
|
|
3102
3130
|
GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
3103
|
-
return fields
|
|
3131
|
+
return fields
|
|
3132
|
+
?.map((field) => {
|
|
3104
3133
|
if (lodash.isString(field))
|
|
3105
3134
|
return field.toString();
|
|
3106
3135
|
if (field === 'affected_rows')
|
|
@@ -3115,41 +3144,55 @@ GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
|
3115
3144
|
if (isNestedField)
|
|
3116
3145
|
return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
|
|
3117
3146
|
return fieldValue.columnName;
|
|
3118
|
-
})
|
|
3147
|
+
})
|
|
3148
|
+
.filter((field) => !!field);
|
|
3119
3149
|
};
|
|
3120
3150
|
GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
|
|
3121
3151
|
const { attributeName, fields: attributeFields, from, } = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields);
|
|
3122
3152
|
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
3123
3153
|
if (Array.isArray(data[columnName]))
|
|
3124
|
-
return
|
|
3154
|
+
return {
|
|
3155
|
+
...result,
|
|
3156
|
+
[attributeName]: from
|
|
3125
3157
|
? from(data[columnName], data)
|
|
3126
|
-
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields))
|
|
3158
|
+
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)),
|
|
3159
|
+
};
|
|
3127
3160
|
if (lodash.isObject(data[columnName]))
|
|
3128
|
-
return
|
|
3161
|
+
return {
|
|
3162
|
+
...result,
|
|
3163
|
+
[attributeName]: from
|
|
3129
3164
|
? from(data[columnName])
|
|
3130
|
-
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields)
|
|
3165
|
+
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields),
|
|
3166
|
+
};
|
|
3131
3167
|
}
|
|
3132
3168
|
if (from)
|
|
3133
|
-
return
|
|
3134
|
-
return
|
|
3169
|
+
return { ...result, [attributeName]: from(data[columnName], data) };
|
|
3170
|
+
return {
|
|
3171
|
+
...result,
|
|
3172
|
+
[attributeName]: lodash.isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName],
|
|
3173
|
+
};
|
|
3135
3174
|
}, {});
|
|
3136
3175
|
GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
3137
|
-
|
|
3138
|
-
const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
3176
|
+
const data = instance.toPlain?.() || instance;
|
|
3139
3177
|
return Object.keys(data).reduce((result, attributeName) => {
|
|
3140
3178
|
const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
|
|
3141
3179
|
if (bindPersistData)
|
|
3142
|
-
return
|
|
3180
|
+
return {
|
|
3181
|
+
...result,
|
|
3182
|
+
...bindPersistData(data[attributeName], instance),
|
|
3183
|
+
};
|
|
3143
3184
|
if (lodash.isNil(columnName))
|
|
3144
3185
|
return result;
|
|
3145
3186
|
if (!!foreignKeyColumn &&
|
|
3146
3187
|
!lodash.isEmpty(foreignKeyColumn) &&
|
|
3147
|
-
!Object.keys(foreignKeyColumn).filter((key) =>
|
|
3188
|
+
!Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
|
|
3148
3189
|
return Object.keys(foreignKeyColumn).reduce((object, current) => {
|
|
3149
|
-
var _a;
|
|
3150
3190
|
const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
|
|
3151
|
-
return
|
|
3152
|
-
|
|
3191
|
+
return {
|
|
3192
|
+
...object,
|
|
3193
|
+
[foreignColumnName]: data[attributeName]?.[current],
|
|
3194
|
+
};
|
|
3195
|
+
}, { ...result });
|
|
3153
3196
|
if (update &&
|
|
3154
3197
|
lodash.isObject(data[attributeName]) &&
|
|
3155
3198
|
!lodash.isNil(attributeFields) &&
|
|
@@ -3161,19 +3204,25 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
3161
3204
|
const converted = !lodash.isNil(columnName) && to
|
|
3162
3205
|
? to(instance[attributeName], instance)
|
|
3163
3206
|
: data[attributeName];
|
|
3164
|
-
return
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
:
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3207
|
+
return {
|
|
3208
|
+
...result,
|
|
3209
|
+
...(converted !== undefined
|
|
3210
|
+
? {
|
|
3211
|
+
[columnName]: {
|
|
3212
|
+
data: instance[attributeName] instanceof BaseModel
|
|
3213
|
+
? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
|
|
3214
|
+
: converted,
|
|
3215
|
+
},
|
|
3216
|
+
}
|
|
3217
|
+
: {}),
|
|
3218
|
+
};
|
|
3173
3219
|
}
|
|
3174
3220
|
if (to)
|
|
3175
|
-
return
|
|
3176
|
-
|
|
3221
|
+
return {
|
|
3222
|
+
...result,
|
|
3223
|
+
[columnName]: to(instance[attributeName], instance),
|
|
3224
|
+
};
|
|
3225
|
+
return { ...result, [columnName]: data[attributeName] };
|
|
3177
3226
|
}, {});
|
|
3178
3227
|
};
|
|
3179
3228
|
GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
|
|
@@ -3231,13 +3280,17 @@ class MD5GeneratorHelper {
|
|
|
3231
3280
|
|
|
3232
3281
|
class HasuraAuthHelper {
|
|
3233
3282
|
static buildHeaders(authOptions) {
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
? {}
|
|
3237
|
-
: {
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3283
|
+
return {
|
|
3284
|
+
'Content-Type': 'application/json',
|
|
3285
|
+
...(lodash.isNil(authOptions?.authToken) ? {} : { Authorization: authOptions?.authToken }),
|
|
3286
|
+
...(lodash.isNil(authOptions?.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': authOptions?.adminSecret }),
|
|
3287
|
+
...(lodash.isNil(authOptions?.authRole)
|
|
3288
|
+
? {}
|
|
3289
|
+
: {
|
|
3290
|
+
'X-Hasura-Role': authOptions.authRole.role,
|
|
3291
|
+
'X-Hasura-User-Id': authOptions?.authRole?.userId,
|
|
3292
|
+
}),
|
|
3293
|
+
};
|
|
3241
3294
|
}
|
|
3242
3295
|
}
|
|
3243
3296
|
|
|
@@ -3327,17 +3380,22 @@ class HasuraGraphQLOperationsHelper {
|
|
|
3327
3380
|
return this.executeFetch({ query: resultQuery, operationParams });
|
|
3328
3381
|
}
|
|
3329
3382
|
static async executeQuery(params) {
|
|
3330
|
-
var _a, _b, _c, _d;
|
|
3331
3383
|
const { operation, fields, variables, operationParams, buildHasuraQueryFields } = params;
|
|
3332
3384
|
const builded = buildHasuraQueryFields({ operation, fields, variables });
|
|
3333
|
-
const intercepted = (await
|
|
3385
|
+
const intercepted = (await operationParams.interceptors?.request?.(builded)) || builded;
|
|
3334
3386
|
const resultQuery = HasuraQueryBuilderHelper.buildQuery(intercepted);
|
|
3387
|
+
console.warn(resultQuery);
|
|
3335
3388
|
const result = await this.executeFetch({ query: resultQuery, operationParams });
|
|
3336
|
-
return (await
|
|
3389
|
+
return (await operationParams.interceptors?.response?.(result, intercepted)) || result;
|
|
3337
3390
|
}
|
|
3338
3391
|
static async executeFetch(params) {
|
|
3339
3392
|
const { query, operationParams } = params;
|
|
3340
|
-
return HasuraRequestHelper.fetch(
|
|
3393
|
+
return HasuraRequestHelper.fetch({
|
|
3394
|
+
...query,
|
|
3395
|
+
endpoint: operationParams.endpoint,
|
|
3396
|
+
headers: HasuraAuthHelper.buildHeaders(operationParams.authOptions),
|
|
3397
|
+
logger: operationParams.logger,
|
|
3398
|
+
});
|
|
3341
3399
|
}
|
|
3342
3400
|
}
|
|
3343
3401
|
|
|
@@ -3351,12 +3409,10 @@ class HasuraColumnHelper {
|
|
|
3351
3409
|
const columnOptions = Object.values(field).shift();
|
|
3352
3410
|
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
3353
3411
|
columnOptions.foreignKeyColumn && [
|
|
3354
|
-
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) =>
|
|
3412
|
+
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => AttributeOptionHelper.FindByAttribute(foreignKeyName, fields)?.columnName),
|
|
3355
3413
|
{
|
|
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
|
-
}),
|
|
3414
|
+
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
|
|
3415
|
+
?.columnName || foreignKeyField),
|
|
3360
3416
|
},
|
|
3361
3417
|
]);
|
|
3362
3418
|
})
|
|
@@ -3381,7 +3437,7 @@ class HasuraCreateOperationsHelper {
|
|
|
3381
3437
|
const { model } = params;
|
|
3382
3438
|
params.repository.logger = DebugHelper.from(params.repository, 'create');
|
|
3383
3439
|
const instance = model.toInstance(data);
|
|
3384
|
-
const newData = await this.executeSave(
|
|
3440
|
+
const newData = await this.executeSave({ ...params, data: instance });
|
|
3385
3441
|
return model.toInstance(newData);
|
|
3386
3442
|
}
|
|
3387
3443
|
static async executeSave(params) {
|
|
@@ -3395,14 +3451,14 @@ class HasuraCreateOperationsHelper {
|
|
|
3395
3451
|
},
|
|
3396
3452
|
});
|
|
3397
3453
|
const convertedResult = repository.convertDataFromHasura(result[insertGraphQLOperation]);
|
|
3398
|
-
return
|
|
3454
|
+
return { ...data.toPlain(), ...convertedResult.toPlain() };
|
|
3399
3455
|
}
|
|
3400
3456
|
}
|
|
3401
3457
|
|
|
3402
3458
|
class HasuraCacheOperationsHelper {
|
|
3403
3459
|
static async removeCacheData(cache, params) {
|
|
3404
3460
|
const { model, identifiers, logger } = params;
|
|
3405
|
-
if (!
|
|
3461
|
+
if (!cache?.cacheAdapter)
|
|
3406
3462
|
return;
|
|
3407
3463
|
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3408
3464
|
await cache.cacheAdapter.remove(cacheKey);
|
|
@@ -3422,13 +3478,16 @@ class HasuraDeleteVariablesHelper {
|
|
|
3422
3478
|
if (lodash.isNil(instance.identifier[identifierBinded]))
|
|
3423
3479
|
return ids;
|
|
3424
3480
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
|
|
3425
|
-
const value =
|
|
3481
|
+
const value = columnOption?.to(identifiers[identifier], instance) ||
|
|
3426
3482
|
identifiers[identifier];
|
|
3427
|
-
return
|
|
3483
|
+
return {
|
|
3484
|
+
...ids,
|
|
3485
|
+
[columnOption.columnName]: {
|
|
3428
3486
|
type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3429
3487
|
value,
|
|
3430
3488
|
required: true,
|
|
3431
|
-
}
|
|
3489
|
+
},
|
|
3490
|
+
};
|
|
3432
3491
|
}, {});
|
|
3433
3492
|
}
|
|
3434
3493
|
}
|
|
@@ -3466,16 +3525,15 @@ class HasuraFindBindingHelper {
|
|
|
3466
3525
|
], []);
|
|
3467
3526
|
}
|
|
3468
3527
|
static bindAggregateAttributes(aggregates, fields) {
|
|
3469
|
-
var _a, _b;
|
|
3470
3528
|
return [
|
|
3471
|
-
...(
|
|
3529
|
+
...(aggregates?.minimal?.length
|
|
3472
3530
|
? [
|
|
3473
3531
|
{
|
|
3474
3532
|
min: this.bindAttributesToColumns(aggregates.minimal, fields),
|
|
3475
3533
|
},
|
|
3476
3534
|
]
|
|
3477
3535
|
: []),
|
|
3478
|
-
...(
|
|
3536
|
+
...(aggregates?.maximum?.length
|
|
3479
3537
|
? [
|
|
3480
3538
|
{
|
|
3481
3539
|
max: this.bindAttributesToColumns(aggregates.maximum, fields),
|
|
@@ -3502,7 +3560,7 @@ class HasuraFindBindingHelper {
|
|
|
3502
3560
|
});
|
|
3503
3561
|
if (typeof fieldOption === 'object' && fieldOption !== null) {
|
|
3504
3562
|
const columnOption = fieldOption[attributeName];
|
|
3505
|
-
return
|
|
3563
|
+
return columnOption?.columnName || attributeName;
|
|
3506
3564
|
}
|
|
3507
3565
|
return attributeName;
|
|
3508
3566
|
}
|
|
@@ -3515,27 +3573,27 @@ class HasuraFindCacheHelper {
|
|
|
3515
3573
|
}
|
|
3516
3574
|
static async getCachedResult(params) {
|
|
3517
3575
|
const { cache, model, findParams, cacheOptions, logger } = params;
|
|
3518
|
-
if (!
|
|
3576
|
+
if (!cache?.cacheAdapter || !cacheOptions?.enabled)
|
|
3519
3577
|
return null;
|
|
3520
3578
|
const cacheKey = this.generateCacheKey(model, findParams);
|
|
3521
3579
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
3522
3580
|
if (cachedData) {
|
|
3523
|
-
logger
|
|
3581
|
+
logger?.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
3524
3582
|
return deserialize(cachedData);
|
|
3525
3583
|
}
|
|
3526
3584
|
return null;
|
|
3527
3585
|
}
|
|
3528
3586
|
static async setCachedResult(params) {
|
|
3529
3587
|
const { cache, model, findParams, cacheOptions, result, logger } = params;
|
|
3530
|
-
if (!
|
|
3588
|
+
if (!cache?.cacheAdapter || !cacheOptions?.enabled)
|
|
3531
3589
|
return;
|
|
3532
3590
|
const cacheKey = this.generateCacheKey(model, findParams);
|
|
3533
3591
|
await cache.cacheAdapter.set({
|
|
3534
3592
|
key: cacheKey,
|
|
3535
3593
|
data: serialize(result),
|
|
3536
|
-
expirationInSeconds:
|
|
3594
|
+
expirationInSeconds: cacheOptions?.ttl || cache.ttlDefault,
|
|
3537
3595
|
});
|
|
3538
|
-
logger
|
|
3596
|
+
logger?.log(`Dados salvos no cache: ${cacheKey}`);
|
|
3539
3597
|
}
|
|
3540
3598
|
}
|
|
3541
3599
|
|
|
@@ -3543,11 +3601,16 @@ class HasuraFindResultHelper {
|
|
|
3543
3601
|
static processResult(params) {
|
|
3544
3602
|
const { result, tableName, enableCount, findOptions, tableFiltersNamed, fields, convertDataFromHasura, lastDistinct, } = params;
|
|
3545
3603
|
const data = result[tableName].map((row) => convertDataFromHasura(row));
|
|
3546
|
-
const findResult =
|
|
3604
|
+
const findResult = {
|
|
3605
|
+
data,
|
|
3606
|
+
count: enableCount ? result[`${tableName}_aggregate`].aggregate.count : Infinity,
|
|
3607
|
+
...this.processMinimalAggregates({ result, tableName, findOptions, fields }),
|
|
3608
|
+
...this.processMaximumAggregates({ result, tableName, findOptions, fields }),
|
|
3609
|
+
...this.processDistinctResults({ result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct }),
|
|
3610
|
+
};
|
|
3547
3611
|
return findResult;
|
|
3548
3612
|
}
|
|
3549
3613
|
static bindAggregateAttributes(params) {
|
|
3550
|
-
var _a, _b;
|
|
3551
3614
|
const { aggregates, fields } = params;
|
|
3552
3615
|
const convertFieldName = (fieldName) => {
|
|
3553
3616
|
const finalFieldName = fieldName.toString().split('.').pop();
|
|
@@ -3559,19 +3622,19 @@ class HasuraFindResultHelper {
|
|
|
3559
3622
|
});
|
|
3560
3623
|
if (fieldOption && typeof fieldOption !== 'string') {
|
|
3561
3624
|
const fieldValue = Object.values(fieldOption)[0];
|
|
3562
|
-
return
|
|
3625
|
+
return fieldValue?.columnName || finalFieldName;
|
|
3563
3626
|
}
|
|
3564
3627
|
return finalFieldName;
|
|
3565
3628
|
};
|
|
3566
3629
|
return [
|
|
3567
|
-
...(
|
|
3630
|
+
...(aggregates?.minimal?.length
|
|
3568
3631
|
? [
|
|
3569
3632
|
{
|
|
3570
3633
|
min: aggregates.minimal.map(convertFieldName),
|
|
3571
3634
|
},
|
|
3572
3635
|
]
|
|
3573
3636
|
: []),
|
|
3574
|
-
...(
|
|
3637
|
+
...(aggregates?.maximum?.length
|
|
3575
3638
|
? [
|
|
3576
3639
|
{
|
|
3577
3640
|
max: aggregates.maximum.map(convertFieldName),
|
|
@@ -3581,48 +3644,52 @@ class HasuraFindResultHelper {
|
|
|
3581
3644
|
];
|
|
3582
3645
|
}
|
|
3583
3646
|
static processMinimalAggregates(params) {
|
|
3584
|
-
var _a;
|
|
3585
3647
|
const { result, tableName, findOptions, fields } = params;
|
|
3586
|
-
return
|
|
3648
|
+
return findOptions?.minimal?.length
|
|
3587
3649
|
? {
|
|
3588
3650
|
minimal: findOptions.minimal.reduce((minimals, current) => {
|
|
3589
|
-
|
|
3590
|
-
return
|
|
3651
|
+
const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
|
|
3652
|
+
return {
|
|
3653
|
+
...minimals,
|
|
3654
|
+
...lodash.set(minimals, current, result[`${tableName}_aggregate`].aggregate.min[columnName]),
|
|
3655
|
+
};
|
|
3591
3656
|
}, {}),
|
|
3592
3657
|
}
|
|
3593
3658
|
: {};
|
|
3594
3659
|
}
|
|
3595
3660
|
static processMaximumAggregates(params) {
|
|
3596
|
-
var _a;
|
|
3597
3661
|
const { result, tableName, findOptions, fields } = params;
|
|
3598
|
-
return
|
|
3662
|
+
return findOptions?.maximum?.length
|
|
3599
3663
|
? {
|
|
3600
3664
|
maximum: findOptions.maximum.reduce((maximums, current) => {
|
|
3601
|
-
|
|
3602
|
-
return
|
|
3665
|
+
const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
|
|
3666
|
+
return {
|
|
3667
|
+
...maximums,
|
|
3668
|
+
...lodash.set(maximums, current, result[`${tableName}_aggregate`].aggregate.max[columnName]),
|
|
3669
|
+
};
|
|
3603
3670
|
}, {}),
|
|
3604
3671
|
}
|
|
3605
3672
|
: {};
|
|
3606
3673
|
}
|
|
3607
3674
|
static processDistinctResults(params) {
|
|
3608
|
-
var _a, _b;
|
|
3609
3675
|
const { result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct } = params;
|
|
3610
|
-
return
|
|
3676
|
+
return findOptions?.distinct?.length
|
|
3611
3677
|
? {
|
|
3612
|
-
distinct:
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3678
|
+
distinct: lastDistinct[tableFiltersNamed] ??
|
|
3679
|
+
(lastDistinct[tableFiltersNamed] = findOptions?.distinct.reduce((distinct, current) => {
|
|
3680
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === current) ??
|
|
3681
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
|
|
3682
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || current;
|
|
3683
|
+
return {
|
|
3684
|
+
...distinct,
|
|
3685
|
+
[current.toString()]: result[`${tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]),
|
|
3686
|
+
};
|
|
3687
|
+
}, {})),
|
|
3618
3688
|
}
|
|
3619
3689
|
: {};
|
|
3620
3690
|
}
|
|
3621
3691
|
static bindAttributesToColumns(attributes, fields) {
|
|
3622
|
-
return attributes.map((attr) =>
|
|
3623
|
-
var _a;
|
|
3624
|
-
return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
|
|
3625
|
-
});
|
|
3692
|
+
return attributes.map((attr) => AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)?.columnName || attr);
|
|
3626
3693
|
}
|
|
3627
3694
|
}
|
|
3628
3695
|
|
|
@@ -3652,16 +3719,19 @@ class HasuraFindVariablesHelper {
|
|
|
3652
3719
|
};
|
|
3653
3720
|
}
|
|
3654
3721
|
static buildDistinctVariables(params) {
|
|
3655
|
-
var _a, _b;
|
|
3656
3722
|
const { distinct, tableName, fields, filtersVariables } = params;
|
|
3657
|
-
const distinctOption =
|
|
3658
|
-
|
|
3659
|
-
|
|
3723
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
|
|
3724
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
3725
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || distinct;
|
|
3726
|
+
return {
|
|
3727
|
+
...filtersVariables,
|
|
3728
|
+
[`${tableName}_${fieldName}_distinct`]: {
|
|
3660
3729
|
type: `${tableName}_select_column!`,
|
|
3661
3730
|
list: true,
|
|
3662
3731
|
value: fieldName,
|
|
3663
3732
|
name: 'distinct_on',
|
|
3664
|
-
}
|
|
3733
|
+
},
|
|
3734
|
+
};
|
|
3665
3735
|
}
|
|
3666
3736
|
static bindOrderByAttributes(orderBy, fields) {
|
|
3667
3737
|
return Object.keys(orderBy).reduce((acc, current) => [
|
|
@@ -3681,11 +3751,17 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3681
3751
|
const { tableName, fields, params, lastDistinct } = queryParams;
|
|
3682
3752
|
const { filters, limits, orderBy, options: findOptions } = params || {};
|
|
3683
3753
|
const filtersVariables = HasuraFindVariablesHelper.buildFiltersVariables({ filters, tableName, fields });
|
|
3684
|
-
const countVariables =
|
|
3685
|
-
|
|
3754
|
+
const countVariables = {
|
|
3755
|
+
...HasuraFindVariablesHelper.buildOrderByVariables({ orderBy, tableName, fields }),
|
|
3756
|
+
...filtersVariables,
|
|
3757
|
+
};
|
|
3758
|
+
const mainVariables = {
|
|
3759
|
+
...(lodash.isNil(limits) ? {} : limits),
|
|
3760
|
+
...countVariables,
|
|
3761
|
+
};
|
|
3686
3762
|
const queries = [
|
|
3687
3763
|
this.buildMainQuery({ tableName, fields, params, mainVariables }),
|
|
3688
|
-
...this.buildAggregateQuery({ tableName, findOptions, countVariables }),
|
|
3764
|
+
...this.buildAggregateQuery({ tableName, findOptions, countVariables, fields }),
|
|
3689
3765
|
...this.buildDistinctQueries({ tableName, fields, findOptions, filtersVariables, lastDistinct }),
|
|
3690
3766
|
];
|
|
3691
3767
|
return queries.filter(Boolean);
|
|
@@ -3694,26 +3770,23 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3694
3770
|
const { tableName, fields, params: findParams, mainVariables } = params;
|
|
3695
3771
|
return {
|
|
3696
3772
|
operation: tableName,
|
|
3697
|
-
fields:
|
|
3773
|
+
fields: findParams?.fields
|
|
3698
3774
|
? findParams.fields
|
|
3699
|
-
.map((fieldName) =>
|
|
3700
|
-
|
|
3701
|
-
return (_a = fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
|
|
3702
|
-
})
|
|
3775
|
+
.map((fieldName) => fields.find((fieldOption) => fieldOption === fieldName) ??
|
|
3776
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
|
|
3703
3777
|
.filter(Boolean)
|
|
3704
3778
|
: fields,
|
|
3705
3779
|
variables: mainVariables,
|
|
3706
3780
|
};
|
|
3707
3781
|
}
|
|
3708
3782
|
static buildAggregateQuery(params) {
|
|
3709
|
-
var _a;
|
|
3710
3783
|
const { tableName, findOptions, countVariables } = params;
|
|
3711
|
-
const enableCount =
|
|
3784
|
+
const enableCount = findOptions?.enableCount ?? true;
|
|
3712
3785
|
const aggregateFields = [
|
|
3713
3786
|
...(enableCount ? ['count'] : []),
|
|
3714
3787
|
...HasuraFindResultHelper.bindAggregateAttributes({
|
|
3715
|
-
aggregates: { minimal: findOptions
|
|
3716
|
-
fields:
|
|
3788
|
+
aggregates: { minimal: findOptions?.minimal, maximum: findOptions?.maximum },
|
|
3789
|
+
fields: params.fields,
|
|
3717
3790
|
}),
|
|
3718
3791
|
];
|
|
3719
3792
|
return aggregateFields.length > 0
|
|
@@ -3731,15 +3804,14 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3731
3804
|
: [];
|
|
3732
3805
|
}
|
|
3733
3806
|
static buildDistinctQueries(params) {
|
|
3734
|
-
var _a;
|
|
3735
3807
|
const { tableName, fields, findOptions, filtersVariables, lastDistinct } = params;
|
|
3736
3808
|
const tableFiltersNamed = `${tableName}:${JSON.stringify(filtersVariables)}`;
|
|
3737
|
-
if (!
|
|
3809
|
+
if (!findOptions?.distinct?.length || lastDistinct[tableFiltersNamed]) {
|
|
3738
3810
|
return [];
|
|
3739
3811
|
}
|
|
3740
3812
|
return findOptions.distinct.map((distinct) => {
|
|
3741
|
-
|
|
3742
|
-
|
|
3813
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
|
|
3814
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
3743
3815
|
return {
|
|
3744
3816
|
operation: {
|
|
3745
3817
|
name: tableName,
|
|
@@ -3759,18 +3831,17 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3759
3831
|
|
|
3760
3832
|
class HasuraFindOperationsHelper {
|
|
3761
3833
|
static async executeFindOperation(operationParams) {
|
|
3762
|
-
var _a;
|
|
3763
3834
|
const { params, cacheOptions, model, tableName, fields, cache, query, convertDataFromHasura, lastDistinct } = operationParams;
|
|
3764
3835
|
const logger = DebugHelper.from(operationParams, 'find');
|
|
3765
3836
|
const { filters, options: findOptions } = params || {};
|
|
3766
3837
|
const tableFiltersNamed = `${tableName}:${JSON.stringify(filters)}`;
|
|
3767
|
-
const enableCount =
|
|
3838
|
+
const enableCount = findOptions?.enableCount ?? true;
|
|
3768
3839
|
// Verifica cache primeiro
|
|
3769
3840
|
const cachedResult = await HasuraFindCacheHelper.getCachedResult({
|
|
3770
3841
|
cache,
|
|
3771
3842
|
model,
|
|
3772
3843
|
findParams: params,
|
|
3773
|
-
cacheOptions: cacheOptions
|
|
3844
|
+
cacheOptions: cacheOptions?.cache,
|
|
3774
3845
|
logger,
|
|
3775
3846
|
});
|
|
3776
3847
|
if (cachedResult) {
|
|
@@ -3798,7 +3869,7 @@ class HasuraFindOperationsHelper {
|
|
|
3798
3869
|
cache,
|
|
3799
3870
|
model,
|
|
3800
3871
|
findParams: params,
|
|
3801
|
-
cacheOptions: cacheOptions
|
|
3872
|
+
cacheOptions: cacheOptions?.cache,
|
|
3802
3873
|
result,
|
|
3803
3874
|
logger,
|
|
3804
3875
|
});
|
|
@@ -3821,9 +3892,8 @@ class HasuraGetCacheHelper {
|
|
|
3821
3892
|
return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3822
3893
|
}
|
|
3823
3894
|
static async getCachedData(cache, params) {
|
|
3824
|
-
var _a;
|
|
3825
3895
|
const { identifiers, options, model, logger } = params;
|
|
3826
|
-
if (!
|
|
3896
|
+
if (!cache?.cacheAdapter || !options?.cache?.enabled)
|
|
3827
3897
|
return null;
|
|
3828
3898
|
const cacheKey = this.generateCacheKey(model, identifiers);
|
|
3829
3899
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -3833,15 +3903,14 @@ class HasuraGetCacheHelper {
|
|
|
3833
3903
|
return model.toInstance(deserialize(cachedData));
|
|
3834
3904
|
}
|
|
3835
3905
|
static async saveCacheData(cache, params) {
|
|
3836
|
-
var _a, _b;
|
|
3837
3906
|
const { identifiers, options, data, logger } = params;
|
|
3838
|
-
if (!
|
|
3907
|
+
if (!cache?.cacheAdapter || !options?.cache?.enabled)
|
|
3839
3908
|
return;
|
|
3840
3909
|
const cacheKey = this.generateCacheKey(params.data.constructor, identifiers);
|
|
3841
3910
|
await cache.cacheAdapter.set({
|
|
3842
3911
|
key: cacheKey,
|
|
3843
3912
|
data: serialize(data),
|
|
3844
|
-
expirationInSeconds:
|
|
3913
|
+
expirationInSeconds: options?.cache?.ttl || cache.ttlDefault,
|
|
3845
3914
|
});
|
|
3846
3915
|
logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
3847
3916
|
}
|
|
@@ -3852,18 +3921,20 @@ class HasuraGetVariablesHelper {
|
|
|
3852
3921
|
const { model, fields, repository } = params;
|
|
3853
3922
|
const instance = model.toInstance(identifiers);
|
|
3854
3923
|
return model.identifiersFields.reduce((ids, identifier) => {
|
|
3855
|
-
var _a;
|
|
3856
3924
|
const identifierBinded = identifier;
|
|
3857
3925
|
if (lodash.isNil(instance[identifierBinded]))
|
|
3858
3926
|
return ids;
|
|
3859
3927
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
|
|
3860
|
-
const value =
|
|
3928
|
+
const value = columnOption?.to?.(identifiers[identifier], instance) ||
|
|
3861
3929
|
identifiers[identifier];
|
|
3862
|
-
return
|
|
3930
|
+
return {
|
|
3931
|
+
...ids,
|
|
3932
|
+
[columnOption.columnName]: {
|
|
3863
3933
|
type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3864
3934
|
value,
|
|
3865
3935
|
required: true,
|
|
3866
|
-
}
|
|
3936
|
+
},
|
|
3937
|
+
};
|
|
3867
3938
|
}, {});
|
|
3868
3939
|
}
|
|
3869
3940
|
}
|
|
@@ -3920,7 +3991,7 @@ class HasuraUpdateDataHelper {
|
|
|
3920
3991
|
static getValueByAction(options) {
|
|
3921
3992
|
if (options instanceof BaseModel)
|
|
3922
3993
|
return options.toPlain();
|
|
3923
|
-
if (lodash.isNil(options
|
|
3994
|
+
if (lodash.isNil(options?.action))
|
|
3924
3995
|
return options;
|
|
3925
3996
|
if ([exports.UpdateOptionActions.REMOVE_FIELD.toString(), exports.UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
3926
3997
|
return null;
|
|
@@ -3929,9 +4000,12 @@ class HasuraUpdateDataHelper {
|
|
|
3929
4000
|
static paramsToPlain(params, model) {
|
|
3930
4001
|
if (model.isModel(params))
|
|
3931
4002
|
return params.toPlain();
|
|
3932
|
-
return Object.keys(params).reduce((data, currentKey) => (
|
|
3933
|
-
|
|
3934
|
-
|
|
4003
|
+
return Object.keys(params).reduce((data, currentKey) => ({
|
|
4004
|
+
...data,
|
|
4005
|
+
...(params[currentKey] !== undefined && {
|
|
4006
|
+
[currentKey]: this.getValueByAction(is(params[currentKey])),
|
|
4007
|
+
}),
|
|
4008
|
+
}), {});
|
|
3935
4009
|
}
|
|
3936
4010
|
static getIdentifiersFromData(data, model) {
|
|
3937
4011
|
const instance = model.toInstance(data);
|
|
@@ -3950,13 +4024,15 @@ class HasuraUpdateVariablesHelper {
|
|
|
3950
4024
|
static getUpdateModelKeys(data, model, fields) {
|
|
3951
4025
|
const instance = model.toInstance(data);
|
|
3952
4026
|
return model.identifiersFields.reduce((ids, identifier) => {
|
|
3953
|
-
var _a;
|
|
3954
4027
|
const identifierBinded = identifier;
|
|
3955
4028
|
if (lodash.isNil(instance.identifier[identifierBinded]))
|
|
3956
4029
|
return ids;
|
|
3957
4030
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifierBinded, fields);
|
|
3958
|
-
const value =
|
|
3959
|
-
return
|
|
4031
|
+
const value = columnOption?.to?.(data[identifierBinded], instance) || data[columnOption.attributeName];
|
|
4032
|
+
return {
|
|
4033
|
+
...ids,
|
|
4034
|
+
[columnOption.columnName]: value,
|
|
4035
|
+
};
|
|
3960
4036
|
}, {});
|
|
3961
4037
|
}
|
|
3962
4038
|
static getIdentifierFields(model, fields) {
|
|
@@ -4001,13 +4077,13 @@ class HasuraUpdateOperationsHelper {
|
|
|
4001
4077
|
}
|
|
4002
4078
|
static async handleCacheRemoval(params) {
|
|
4003
4079
|
const { plainData, model, cache, logger } = params;
|
|
4004
|
-
if (!
|
|
4080
|
+
if (!cache?.cacheAdapter)
|
|
4005
4081
|
return;
|
|
4006
4082
|
const identifiers = HasuraUpdateDataHelper.getIdentifiersFromData(plainData, model);
|
|
4007
4083
|
if (Object.keys(identifiers).length > 0) {
|
|
4008
4084
|
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
4009
4085
|
await cache.cacheAdapter.remove(cacheKey);
|
|
4010
|
-
logger
|
|
4086
|
+
logger?.log(`Cache removido: ${cacheKey}`);
|
|
4011
4087
|
}
|
|
4012
4088
|
}
|
|
4013
4089
|
}
|
|
@@ -4029,9 +4105,8 @@ class FirestoreCacheKeyGeneratorHelper {
|
|
|
4029
4105
|
|
|
4030
4106
|
class FirestoreCacheHelper {
|
|
4031
4107
|
static async getCachedData(cache, params) {
|
|
4032
|
-
var _a;
|
|
4033
4108
|
const { model, identifiers, options, logger, req } = params;
|
|
4034
|
-
if (!
|
|
4109
|
+
if (!cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4035
4110
|
return null;
|
|
4036
4111
|
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(model, identifiers);
|
|
4037
4112
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -4042,9 +4117,8 @@ class FirestoreCacheHelper {
|
|
|
4042
4117
|
return null;
|
|
4043
4118
|
}
|
|
4044
4119
|
static async getCachedFindData(cache, params) {
|
|
4045
|
-
var _a;
|
|
4046
4120
|
const { model, find, options, logger } = params;
|
|
4047
|
-
if (!
|
|
4121
|
+
if (!cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4048
4122
|
return null;
|
|
4049
4123
|
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(model, find);
|
|
4050
4124
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -4056,7 +4130,7 @@ class FirestoreCacheHelper {
|
|
|
4056
4130
|
}
|
|
4057
4131
|
static async saveCacheData(cache, params) {
|
|
4058
4132
|
const { cacheKey, data, expirationInSeconds, logger, req } = params;
|
|
4059
|
-
if (!
|
|
4133
|
+
if (!cache?.cacheAdapter)
|
|
4060
4134
|
return;
|
|
4061
4135
|
await cache.cacheAdapter.set({
|
|
4062
4136
|
key: cacheKey,
|
|
@@ -4068,7 +4142,7 @@ class FirestoreCacheHelper {
|
|
|
4068
4142
|
}
|
|
4069
4143
|
static async removeCacheData(cache, params) {
|
|
4070
4144
|
const { cacheKey, logger } = params;
|
|
4071
|
-
if (!
|
|
4145
|
+
if (!cache?.cacheAdapter)
|
|
4072
4146
|
return;
|
|
4073
4147
|
await cache.cacheAdapter.remove(cacheKey);
|
|
4074
4148
|
logger.log(`Cache removido: ${cacheKey}`);
|
|
@@ -4086,7 +4160,7 @@ class FirestoreOperationsHelper {
|
|
|
4086
4160
|
this.model = model;
|
|
4087
4161
|
}
|
|
4088
4162
|
buildInstanceFromIdentifiers(identifiers) {
|
|
4089
|
-
return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (
|
|
4163
|
+
return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
|
|
4090
4164
|
}
|
|
4091
4165
|
async validateDocumentExists(docRef, collectionName, identifiers) {
|
|
4092
4166
|
const docSnapshot = await docRef.get();
|
|
@@ -4108,7 +4182,7 @@ class FirestoreOperationsHelper {
|
|
|
4108
4182
|
calculateCount(data, limits) {
|
|
4109
4183
|
if (data.length <= 0)
|
|
4110
4184
|
return 0;
|
|
4111
|
-
if (data.length <
|
|
4185
|
+
if (data.length < limits?.limit)
|
|
4112
4186
|
return data.length;
|
|
4113
4187
|
return Infinity;
|
|
4114
4188
|
}
|
|
@@ -4121,8 +4195,8 @@ class FirestoreOperationsHelper {
|
|
|
4121
4195
|
const { isSubCollection, collectionName, parentRepository, parentIdField, identifiers } = params;
|
|
4122
4196
|
if (!isSubCollection)
|
|
4123
4197
|
return collectionName;
|
|
4124
|
-
const parentId = identifiers
|
|
4125
|
-
return `${parentRepository
|
|
4198
|
+
const parentId = identifiers?.[parentIdField];
|
|
4199
|
+
return `${parentRepository?.collectionName}/${parentId}/${collectionName}`;
|
|
4126
4200
|
}
|
|
4127
4201
|
getKeyField() {
|
|
4128
4202
|
const model = new this.model();
|
|
@@ -4173,27 +4247,25 @@ const createGetFirestoreClass = (MixinBase) => {
|
|
|
4173
4247
|
}
|
|
4174
4248
|
}
|
|
4175
4249
|
async executeGet(params) {
|
|
4176
|
-
var _a, _b, _c, _d;
|
|
4177
4250
|
const { instance, collectionName, identifiers, logger, req } = params;
|
|
4178
|
-
const intercepted = await
|
|
4179
|
-
const builded =
|
|
4251
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4252
|
+
const builded = intercepted?.instance || instance;
|
|
4180
4253
|
const docRef = await this.operationsHelper.getDocumentSnapshot(this.collection(collectionName), builded);
|
|
4181
4254
|
const data = docRef.data();
|
|
4182
4255
|
this.operationsHelper.validateDocumentData(data, collectionName, identifiers);
|
|
4183
|
-
const result = (await
|
|
4256
|
+
const result = (await this.interceptors?.response?.(data, intercepted)) || data;
|
|
4184
4257
|
logger.log({ req, res: result });
|
|
4185
4258
|
return result;
|
|
4186
4259
|
}
|
|
4187
4260
|
async saveCacheData(params) {
|
|
4188
|
-
var _a, _b, _c;
|
|
4189
4261
|
const { identifiers, options, result, logger, req } = params;
|
|
4190
|
-
if (!
|
|
4262
|
+
if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4191
4263
|
return;
|
|
4192
4264
|
const cacheKey = FirestoreCacheHelper.generateGetCacheKey(this.model, identifiers);
|
|
4193
4265
|
await FirestoreCacheHelper.saveCacheData(this.cache, {
|
|
4194
4266
|
cacheKey,
|
|
4195
4267
|
data: result,
|
|
4196
|
-
expirationInSeconds:
|
|
4268
|
+
expirationInSeconds: options?.cache?.ttl,
|
|
4197
4269
|
logger,
|
|
4198
4270
|
req,
|
|
4199
4271
|
});
|
|
@@ -4224,14 +4296,13 @@ class FirestoreQueryBuilderHelper {
|
|
|
4224
4296
|
this.config = config;
|
|
4225
4297
|
}
|
|
4226
4298
|
buildWhereSentence(fieldName, options) {
|
|
4227
|
-
|
|
4228
|
-
if (((_b = (_a = this.config).isSubCollection) === null || _b === void 0 ? void 0 : _b.call(_a, this)) && fieldName === this.config.parentIdField)
|
|
4299
|
+
if (this.config.isSubCollection?.(this) && fieldName === this.config.parentIdField)
|
|
4229
4300
|
return [];
|
|
4230
4301
|
const firestoreFieldName = this.getFirestoreFieldName(fieldName, options);
|
|
4231
4302
|
return this.buildWhereConditions(firestoreFieldName, options, fieldName);
|
|
4232
4303
|
}
|
|
4233
4304
|
getFirestoreFieldName(fieldName, options) {
|
|
4234
|
-
const value =
|
|
4305
|
+
const value = options?.value || options;
|
|
4235
4306
|
const object = {};
|
|
4236
4307
|
lodash.set(object, fieldName.toString(), value);
|
|
4237
4308
|
const plainInstance = new this.config.model(object).toPlain();
|
|
@@ -4240,19 +4311,19 @@ class FirestoreQueryBuilderHelper {
|
|
|
4240
4311
|
: Object.keys(plainInstance).find((key) => plainInstance[key]);
|
|
4241
4312
|
}
|
|
4242
4313
|
buildWhereConditions(firestoreFieldName, options, fieldName) {
|
|
4243
|
-
if (
|
|
4314
|
+
if (options?.operator === exports.Where.LIKE) {
|
|
4244
4315
|
return this.buildLikeConditions(firestoreFieldName, options);
|
|
4245
4316
|
}
|
|
4246
|
-
if (
|
|
4317
|
+
if (options?.operator === exports.Where.IN && Array.isArray(options?.value)) {
|
|
4247
4318
|
return this.buildInConditions(firestoreFieldName, options);
|
|
4248
4319
|
}
|
|
4249
4320
|
if (this.isNestedObjectFilter(options)) {
|
|
4250
4321
|
return this.buildNestedObjectConditions(fieldName, options);
|
|
4251
4322
|
}
|
|
4252
|
-
return [[firestoreFieldName, (
|
|
4323
|
+
return [[firestoreFieldName, (options?.operator || '=='), options?.value || options]];
|
|
4253
4324
|
}
|
|
4254
4325
|
buildLikeConditions(firestoreFieldName, options) {
|
|
4255
|
-
if (this.isArrayField(firestoreFieldName) && Array.isArray(options
|
|
4326
|
+
if (this.isArrayField(firestoreFieldName) && Array.isArray(options?.value)) {
|
|
4256
4327
|
return [[firestoreFieldName, 'array-contains-any', options.value]];
|
|
4257
4328
|
}
|
|
4258
4329
|
return [
|
|
@@ -4273,13 +4344,12 @@ class FirestoreQueryBuilderHelper {
|
|
|
4273
4344
|
], []);
|
|
4274
4345
|
}
|
|
4275
4346
|
isArrayField(firestoreFieldName) {
|
|
4276
|
-
|
|
4277
|
-
return (((_a = this.config.fields) === null || _a === void 0 ? void 0 : _a[firestoreFieldName]) ===
|
|
4347
|
+
return (this.config.fields?.[firestoreFieldName] ===
|
|
4278
4348
|
FirestoreFieldType.Array ||
|
|
4279
|
-
!
|
|
4349
|
+
!this.config.fields?.[firestoreFieldName]);
|
|
4280
4350
|
}
|
|
4281
4351
|
isNestedObjectFilter(options) {
|
|
4282
|
-
return lodash.isObject(options) && lodash.isNil(options
|
|
4352
|
+
return lodash.isObject(options) && lodash.isNil(options?.operator) && lodash.isNil(options?.value);
|
|
4283
4353
|
}
|
|
4284
4354
|
buildOrderBy(filters, fieldsToOrderBy) {
|
|
4285
4355
|
const orderByKeys = Object.keys(fieldsToOrderBy || {});
|
|
@@ -4295,8 +4365,8 @@ class FirestoreQueryBuilderHelper {
|
|
|
4295
4365
|
filtersKeysWithUnordered.forEach((filterKey) => {
|
|
4296
4366
|
const filterValue = filters[filterKey];
|
|
4297
4367
|
const filterOptions = is(filterValue);
|
|
4298
|
-
if (
|
|
4299
|
-
updatedOrderBy =
|
|
4368
|
+
if (filterOptions?.operator && ![exports.Where.EQUALS].includes(filterOptions.operator)) {
|
|
4369
|
+
updatedOrderBy = { [filterKey]: 'asc', ...updatedOrderBy };
|
|
4300
4370
|
}
|
|
4301
4371
|
});
|
|
4302
4372
|
return updatedOrderBy;
|
|
@@ -4310,21 +4380,21 @@ class FirestoreQueryBuilderHelper {
|
|
|
4310
4380
|
async buildLimits(params) {
|
|
4311
4381
|
const { filters, limits, collection, buildCollectionPath } = params;
|
|
4312
4382
|
const queries = [];
|
|
4313
|
-
if (limits
|
|
4383
|
+
if (limits?.offset) {
|
|
4314
4384
|
await this.addOffsetQuery({ queries, limits, filters, collection, buildCollectionPath });
|
|
4315
4385
|
}
|
|
4316
|
-
if (limits
|
|
4386
|
+
if (limits?.limit) {
|
|
4317
4387
|
queries.push(['limit', limits.limit]);
|
|
4318
4388
|
}
|
|
4319
4389
|
return queries;
|
|
4320
4390
|
}
|
|
4321
4391
|
async addOffsetQuery(params) {
|
|
4322
|
-
var _a;
|
|
4323
4392
|
const { queries, limits, filters, collection, buildCollectionPath } = params;
|
|
4324
4393
|
if (this.config.model.isModel(limits.offset)) {
|
|
4325
4394
|
const docSnapshot = await collection(buildCollectionPath(filters))
|
|
4326
|
-
.getDoc(
|
|
4327
|
-
.shift()
|
|
4395
|
+
.getDoc(Object.values(limits.offset.identifier)
|
|
4396
|
+
.shift()
|
|
4397
|
+
?.toString())
|
|
4328
4398
|
.get();
|
|
4329
4399
|
queries.push(['fromStartAfter', docSnapshot]);
|
|
4330
4400
|
}
|
|
@@ -4339,7 +4409,7 @@ class FirestoreQueryBuilderHelper {
|
|
|
4339
4409
|
}
|
|
4340
4410
|
|
|
4341
4411
|
const createFilterHelpers = () => {
|
|
4342
|
-
const checkIfIsFilterOption = (filter) => !lodash.isNil(filter
|
|
4412
|
+
const checkIfIsFilterOption = (filter) => !lodash.isNil(filter?.operator);
|
|
4343
4413
|
const getValueFromFilter = (filter) => {
|
|
4344
4414
|
return checkIfIsFilterOption(filter) ? filter.value : filter;
|
|
4345
4415
|
};
|
|
@@ -4397,20 +4467,19 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4397
4467
|
}
|
|
4398
4468
|
}
|
|
4399
4469
|
async executeFind(params) {
|
|
4400
|
-
var _a, _b, _c, _d, _e, _f;
|
|
4401
4470
|
const { find, collectionName, logger, req } = params;
|
|
4402
4471
|
const collection = this.collection(collectionName);
|
|
4403
|
-
const enableCount =
|
|
4404
|
-
const intercepted = await
|
|
4405
|
-
const { filters, limits, orderBy } =
|
|
4472
|
+
const enableCount = find?.options?.enableCount ?? true;
|
|
4473
|
+
const intercepted = await this.interceptors?.request?.({ find });
|
|
4474
|
+
const { filters, limits, orderBy } = intercepted?.find || find;
|
|
4406
4475
|
const queryData = await this.buildQueryData(filters, orderBy, limits);
|
|
4407
4476
|
const docs = await this.executeQuery(collection, queryData);
|
|
4408
4477
|
const data = docs.docs.map((doc) => doc.data());
|
|
4409
4478
|
const result = {
|
|
4410
|
-
data: (await
|
|
4479
|
+
data: (await this.interceptors?.response?.(data, intercepted)) || data,
|
|
4411
4480
|
count: enableCount ? this.operationsHelper.calculateCount(data, limits) : Infinity,
|
|
4412
4481
|
};
|
|
4413
|
-
logger.log(
|
|
4482
|
+
logger.log({ req, ...queryData, res: result });
|
|
4414
4483
|
return result;
|
|
4415
4484
|
}
|
|
4416
4485
|
async buildQueryData(filters, orderBy, limits) {
|
|
@@ -4426,19 +4495,21 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4426
4495
|
}
|
|
4427
4496
|
async executeQuery(collection, queryData) {
|
|
4428
4497
|
return this.queryBuilder
|
|
4429
|
-
.buildQuery(
|
|
4498
|
+
.buildQuery({
|
|
4499
|
+
collection,
|
|
4500
|
+
...queryData,
|
|
4501
|
+
})
|
|
4430
4502
|
.getDocs();
|
|
4431
4503
|
}
|
|
4432
4504
|
async saveCacheData(params) {
|
|
4433
|
-
var _a, _b, _c;
|
|
4434
4505
|
const { find, options, result, logger } = params;
|
|
4435
|
-
if (!
|
|
4506
|
+
if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4436
4507
|
return;
|
|
4437
4508
|
const cacheKey = this.generateCacheKey(find);
|
|
4438
4509
|
await FirestoreCacheHelper.saveCacheData(this.cache, {
|
|
4439
4510
|
cacheKey,
|
|
4440
4511
|
data: result,
|
|
4441
|
-
expirationInSeconds:
|
|
4512
|
+
expirationInSeconds: options?.cache?.ttl,
|
|
4442
4513
|
logger,
|
|
4443
4514
|
});
|
|
4444
4515
|
}
|
|
@@ -4446,7 +4517,7 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4446
4517
|
if (!this.isSubCollection(this))
|
|
4447
4518
|
return this.collectionName;
|
|
4448
4519
|
const parentIdField = this.parentIdField;
|
|
4449
|
-
const parentId = getValueFromFilter(filters
|
|
4520
|
+
const parentId = getValueFromFilter(filters?.[parentIdField]);
|
|
4450
4521
|
return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
|
|
4451
4522
|
}
|
|
4452
4523
|
};
|
|
@@ -4455,16 +4526,15 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4455
4526
|
const withCreateFirestore = (MixinBase) => {
|
|
4456
4527
|
return class CreateFirestore extends MixinBase {
|
|
4457
4528
|
async create(data) {
|
|
4458
|
-
var _a, _b, _c, _d;
|
|
4459
4529
|
const logger = this.logger.with('create');
|
|
4460
4530
|
const instance = this.model.toInstance(data);
|
|
4461
|
-
const intercepted = await
|
|
4462
|
-
const builded =
|
|
4531
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4532
|
+
const builded = intercepted?.instance || instance;
|
|
4463
4533
|
const req = { collection: this.buildCollectionPathForAdd(builded), data };
|
|
4464
4534
|
try {
|
|
4465
4535
|
const docRef = await this.save(builded);
|
|
4466
4536
|
const doc = (await docRef.get()).data();
|
|
4467
|
-
const docBuilded = (await
|
|
4537
|
+
const docBuilded = (await this.interceptors?.response?.(doc, intercepted)) || doc;
|
|
4468
4538
|
logger.log({ req, res: docBuilded });
|
|
4469
4539
|
return docBuilded;
|
|
4470
4540
|
}
|
|
@@ -4475,10 +4545,9 @@ const withCreateFirestore = (MixinBase) => {
|
|
|
4475
4545
|
}
|
|
4476
4546
|
}
|
|
4477
4547
|
async save(data) {
|
|
4478
|
-
var _a, _b;
|
|
4479
4548
|
const collectionPath = this.buildCollectionPathForAdd(data);
|
|
4480
4549
|
const collection = this.collection(collectionPath);
|
|
4481
|
-
return collection.add(data,
|
|
4550
|
+
return collection.add(data, Object.values(data.identifier).shift()?.toString?.());
|
|
4482
4551
|
}
|
|
4483
4552
|
buildCollectionPathForAdd(identifiers) {
|
|
4484
4553
|
return this.isSubCollection(this)
|
|
@@ -4489,26 +4558,23 @@ const withCreateFirestore = (MixinBase) => {
|
|
|
4489
4558
|
};
|
|
4490
4559
|
|
|
4491
4560
|
const createUpdateHelpers = () => {
|
|
4492
|
-
const getValueFromParams = (params, field) =>
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
? is(params[field])
|
|
4496
|
-
: is(params[field]).value) || null;
|
|
4497
|
-
};
|
|
4561
|
+
const getValueFromParams = (params, field) => (lodash.isNil(is(params[field])?.value)
|
|
4562
|
+
? is(params[field])
|
|
4563
|
+
: is(params[field]).value) || null;
|
|
4498
4564
|
const getValueByAction = (options) => {
|
|
4499
|
-
if (lodash.isNil(options
|
|
4565
|
+
if (lodash.isNil(options?.action))
|
|
4500
4566
|
return options;
|
|
4501
|
-
if (
|
|
4567
|
+
if (options?.action === exports.UpdateOptionActions.REMOVE_FIELD)
|
|
4502
4568
|
return firestore.deleteField();
|
|
4503
|
-
if (
|
|
4569
|
+
if (options?.action === exports.UpdateOptionActions.NULL)
|
|
4504
4570
|
return null;
|
|
4505
|
-
if (Array.isArray(options
|
|
4506
|
-
if (
|
|
4571
|
+
if (Array.isArray(options?.value)) {
|
|
4572
|
+
if (options?.action === exports.UpdateOptionActions.MERGE)
|
|
4507
4573
|
return firestore.arrayUnion(...options.value);
|
|
4508
|
-
if (
|
|
4574
|
+
if (options?.action === exports.UpdateOptionActions.REMOVE)
|
|
4509
4575
|
return firestore.arrayRemove(...options.value);
|
|
4510
4576
|
}
|
|
4511
|
-
return options
|
|
4577
|
+
return options?.value;
|
|
4512
4578
|
};
|
|
4513
4579
|
return { getValueFromParams, getValueByAction };
|
|
4514
4580
|
};
|
|
@@ -4559,14 +4625,13 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
|
|
|
4559
4625
|
await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
|
|
4560
4626
|
}
|
|
4561
4627
|
async executeUpdate(params) {
|
|
4562
|
-
var _a, _b, _c, _d;
|
|
4563
4628
|
const { data, docRef, logger, req, identifiers } = params;
|
|
4564
4629
|
const plainFromData = this.model.toInstance(this.paramsToPlain(data));
|
|
4565
|
-
const intercepted = await
|
|
4566
|
-
const builded =
|
|
4630
|
+
const intercepted = await this.interceptors?.request?.({ instance: plainFromData });
|
|
4631
|
+
const builded = intercepted?.instance || plainFromData;
|
|
4567
4632
|
await docRef.save(builded.toPlain());
|
|
4568
4633
|
const docData = await docRef.get();
|
|
4569
|
-
const result =
|
|
4634
|
+
const result = this.interceptors?.response?.(docData.data(), intercepted) || docData.data();
|
|
4570
4635
|
logger.log({ req, res: result, identifiers });
|
|
4571
4636
|
return result;
|
|
4572
4637
|
}
|
|
@@ -4582,7 +4647,10 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
|
|
|
4582
4647
|
return this.convertParamsToPlainObject(params);
|
|
4583
4648
|
}
|
|
4584
4649
|
convertParamsToPlainObject(params) {
|
|
4585
|
-
return Object.keys(params).reduce((data, currentKey) => (
|
|
4650
|
+
return Object.keys(params).reduce((data, currentKey) => ({
|
|
4651
|
+
...data,
|
|
4652
|
+
...this.processParamValue(currentKey, params[currentKey]),
|
|
4653
|
+
}), {});
|
|
4586
4654
|
}
|
|
4587
4655
|
processParamValue(key, value) {
|
|
4588
4656
|
const processedValue = getValueByAction(value);
|
|
@@ -4623,12 +4691,11 @@ const createDeleteFirestoreClass = (MixinBase) => {
|
|
|
4623
4691
|
await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
|
|
4624
4692
|
}
|
|
4625
4693
|
async executeDeleteOperation(params) {
|
|
4626
|
-
var _a, _b, _c, _d;
|
|
4627
4694
|
const { instance, collectionName, logger, req } = params;
|
|
4628
|
-
const intercepted = await
|
|
4629
|
-
const builded =
|
|
4695
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4696
|
+
const builded = intercepted?.instance || instance;
|
|
4630
4697
|
await this.operationsHelper.executeDelete(this.collection(collectionName), builded);
|
|
4631
|
-
await
|
|
4698
|
+
await this.interceptors?.response?.(instance, intercepted);
|
|
4632
4699
|
logger.log({ req, res: undefined });
|
|
4633
4700
|
}
|
|
4634
4701
|
buildCollectionPathForRemove(identifiers) {
|
|
@@ -4708,15 +4775,15 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
4708
4775
|
const products = [];
|
|
4709
4776
|
const wheres = [];
|
|
4710
4777
|
for (const productIds of chunks) {
|
|
4711
|
-
if (
|
|
4778
|
+
if (options?.limit && products.length >= options?.limit)
|
|
4712
4779
|
break;
|
|
4713
4780
|
wheres.push(['published', '==', true], ['id', 'in', productIds]);
|
|
4714
|
-
if (options
|
|
4781
|
+
if (options?.hasStock)
|
|
4715
4782
|
wheres.push(['stock.quantity', '>', 0]);
|
|
4716
|
-
if (options
|
|
4717
|
-
wheres.push(['tags', 'array-contains', options
|
|
4783
|
+
if (options?.gender)
|
|
4784
|
+
wheres.push(['tags', 'array-contains', options?.gender]);
|
|
4718
4785
|
const productSnap = await wheres
|
|
4719
|
-
.reduce((collection, where) => collection.where(...where),
|
|
4786
|
+
.reduce((collection, where) => collection.where(...where), options?.limit
|
|
4720
4787
|
? this.collection('productsErpVitrine').limit(options.limit)
|
|
4721
4788
|
: this.collection('productsErpVitrine'))
|
|
4722
4789
|
.getDocs();
|
|
@@ -4781,19 +4848,17 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
4781
4848
|
throw new Error('Method not implemented.');
|
|
4782
4849
|
}
|
|
4783
4850
|
async getBySlug(slug) {
|
|
4784
|
-
var _a;
|
|
4785
4851
|
const result = await this.find({
|
|
4786
4852
|
filters: {
|
|
4787
4853
|
slug: { operator: exports.Where.EQUALS, value: slug },
|
|
4788
4854
|
},
|
|
4789
4855
|
});
|
|
4790
|
-
return
|
|
4856
|
+
return result?.data?.shift();
|
|
4791
4857
|
}
|
|
4792
4858
|
async fetchReviews(status) {
|
|
4793
4859
|
const { data: products } = await this.find();
|
|
4794
4860
|
products.forEach((product) => {
|
|
4795
|
-
|
|
4796
|
-
if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
|
|
4861
|
+
if ([undefined, 0].includes(product.reviews?.length))
|
|
4797
4862
|
return;
|
|
4798
4863
|
const productInfo = {
|
|
4799
4864
|
productId: product.id,
|
|
@@ -4805,11 +4870,11 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
4805
4870
|
this.reviews.rejected = [];
|
|
4806
4871
|
product.reviews.forEach((review) => {
|
|
4807
4872
|
if ([null, undefined].includes(review.status))
|
|
4808
|
-
return this.reviews.pending.push(
|
|
4873
|
+
return this.reviews.pending.push({ ...review, ...productInfo });
|
|
4809
4874
|
if (review.status === false)
|
|
4810
|
-
return this.reviews.rejected.push(
|
|
4875
|
+
return this.reviews.rejected.push({ ...review, ...productInfo });
|
|
4811
4876
|
if (review.status)
|
|
4812
|
-
return this.reviews.approved.push(
|
|
4877
|
+
return this.reviews.approved.push({ ...review, ...productInfo });
|
|
4813
4878
|
return review;
|
|
4814
4879
|
});
|
|
4815
4880
|
});
|
|
@@ -4896,22 +4961,18 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
4896
4961
|
interceptors,
|
|
4897
4962
|
cache,
|
|
4898
4963
|
});
|
|
4899
|
-
this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
|
|
4912
|
-
products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
|
|
4913
|
-
});
|
|
4914
|
-
};
|
|
4964
|
+
this.homeCategoryGroupToPlain = (homeCategoryGroup) => ({
|
|
4965
|
+
category: homeCategoryGroup?.category?.toPlain
|
|
4966
|
+
? homeCategoryGroup?.category?.toPlain()
|
|
4967
|
+
: homeCategoryGroup?.category,
|
|
4968
|
+
products: homeCategoryGroup?.products
|
|
4969
|
+
?.map((product) => (product?.toPlain ? product?.toPlain() : product))
|
|
4970
|
+
.filter(Boolean) || [],
|
|
4971
|
+
});
|
|
4972
|
+
this.plainToHomeCategoryGroup = (homeCategoryGroup) => ({
|
|
4973
|
+
category: Category.toInstance(homeCategoryGroup?.category),
|
|
4974
|
+
products: homeCategoryGroup.products?.map((product) => Product.toInstance(product)),
|
|
4975
|
+
});
|
|
4915
4976
|
}
|
|
4916
4977
|
buildModelInstance() {
|
|
4917
4978
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -4927,17 +4988,15 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
4927
4988
|
};
|
|
4928
4989
|
}
|
|
4929
4990
|
homeToFirestore(home) {
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
home.data.data.
|
|
4933
|
-
home.data.data.
|
|
4934
|
-
home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
|
|
4991
|
+
if (home.data?.data) {
|
|
4992
|
+
home.data.data.discoverProducts = home.data.data.discoverProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4993
|
+
home.data.data.featuredProducts = home.data.data.featuredProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4994
|
+
home.data.data.verticalProducts = home.data.data.verticalProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4935
4995
|
}
|
|
4936
4996
|
return home;
|
|
4937
4997
|
}
|
|
4938
4998
|
homeFromFirestore(home) {
|
|
4939
|
-
|
|
4940
|
-
if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
|
|
4999
|
+
if (home.data?.data) {
|
|
4941
5000
|
home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
|
|
4942
5001
|
home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
|
|
4943
5002
|
home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
|
|
@@ -5076,8 +5135,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
5076
5135
|
},
|
|
5077
5136
|
});
|
|
5078
5137
|
this.orderFromFirestore = (order) => {
|
|
5079
|
-
|
|
5080
|
-
if ((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length) {
|
|
5138
|
+
if (order?.lineItems?.length) {
|
|
5081
5139
|
order.lineItems = order.lineItems.map((lineItem) => {
|
|
5082
5140
|
const prices = !!lineItem.price;
|
|
5083
5141
|
const shopPrice = prices[order.shop];
|
|
@@ -5092,7 +5150,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
5092
5150
|
buildModelInstance() {
|
|
5093
5151
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
5094
5152
|
return {
|
|
5095
|
-
toFirestore: (data) => toFirestore(
|
|
5153
|
+
toFirestore: (data) => toFirestore(data?.toPlain ? data.toPlain() : data),
|
|
5096
5154
|
fromFirestore: (snap) => {
|
|
5097
5155
|
const instance = fromFirestore(snap);
|
|
5098
5156
|
return this.orderFromFirestore(instance);
|
|
@@ -5123,18 +5181,20 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
|
|
|
5123
5181
|
});
|
|
5124
5182
|
}
|
|
5125
5183
|
async createBlockedOrderOrPayment(params) {
|
|
5126
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5127
5184
|
const { checkout, blockType, type, limiteRange, card = null } = params;
|
|
5128
5185
|
return this.create(OrderBlocked.toInstance({
|
|
5129
5186
|
customer: {
|
|
5130
|
-
name:
|
|
5131
|
-
cpf:
|
|
5132
|
-
id:
|
|
5133
|
-
email:
|
|
5134
|
-
phoneNumber: '+55' +
|
|
5135
|
-
isSubscriber:
|
|
5136
|
-
subscriptionPlan:
|
|
5137
|
-
shippingAddress:
|
|
5187
|
+
name: checkout.user?.displayName || '',
|
|
5188
|
+
cpf: checkout.user?.cpf || '',
|
|
5189
|
+
id: checkout.user?.id,
|
|
5190
|
+
email: checkout.user?.email || '',
|
|
5191
|
+
phoneNumber: '+55' + checkout.user?.phone,
|
|
5192
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
5193
|
+
subscriptionPlan: checkout.user?.subscriptionPlan || '',
|
|
5194
|
+
shippingAddress: {
|
|
5195
|
+
...checkout.shippingAddress,
|
|
5196
|
+
zip: this.formatZip(checkout.shippingAddress?.zip),
|
|
5197
|
+
},
|
|
5138
5198
|
},
|
|
5139
5199
|
blockType,
|
|
5140
5200
|
limiteRange,
|
|
@@ -5382,7 +5442,7 @@ class ConnectDocumentService {
|
|
|
5382
5442
|
this.reference = firestore.doc(this.firestore, this.path).withConverter({
|
|
5383
5443
|
toFirestore: (data) => data,
|
|
5384
5444
|
fromFirestore: (snapshot) => {
|
|
5385
|
-
return
|
|
5445
|
+
return { id: snapshot.id, ...snapshot.data() };
|
|
5386
5446
|
},
|
|
5387
5447
|
});
|
|
5388
5448
|
}
|
|
@@ -5420,7 +5480,7 @@ class ConnectCollectionService {
|
|
|
5420
5480
|
this.reference = firestore.collection(firestore$1, path).withConverter({
|
|
5421
5481
|
toFirestore: (data) => data,
|
|
5422
5482
|
fromFirestore: (snapshot) => {
|
|
5423
|
-
return
|
|
5483
|
+
return { id: snapshot.id, ...snapshot.data() };
|
|
5424
5484
|
},
|
|
5425
5485
|
});
|
|
5426
5486
|
}
|
|
@@ -5515,10 +5575,10 @@ class FirebaseFileUploaderService {
|
|
|
5515
5575
|
function createCreateHasuraGraphQLClass(MixinBase) {
|
|
5516
5576
|
return class CreateHasuraGraphQLMixin extends MixinBase {
|
|
5517
5577
|
constructor(...params) {
|
|
5518
|
-
const options = params
|
|
5578
|
+
const options = params?.[0];
|
|
5519
5579
|
super(...params);
|
|
5520
|
-
this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options
|
|
5521
|
-
this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options
|
|
5580
|
+
this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options?.insertGraphQLOperation);
|
|
5581
|
+
this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options?.insertGraphQLObjectType);
|
|
5522
5582
|
}
|
|
5523
5583
|
async create(data) {
|
|
5524
5584
|
return HasuraCreateOperationsHelper.executeCreate(data, {
|
|
@@ -5545,9 +5605,9 @@ function createCreateHasuraGraphQLClass(MixinBase) {
|
|
|
5545
5605
|
function createDeleteHasuraGraphQLClass(MixinBase) {
|
|
5546
5606
|
return class DeleteHasuraGraphQLMixin extends MixinBase {
|
|
5547
5607
|
constructor(...params) {
|
|
5548
|
-
const options = params
|
|
5608
|
+
const options = params?.[0];
|
|
5549
5609
|
super(...params);
|
|
5550
|
-
this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options
|
|
5610
|
+
this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options?.deleteGraphQLOperation);
|
|
5551
5611
|
}
|
|
5552
5612
|
async delete(identifiers) {
|
|
5553
5613
|
await HasuraDeleteOperationsHelper.executeDelete({
|
|
@@ -5593,9 +5653,9 @@ function createFindHasuraGraphQLClass(MixinBase) {
|
|
|
5593
5653
|
function createGetHasuraGraphQLClass(MixinBase) {
|
|
5594
5654
|
return class GetHasuraGraphQLMixin extends MixinBase {
|
|
5595
5655
|
constructor(...params) {
|
|
5596
|
-
const options = params
|
|
5656
|
+
const options = params?.[0];
|
|
5597
5657
|
super(...params);
|
|
5598
|
-
this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options
|
|
5658
|
+
this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options?.getGraphQLOperation);
|
|
5599
5659
|
}
|
|
5600
5660
|
generateCacheKey(identifiers) {
|
|
5601
5661
|
return HasuraGetCacheHelper.generateCacheKey(this.model, identifiers);
|
|
@@ -5671,11 +5731,11 @@ function createHasuraGraphQLClass(MixinBase) {
|
|
|
5671
5731
|
function createUpdateHasuraGraphQLClass(MixinBase) {
|
|
5672
5732
|
return class UpdateHasuraGraphQLMixin extends MixinBase {
|
|
5673
5733
|
constructor(...params) {
|
|
5674
|
-
const options = params
|
|
5734
|
+
const options = params?.[0];
|
|
5675
5735
|
super(...params);
|
|
5676
|
-
this.updateGraphQLOperation =
|
|
5677
|
-
this.updateGraphQLObjectType =
|
|
5678
|
-
this.updateGraphQLPKType =
|
|
5736
|
+
this.updateGraphQLOperation = options?.updateGraphQLOperation || `update_${this.tableName}_by_pk`;
|
|
5737
|
+
this.updateGraphQLObjectType = options?.updateGraphQLObjectType || `${this.tableName}_set_input`;
|
|
5738
|
+
this.updateGraphQLPKType = options?.updateGraphQLPKType || `${this.tableName}_pk_columns_input`;
|
|
5679
5739
|
}
|
|
5680
5740
|
getIdentifiersFromData(data) {
|
|
5681
5741
|
return HasuraUpdateDataHelper.getIdentifiersFromData(data, this.model);
|
|
@@ -5865,7 +5925,7 @@ const fieldsConfiguration$5 = [
|
|
|
5865
5925
|
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
5866
5926
|
}),
|
|
5867
5927
|
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
5868
|
-
from: (categories) =>
|
|
5928
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
5869
5929
|
},
|
|
5870
5930
|
},
|
|
5871
5931
|
],
|
|
@@ -5946,8 +6006,7 @@ class CategoryCacheOperationsHelper {
|
|
|
5946
6006
|
logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5947
6007
|
}
|
|
5948
6008
|
static shouldUseCache(cacheAdapter, optionsCache) {
|
|
5949
|
-
|
|
5950
|
-
return !!(cacheAdapter && ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.enabled));
|
|
6009
|
+
return !!(cacheAdapter && optionsCache?.cache?.enabled);
|
|
5951
6010
|
}
|
|
5952
6011
|
}
|
|
5953
6012
|
|
|
@@ -6115,19 +6174,25 @@ class CategoryProductOperationsHelper {
|
|
|
6115
6174
|
}
|
|
6116
6175
|
static buildProductQuery(params) {
|
|
6117
6176
|
const { productIds, fields, hasStock, limit } = params;
|
|
6118
|
-
return
|
|
6177
|
+
return {
|
|
6178
|
+
filters: this.buildProductFilters(productIds, hasStock),
|
|
6179
|
+
...(limit ? { limits: { limit } } : {}),
|
|
6180
|
+
fields,
|
|
6181
|
+
options: { enableCount: false },
|
|
6182
|
+
orderBy: {
|
|
6119
6183
|
stock: 'desc',
|
|
6120
6184
|
shoppingCount: 'desc',
|
|
6121
6185
|
rate: 'desc',
|
|
6122
6186
|
name: 'asc',
|
|
6123
|
-
}
|
|
6187
|
+
},
|
|
6188
|
+
};
|
|
6124
6189
|
}
|
|
6125
6190
|
static getGenderParam(shop) {
|
|
6126
6191
|
return shop === exports.Shops.MENSMARKET ? 'male' : 'female';
|
|
6127
6192
|
}
|
|
6128
6193
|
static async fetchMostRelevantProducts(params) {
|
|
6129
6194
|
const { productRepository, mostRelevantsIds, fields, shop, hasStock, optionsCache } = params;
|
|
6130
|
-
if (!
|
|
6195
|
+
if (!mostRelevantsIds?.length)
|
|
6131
6196
|
return [];
|
|
6132
6197
|
const query = this.buildProductQuery({ productIds: mostRelevantsIds, fields, hasStock });
|
|
6133
6198
|
const { data } = await productRepository.findCatalog(query, this.getGenderParam(shop), optionsCache);
|
|
@@ -6156,9 +6221,8 @@ class CategoryProductOperationsHelper {
|
|
|
6156
6221
|
|
|
6157
6222
|
class CategoryMountOperationsHelper {
|
|
6158
6223
|
static async executeMount(params, dependencies) {
|
|
6159
|
-
var _a;
|
|
6160
6224
|
const { category, shop, options = {}, optionsCache } = params;
|
|
6161
|
-
if (!
|
|
6225
|
+
if (!category?.products?.length)
|
|
6162
6226
|
return [];
|
|
6163
6227
|
const cachedResult = await this.tryGetFromCache({
|
|
6164
6228
|
category,
|
|
@@ -6256,7 +6320,6 @@ class CategoryMountOperationsHelper {
|
|
|
6256
6320
|
return result;
|
|
6257
6321
|
}
|
|
6258
6322
|
static async saveToCacheIfNeeded(params) {
|
|
6259
|
-
var _a;
|
|
6260
6323
|
const { category, shop, options, optionsCache, result, dependencies } = params;
|
|
6261
6324
|
const shouldUseCache = CategoryCacheOperationsHelper.shouldUseCache(dependencies.cacheAdapter, optionsCache);
|
|
6262
6325
|
if (!shouldUseCache)
|
|
@@ -6266,7 +6329,7 @@ class CategoryMountOperationsHelper {
|
|
|
6266
6329
|
cacheAdapter: dependencies.cacheAdapter,
|
|
6267
6330
|
cacheKey,
|
|
6268
6331
|
products: result,
|
|
6269
|
-
ttl:
|
|
6332
|
+
ttl: optionsCache?.cache?.ttl || dependencies.defaultCacheTtl,
|
|
6270
6333
|
logger: dependencies.logger,
|
|
6271
6334
|
});
|
|
6272
6335
|
}
|
|
@@ -6292,7 +6355,12 @@ class ProductFetchReviewsHelper {
|
|
|
6292
6355
|
...reviews,
|
|
6293
6356
|
...product.reviews
|
|
6294
6357
|
.filter((review) => this.matchesStatus(review, status))
|
|
6295
|
-
.map((review) => (
|
|
6358
|
+
.map((review) => ({
|
|
6359
|
+
...bindReviewToModel(review),
|
|
6360
|
+
productId: product.id,
|
|
6361
|
+
productName: product.name,
|
|
6362
|
+
productSku: product.sku,
|
|
6363
|
+
})),
|
|
6296
6364
|
], []);
|
|
6297
6365
|
}
|
|
6298
6366
|
static matchesStatus(review, status) {
|
|
@@ -6339,8 +6407,7 @@ class ProductReviewCacheHelper {
|
|
|
6339
6407
|
dependencies.logger.log(`Dados salvos no cache: ${key}`);
|
|
6340
6408
|
}
|
|
6341
6409
|
static shouldUseCache(cacheAdapter, options) {
|
|
6342
|
-
|
|
6343
|
-
return !!(cacheAdapter && ((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled));
|
|
6410
|
+
return !!(cacheAdapter && options?.cache?.enabled);
|
|
6344
6411
|
}
|
|
6345
6412
|
}
|
|
6346
6413
|
|
|
@@ -6351,9 +6418,12 @@ class ProductReviewOperationsHelper {
|
|
|
6351
6418
|
let count = 0;
|
|
6352
6419
|
let offset = 0;
|
|
6353
6420
|
do {
|
|
6354
|
-
const result = await repository.find(
|
|
6355
|
-
|
|
6356
|
-
|
|
6421
|
+
const result = await repository.find({
|
|
6422
|
+
fields: ['id', 'name', 'sku', 'reviews'],
|
|
6423
|
+
...(limit && {
|
|
6424
|
+
limits: { offset, limit },
|
|
6425
|
+
}),
|
|
6426
|
+
});
|
|
6357
6427
|
data = data.concat(result.data);
|
|
6358
6428
|
count = result.data.length;
|
|
6359
6429
|
offset += limit;
|
|
@@ -6364,7 +6434,13 @@ class ProductReviewOperationsHelper {
|
|
|
6364
6434
|
const { data, getReviewStatus } = params;
|
|
6365
6435
|
return data.reduce((reviews, product) => [
|
|
6366
6436
|
...reviews,
|
|
6367
|
-
...product.reviews.map((review) => (
|
|
6437
|
+
...product.reviews.map((review) => ({
|
|
6438
|
+
...review,
|
|
6439
|
+
reviewStatus: getReviewStatus(review),
|
|
6440
|
+
productId: product.id,
|
|
6441
|
+
productName: product.name,
|
|
6442
|
+
productSku: product.sku,
|
|
6443
|
+
})),
|
|
6368
6444
|
], []);
|
|
6369
6445
|
}
|
|
6370
6446
|
static applyReviewFilters(params) {
|
|
@@ -6408,7 +6484,7 @@ class ProductReviewUpdateHelper {
|
|
|
6408
6484
|
const { productId, reviews, dependencies } = params;
|
|
6409
6485
|
const reviewIds = await Promise.all(reviews.value.map(async (reviewData) => {
|
|
6410
6486
|
const review = await dependencies.findReview(reviewData, productId);
|
|
6411
|
-
return review
|
|
6487
|
+
return review?.id;
|
|
6412
6488
|
}));
|
|
6413
6489
|
await dependencies.mutation('delete_product_review', ['affected_rows'], {
|
|
6414
6490
|
where: {
|
|
@@ -6447,7 +6523,7 @@ class ProductReviewUpdateHelper {
|
|
|
6447
6523
|
static async insertNewReview(reviewData, productId, dependencies) {
|
|
6448
6524
|
const result = await dependencies.mutation('insert_product_review_one', dependencies.reviewsFields, {
|
|
6449
6525
|
object: {
|
|
6450
|
-
value: lodash.omit(
|
|
6526
|
+
value: lodash.omit({ ...dependencies.bindReviewToHasura(reviewData), product_id: productId.toString() }, ['id']),
|
|
6451
6527
|
type: 'product_review_insert_input',
|
|
6452
6528
|
required: true,
|
|
6453
6529
|
},
|
|
@@ -6540,11 +6616,14 @@ const fieldsConfiguration$4 = [
|
|
|
6540
6616
|
bindPersistData: (value) => {
|
|
6541
6617
|
return {
|
|
6542
6618
|
brand_condition: value.brand,
|
|
6543
|
-
tag_condition:
|
|
6619
|
+
tag_condition: value?.tags || [],
|
|
6544
6620
|
};
|
|
6545
6621
|
},
|
|
6546
6622
|
bindFindFilter: (sentence) => {
|
|
6547
|
-
return
|
|
6623
|
+
return {
|
|
6624
|
+
...(sentence.brand ? { brand_condition: sentence.brand } : {}),
|
|
6625
|
+
...(sentence.tags ? { tag_condition: sentence.tags } : {}),
|
|
6626
|
+
};
|
|
6548
6627
|
},
|
|
6549
6628
|
},
|
|
6550
6629
|
},
|
|
@@ -6556,7 +6635,7 @@ const fieldsConfiguration$4 = [
|
|
|
6556
6635
|
bindPersistData: (value) => ({
|
|
6557
6636
|
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
6558
6637
|
}),
|
|
6559
|
-
from: (filters) =>
|
|
6638
|
+
from: (filters) => filters?.map((filter) => filter?.filter).filter((filter) => filter.enabled) || [],
|
|
6560
6639
|
},
|
|
6561
6640
|
},
|
|
6562
6641
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -6621,11 +6700,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6621
6700
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
6622
6701
|
}
|
|
6623
6702
|
async create(params) {
|
|
6624
|
-
const { images, mostRelevants, metadatas
|
|
6625
|
-
return super.create(
|
|
6703
|
+
const { images, mostRelevants, metadatas, ...data } = params;
|
|
6704
|
+
return super.create({
|
|
6705
|
+
...data,
|
|
6706
|
+
isWishlist: false,
|
|
6707
|
+
metadatas: metadatas || [{ shop: null, description: null, title: null }],
|
|
6708
|
+
mostRelevants: mostRelevants || {
|
|
6626
6709
|
[exports.Shops.GLAMSHOP]: null,
|
|
6627
6710
|
[exports.Shops.MENSMARKET]: null,
|
|
6628
|
-
},
|
|
6711
|
+
},
|
|
6712
|
+
images: images || {
|
|
6629
6713
|
[exports.Shops.GLAMSHOP]: {
|
|
6630
6714
|
brandBanner: null,
|
|
6631
6715
|
brandBannerMobile: null,
|
|
@@ -6636,17 +6720,18 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6636
6720
|
brandBannerMobile: null,
|
|
6637
6721
|
image: null,
|
|
6638
6722
|
},
|
|
6639
|
-
}
|
|
6723
|
+
},
|
|
6724
|
+
});
|
|
6640
6725
|
}
|
|
6641
6726
|
async get(identifiers, optionsCache) {
|
|
6642
6727
|
const id = await this.getId(identifiers.id);
|
|
6643
6728
|
return super.get({ id }, optionsCache);
|
|
6644
6729
|
}
|
|
6645
6730
|
async update(params) {
|
|
6646
|
-
const { id, products, metadatas, filters
|
|
6731
|
+
const { id, products, metadatas, filters, ...data } = params;
|
|
6647
6732
|
const categoryId = +(await this.getId(id));
|
|
6648
6733
|
const [category] = await Promise.all([
|
|
6649
|
-
super.update(
|
|
6734
|
+
super.update({ id: categoryId?.toString(), ...data }),
|
|
6650
6735
|
...(products ? [this.updateProducts(categoryId, { products })] : []),
|
|
6651
6736
|
...(metadatas ? [this.updateMetadata(categoryId, { metadatas })] : []),
|
|
6652
6737
|
...(filters ? [this.updateFilters(categoryId, { filters })] : []),
|
|
@@ -6686,7 +6771,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6686
6771
|
}
|
|
6687
6772
|
async getCategoriesForHome(params) {
|
|
6688
6773
|
const { categoryIds, shop, limit = 4, optionsCache } = params;
|
|
6689
|
-
if (!
|
|
6774
|
+
if (!categoryIds?.length)
|
|
6690
6775
|
return [];
|
|
6691
6776
|
const { firestore, hasura } = CategoryHomeOperationsHelper.separateCategoryIds(categoryIds);
|
|
6692
6777
|
const categories = [];
|
|
@@ -6707,11 +6792,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6707
6792
|
});
|
|
6708
6793
|
}
|
|
6709
6794
|
async mountCategory(params) {
|
|
6710
|
-
var _a, _b;
|
|
6711
6795
|
return CategoryMountOperationsHelper.executeMount(params, {
|
|
6712
6796
|
productRepository: this.productRepository,
|
|
6713
|
-
cacheAdapter:
|
|
6714
|
-
defaultCacheTtl:
|
|
6797
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
6798
|
+
defaultCacheTtl: this.cache?.ttlDefault,
|
|
6715
6799
|
logger: this.logger,
|
|
6716
6800
|
});
|
|
6717
6801
|
}
|
|
@@ -6730,12 +6814,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6730
6814
|
return categoryTree.some((c) => c.id == id.toString());
|
|
6731
6815
|
}
|
|
6732
6816
|
async getId(id) {
|
|
6733
|
-
var _a, _b;
|
|
6734
6817
|
if (!Number.isNaN(+id))
|
|
6735
6818
|
return id;
|
|
6736
6819
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
6737
|
-
if (
|
|
6738
|
-
return
|
|
6820
|
+
if (data?.[0]?.id)
|
|
6821
|
+
return data?.[0]?.id;
|
|
6739
6822
|
throw new NotFoundError(`Category with id ${id} not found`);
|
|
6740
6823
|
}
|
|
6741
6824
|
async updateProducts(categoryId, { products }) {
|
|
@@ -6789,7 +6872,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6789
6872
|
objects: {
|
|
6790
6873
|
type: '[category_metadata_insert_input!]',
|
|
6791
6874
|
required: true,
|
|
6792
|
-
value: metadatas.map((m) => (
|
|
6875
|
+
value: metadatas.map((m) => ({ category_id: categoryId, ...m })),
|
|
6793
6876
|
},
|
|
6794
6877
|
});
|
|
6795
6878
|
return metadatas;
|
|
@@ -6955,7 +7038,7 @@ const fieldsConfiguration$3 = [
|
|
|
6955
7038
|
bindPersistData: (value) => ({
|
|
6956
7039
|
categories: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
6957
7040
|
}),
|
|
6958
|
-
from: (categories) =>
|
|
7041
|
+
from: (categories) => categories?.map((category) => category?.category) || [],
|
|
6959
7042
|
},
|
|
6960
7043
|
},
|
|
6961
7044
|
];
|
|
@@ -6974,7 +7057,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6974
7057
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
6975
7058
|
}
|
|
6976
7059
|
async update(params) {
|
|
6977
|
-
const { options
|
|
7060
|
+
const { options, ...data } = params;
|
|
6978
7061
|
const filter = await super.update(data);
|
|
6979
7062
|
filter.options = await this.updateOptions(+data.id, { options });
|
|
6980
7063
|
return filter;
|
|
@@ -6996,8 +7079,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6996
7079
|
if (hasFilter)
|
|
6997
7080
|
filterOptions.push(hasFilter);
|
|
6998
7081
|
}
|
|
6999
|
-
catch
|
|
7000
|
-
const newOption = await this.filterOptionRepository.create(
|
|
7082
|
+
catch {
|
|
7083
|
+
const newOption = await this.filterOptionRepository.create({ ...options.value[i], filterId });
|
|
7001
7084
|
filterOptions.push(newOption);
|
|
7002
7085
|
}
|
|
7003
7086
|
}
|
|
@@ -7011,8 +7094,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
7011
7094
|
if (hasFilter)
|
|
7012
7095
|
filterOptions.push(hasFilter);
|
|
7013
7096
|
}
|
|
7014
|
-
catch
|
|
7015
|
-
const newOption = await this.filterOptionRepository.create(
|
|
7097
|
+
catch {
|
|
7098
|
+
const newOption = await this.filterOptionRepository.create({ ...options[i], filterId });
|
|
7016
7099
|
filterOptions.push(newOption);
|
|
7017
7100
|
}
|
|
7018
7101
|
}
|
|
@@ -7133,13 +7216,13 @@ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
|
|
|
7133
7216
|
filters: {
|
|
7134
7217
|
id: {
|
|
7135
7218
|
operator: exports.Where.IN,
|
|
7136
|
-
value: Array.from(new Set(variantsWithNoData.map((item) =>
|
|
7219
|
+
value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
|
|
7137
7220
|
},
|
|
7138
7221
|
},
|
|
7139
7222
|
});
|
|
7140
7223
|
products.forEach((product) => {
|
|
7141
7224
|
result.data
|
|
7142
|
-
.filter((variant) =>
|
|
7225
|
+
.filter((variant) => variant.product.productId?.toString() === product.id.toString())
|
|
7143
7226
|
.forEach((variant) => {
|
|
7144
7227
|
variant.product.name = product.name;
|
|
7145
7228
|
variant.product.group = product.group;
|
|
@@ -7172,21 +7255,37 @@ const commonFields = [
|
|
|
7172
7255
|
purpose: data.purpose,
|
|
7173
7256
|
}),
|
|
7174
7257
|
bindFindFilter: (filters) => {
|
|
7175
|
-
return
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7258
|
+
return {
|
|
7259
|
+
...(filters?.description && { description: filters.description }),
|
|
7260
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
7261
|
+
...(filters.whoMustUse && {
|
|
7262
|
+
who_must_use: filters.whoMustUse,
|
|
7263
|
+
}),
|
|
7264
|
+
...(filters.howToUse && {
|
|
7265
|
+
how_to_use: filters.howToUse,
|
|
7266
|
+
}),
|
|
7267
|
+
...(filters.brand && {
|
|
7268
|
+
brand_description: filters.brand,
|
|
7269
|
+
}),
|
|
7270
|
+
...(filters.ingredients && {
|
|
7271
|
+
ingredients: filters.ingredients,
|
|
7272
|
+
}),
|
|
7273
|
+
...(filters.purpose && {
|
|
7274
|
+
purpose: filters.purpose,
|
|
7275
|
+
}),
|
|
7276
|
+
};
|
|
7186
7277
|
},
|
|
7187
|
-
bindPersistData: (descriptionData) => (
|
|
7188
|
-
|
|
7189
|
-
|
|
7278
|
+
bindPersistData: (descriptionData) => ({
|
|
7279
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
7280
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
7281
|
+
...(descriptionData.whoMustUse && {
|
|
7282
|
+
who_must_use: descriptionData.whoMustUse,
|
|
7283
|
+
}),
|
|
7284
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
7285
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
7286
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
7287
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
7288
|
+
}),
|
|
7190
7289
|
},
|
|
7191
7290
|
},
|
|
7192
7291
|
{ differentials: { columnName: 'differentials' } },
|
|
@@ -7199,13 +7298,13 @@ const commonFields = [
|
|
|
7199
7298
|
{
|
|
7200
7299
|
images: {
|
|
7201
7300
|
columnName: 'images',
|
|
7202
|
-
to: (value) =>
|
|
7301
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7203
7302
|
},
|
|
7204
7303
|
},
|
|
7205
7304
|
{
|
|
7206
7305
|
miniatures: {
|
|
7207
7306
|
columnName: 'miniatures',
|
|
7208
|
-
to: (value) =>
|
|
7307
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7209
7308
|
},
|
|
7210
7309
|
},
|
|
7211
7310
|
'name',
|
|
@@ -7220,19 +7319,31 @@ const commonFields = [
|
|
|
7220
7319
|
subscriberPrice: data.subscriber_price,
|
|
7221
7320
|
}),
|
|
7222
7321
|
bindFindFilter: (filters) => {
|
|
7223
|
-
return
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7322
|
+
return {
|
|
7323
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7324
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7325
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7326
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7327
|
+
}),
|
|
7328
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7329
|
+
subscriber_price: filters.subscriberPrice,
|
|
7330
|
+
}),
|
|
7331
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7332
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7333
|
+
}),
|
|
7334
|
+
};
|
|
7230
7335
|
},
|
|
7231
|
-
bindPersistData: (priceData) => (
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7336
|
+
bindPersistData: (priceData) => ({
|
|
7337
|
+
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
7338
|
+
...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
|
|
7339
|
+
...(priceData.subscriberDiscountPercentage >= 0 && {
|
|
7340
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
7341
|
+
}),
|
|
7342
|
+
...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
7343
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
7344
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
7345
|
+
}),
|
|
7346
|
+
}),
|
|
7236
7347
|
},
|
|
7237
7348
|
},
|
|
7238
7349
|
{ fullPrice: { columnName: 'full_price' } },
|
|
@@ -7247,7 +7358,7 @@ const commonFields = [
|
|
|
7247
7358
|
stock: {
|
|
7248
7359
|
columnName: 'stock',
|
|
7249
7360
|
from: (quantity) => ({ quantity }),
|
|
7250
|
-
to: (value) => (lodash.isNil(value
|
|
7361
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
7251
7362
|
},
|
|
7252
7363
|
},
|
|
7253
7364
|
{ hasStock: { columnName: 'has_stock' } },
|
|
@@ -7286,7 +7397,7 @@ const fieldsConfiguration$2 = [
|
|
|
7286
7397
|
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
7287
7398
|
}),
|
|
7288
7399
|
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
7289
|
-
from: (categories) =>
|
|
7400
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
7290
7401
|
},
|
|
7291
7402
|
},
|
|
7292
7403
|
{
|
|
@@ -7362,12 +7473,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7362
7473
|
fields: fieldsConfiguration$2,
|
|
7363
7474
|
cache,
|
|
7364
7475
|
});
|
|
7365
|
-
this.bindReviewToModel = (plain) => ProductReview.toInstance(
|
|
7366
|
-
|
|
7476
|
+
this.bindReviewToModel = (plain) => ProductReview.toInstance({
|
|
7477
|
+
...is(lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
|
|
7478
|
+
createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
|
|
7479
|
+
updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
|
|
7480
|
+
personId: plain.person_id,
|
|
7481
|
+
orderId: plain.order_id,
|
|
7482
|
+
});
|
|
7483
|
+
this.bindReviewToHasura = (review) => ({
|
|
7484
|
+
...is(lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
|
|
7485
|
+
person_id: review.personId,
|
|
7486
|
+
order_id: review.orderId,
|
|
7487
|
+
});
|
|
7367
7488
|
}
|
|
7368
7489
|
async create(params) {
|
|
7369
|
-
const { metadata
|
|
7370
|
-
const product = await super.create(lodash.omit(
|
|
7490
|
+
const { metadata, ...data } = params;
|
|
7491
|
+
const product = await super.create(lodash.omit({ ...data, metadata: metadata || { description: null, title: null } }, ['reviews']));
|
|
7371
7492
|
try {
|
|
7372
7493
|
product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
|
|
7373
7494
|
}
|
|
@@ -7378,10 +7499,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7378
7499
|
return product;
|
|
7379
7500
|
}
|
|
7380
7501
|
async get(identifiers, options) {
|
|
7381
|
-
var _a;
|
|
7382
7502
|
const product = Number.isNaN(+identifiers.id)
|
|
7383
|
-
? (
|
|
7384
|
-
.data
|
|
7503
|
+
? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
|
|
7504
|
+
.data?.[0]
|
|
7385
7505
|
: await super.get(identifiers, options);
|
|
7386
7506
|
if (product.productId)
|
|
7387
7507
|
throw new NotFoundError('Product not found, it is a variant');
|
|
@@ -7389,19 +7509,21 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7389
7509
|
return product;
|
|
7390
7510
|
}
|
|
7391
7511
|
async find(params, optionsParams) {
|
|
7392
|
-
|
|
7393
|
-
const _o = params || {}, { filters, fields } = _o, options = tslib.__rest(_o, ["filters", "fields"]);
|
|
7512
|
+
const { filters, fields, ...options } = params || {};
|
|
7394
7513
|
const bindFields = fields ||
|
|
7395
7514
|
this.fields
|
|
7396
7515
|
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
7397
7516
|
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
7398
|
-
if (
|
|
7399
|
-
|
|
7400
|
-
if (
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
return super.find(
|
|
7517
|
+
if (options.options?.minimal?.includes('price'))
|
|
7518
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7519
|
+
if (options.options?.maximum?.includes('price'))
|
|
7520
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7521
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
7522
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
7523
|
+
return super.find({
|
|
7524
|
+
...options,
|
|
7525
|
+
filters: { ...filters, productId: { operator: exports.Where.ISNULL } },
|
|
7526
|
+
fields: [
|
|
7405
7527
|
...bindFields,
|
|
7406
7528
|
...(bindFields.includes('price')
|
|
7407
7529
|
? [
|
|
@@ -7410,11 +7532,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7410
7532
|
'fullPrice',
|
|
7411
7533
|
]
|
|
7412
7534
|
: []),
|
|
7413
|
-
]
|
|
7535
|
+
],
|
|
7536
|
+
}, optionsParams);
|
|
7414
7537
|
}
|
|
7415
7538
|
async getBySlug(slug, options) {
|
|
7416
|
-
|
|
7417
|
-
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)) {
|
|
7539
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7418
7540
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
7419
7541
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7420
7542
|
if (cachedData) {
|
|
@@ -7433,70 +7555,68 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7433
7555
|
});
|
|
7434
7556
|
if (!result.data.length)
|
|
7435
7557
|
return null;
|
|
7436
|
-
const product =
|
|
7558
|
+
const product = result?.data?.shift();
|
|
7437
7559
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
7438
|
-
if (
|
|
7560
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7439
7561
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
7440
7562
|
await this.cache.cacheAdapter.set({
|
|
7441
7563
|
key: cacheKey,
|
|
7442
7564
|
data: serialize(product),
|
|
7443
|
-
expirationInSeconds:
|
|
7565
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7444
7566
|
});
|
|
7445
7567
|
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7446
7568
|
}
|
|
7447
7569
|
return product;
|
|
7448
7570
|
}
|
|
7449
7571
|
async update(params) {
|
|
7450
|
-
const
|
|
7572
|
+
const { kitProducts, reviews, id: checkId, metadata, ...data } = lodash.omit(params, ['categories', 'rate']);
|
|
7451
7573
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
7452
7574
|
const id = await this.getId(plainData.id);
|
|
7453
|
-
const product = await super.update(
|
|
7575
|
+
const product = await super.update({ id, ...data });
|
|
7454
7576
|
product.kitProducts = kitProducts && (await this.updateKitProducts(+id, { kitProducts }));
|
|
7455
7577
|
product.reviews = reviews && (await this.updateReviews(+id, { reviews }));
|
|
7456
7578
|
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
7457
7579
|
return product;
|
|
7458
7580
|
}
|
|
7459
7581
|
async fetchProductReviews(filters, options) {
|
|
7460
|
-
var _a, _b, _c, _d, _e;
|
|
7461
7582
|
const cacheKey = ProductReviewCacheHelper.generateProductReviewsCacheKey(filters, this.model.name);
|
|
7462
7583
|
const dependencies = {
|
|
7463
|
-
cacheAdapter:
|
|
7584
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
7464
7585
|
logger: this.logger,
|
|
7465
7586
|
modelName: this.model.name,
|
|
7466
|
-
defaultTtl:
|
|
7587
|
+
defaultTtl: this.cache?.ttlDefault,
|
|
7467
7588
|
};
|
|
7468
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7589
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7469
7590
|
const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
|
|
7470
7591
|
if (cachedData)
|
|
7471
7592
|
return cachedData;
|
|
7472
7593
|
}
|
|
7473
|
-
const limit =
|
|
7594
|
+
const limit = filters?.limit || 500;
|
|
7474
7595
|
const data = await ProductReviewOperationsHelper.fetchAllProductsWithReviews({ repository: this, limit });
|
|
7475
7596
|
const reviews = ProductReviewOperationsHelper.processProductsToReviews({
|
|
7476
7597
|
data,
|
|
7477
7598
|
getReviewStatus: this.getReviewStatus.bind(this),
|
|
7478
7599
|
});
|
|
7479
7600
|
const filteredReviews = ProductReviewOperationsHelper.applyReviewFilters({ reviews, filters });
|
|
7480
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7601
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7481
7602
|
await ProductReviewCacheHelper.saveToCache({
|
|
7482
7603
|
key: cacheKey,
|
|
7483
7604
|
data: filteredReviews,
|
|
7484
|
-
ttl:
|
|
7605
|
+
ttl: options?.cache?.ttl,
|
|
7485
7606
|
dependencies,
|
|
7486
7607
|
});
|
|
7487
7608
|
}
|
|
7488
7609
|
return filteredReviews;
|
|
7489
7610
|
}
|
|
7490
7611
|
async fetchReviews(status, options) {
|
|
7491
|
-
var _a, _b, _c, _d, _e;
|
|
7492
7612
|
const cacheKey = ProductReviewCacheHelper.generateReviewsStatusCacheKey(status, this.model.name);
|
|
7493
7613
|
const dependencies = {
|
|
7494
|
-
cacheAdapter:
|
|
7614
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
7495
7615
|
logger: this.logger,
|
|
7496
7616
|
modelName: this.model.name,
|
|
7497
|
-
defaultTtl:
|
|
7617
|
+
defaultTtl: this.cache?.ttlDefault,
|
|
7498
7618
|
};
|
|
7499
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7619
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7500
7620
|
const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
|
|
7501
7621
|
if (cachedData)
|
|
7502
7622
|
return cachedData;
|
|
@@ -7507,18 +7627,26 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7507
7627
|
reviewsFields: this.reviewsFields,
|
|
7508
7628
|
};
|
|
7509
7629
|
const reviews = await ProductFetchReviewsHelper.executeQuery(status, fetchDependencies);
|
|
7510
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7630
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7511
7631
|
await ProductReviewCacheHelper.saveToCache({
|
|
7512
7632
|
key: cacheKey,
|
|
7513
7633
|
data: reviews,
|
|
7514
|
-
ttl:
|
|
7634
|
+
ttl: options?.cache?.ttl,
|
|
7515
7635
|
dependencies,
|
|
7516
7636
|
});
|
|
7517
7637
|
}
|
|
7518
7638
|
return reviews;
|
|
7519
7639
|
}
|
|
7520
7640
|
async findCatalog(params, mainGender, options) {
|
|
7521
|
-
const result = await this.find(
|
|
7641
|
+
const result = await this.find({
|
|
7642
|
+
...params,
|
|
7643
|
+
filters: { ...params.filters, published: true },
|
|
7644
|
+
orderBy: {
|
|
7645
|
+
hasStock: 'desc',
|
|
7646
|
+
...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
|
|
7647
|
+
...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
|
|
7648
|
+
},
|
|
7649
|
+
}, options);
|
|
7522
7650
|
return result;
|
|
7523
7651
|
}
|
|
7524
7652
|
async cleanShoppingCountFromIds(ids) {
|
|
@@ -7589,17 +7717,15 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7589
7717
|
return plainData.metadata;
|
|
7590
7718
|
}
|
|
7591
7719
|
async getId(id) {
|
|
7592
|
-
var _a, _b;
|
|
7593
7720
|
if (!Number.isNaN(+id))
|
|
7594
7721
|
return id;
|
|
7595
7722
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
7596
|
-
if (
|
|
7597
|
-
return
|
|
7723
|
+
if (data?.[0]?.id)
|
|
7724
|
+
return data?.[0]?.id;
|
|
7598
7725
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7599
7726
|
}
|
|
7600
7727
|
async findReviewsByProduct(productId, options) {
|
|
7601
|
-
|
|
7602
|
-
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)) {
|
|
7728
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7603
7729
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7604
7730
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7605
7731
|
if (cachedData) {
|
|
@@ -7616,13 +7742,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7616
7742
|
required: true,
|
|
7617
7743
|
},
|
|
7618
7744
|
});
|
|
7619
|
-
const reviews = data
|
|
7620
|
-
if (
|
|
7745
|
+
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
7746
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
7621
7747
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7622
7748
|
await this.cache.cacheAdapter.set({
|
|
7623
7749
|
key: cacheKey,
|
|
7624
7750
|
data: serialize(reviews),
|
|
7625
|
-
expirationInSeconds:
|
|
7751
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7626
7752
|
});
|
|
7627
7753
|
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7628
7754
|
}
|
|
@@ -7646,23 +7772,32 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7646
7772
|
async getReviewByPersonId(personId, productId, orderId) {
|
|
7647
7773
|
const { product_review: data } = await this.query('product_review', this.reviewsFields, {
|
|
7648
7774
|
where: {
|
|
7649
|
-
value:
|
|
7775
|
+
value: {
|
|
7776
|
+
product_id: { _eq: productId },
|
|
7777
|
+
person_id: { _eq: personId },
|
|
7778
|
+
...(orderId && { order_id: { _eq: orderId } }),
|
|
7779
|
+
},
|
|
7650
7780
|
type: 'product_review_bool_exp',
|
|
7651
7781
|
required: true,
|
|
7652
7782
|
},
|
|
7653
7783
|
});
|
|
7654
|
-
return
|
|
7784
|
+
return data?.[0] && this.bindReviewToModel(data[0]);
|
|
7655
7785
|
}
|
|
7656
7786
|
async getReviewByAuthorAndEmail(params) {
|
|
7657
7787
|
const { author, email, productId, orderId } = params;
|
|
7658
7788
|
const { product_review: data } = await this.query('product_review', this.reviewsFields, {
|
|
7659
7789
|
where: {
|
|
7660
|
-
value:
|
|
7790
|
+
value: {
|
|
7791
|
+
product_id: { _eq: productId },
|
|
7792
|
+
author: { _eq: author },
|
|
7793
|
+
email: { _eq: email },
|
|
7794
|
+
...(orderId && { order_id: { _eq: orderId } }),
|
|
7795
|
+
},
|
|
7661
7796
|
type: 'product_review_bool_exp',
|
|
7662
7797
|
required: true,
|
|
7663
7798
|
},
|
|
7664
7799
|
});
|
|
7665
|
-
return
|
|
7800
|
+
return data?.[0] && this.bindReviewToModel(data[0]);
|
|
7666
7801
|
}
|
|
7667
7802
|
async productVariantFullReport() {
|
|
7668
7803
|
const dependencies = {
|
|
@@ -7811,7 +7946,16 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
|
|
|
7811
7946
|
});
|
|
7812
7947
|
}
|
|
7813
7948
|
async getNotificationsReport(params, orderBy, pagination) {
|
|
7814
|
-
const query =
|
|
7949
|
+
const query = {
|
|
7950
|
+
...(params.productId && { product_id: { _eq: params.productId } }),
|
|
7951
|
+
...(params.ean && { ean: { _eq: params.ean } }),
|
|
7952
|
+
...(params.sku && { sku: { _eq: params.sku } }),
|
|
7953
|
+
...(params.name && { name: { _iregex: params.name } }),
|
|
7954
|
+
...(params.categoryId && { category_id: { _eq: params.categoryId } }),
|
|
7955
|
+
...(params.category && { category: { _iregex: params.category } }),
|
|
7956
|
+
...(params.reference && { category_reference: { _eq: params.reference } }),
|
|
7957
|
+
...(params.emailsCount && { emails_registered: { _eq: params.emailsCount } }),
|
|
7958
|
+
};
|
|
7815
7959
|
const orderByField = {
|
|
7816
7960
|
[orderBy.field]: orderBy.direction,
|
|
7817
7961
|
};
|
|
@@ -7827,8 +7971,8 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
|
|
|
7827
7971
|
required: true,
|
|
7828
7972
|
},
|
|
7829
7973
|
});
|
|
7830
|
-
const data =
|
|
7831
|
-
? reportStockNotification.slice(pagination
|
|
7974
|
+
const data = pagination?.limit
|
|
7975
|
+
? reportStockNotification.slice(pagination?.offset, pagination?.offset + pagination?.limit)
|
|
7832
7976
|
: reportStockNotification;
|
|
7833
7977
|
return {
|
|
7834
7978
|
data,
|
|
@@ -7844,7 +7988,7 @@ const fieldsConfiguration$1 = [
|
|
|
7844
7988
|
productId: {
|
|
7845
7989
|
columnName: 'main_product_id',
|
|
7846
7990
|
to: (value) => +value,
|
|
7847
|
-
from: (value) => value
|
|
7991
|
+
from: (value) => value?.toString(),
|
|
7848
7992
|
},
|
|
7849
7993
|
},
|
|
7850
7994
|
{ EAN: { columnName: 'ean' } },
|
|
@@ -7861,19 +8005,31 @@ const fieldsConfiguration$1 = [
|
|
|
7861
8005
|
}),
|
|
7862
8006
|
bindFindFilter: (sentence) => {
|
|
7863
8007
|
const filters = Object.values(sentence).shift();
|
|
7864
|
-
return
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
8008
|
+
return {
|
|
8009
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
8010
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
8011
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
8012
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
8013
|
+
}),
|
|
8014
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
8015
|
+
subscriber_price: filters.subscriberPrice,
|
|
8016
|
+
}),
|
|
8017
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
8018
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
8019
|
+
}),
|
|
8020
|
+
};
|
|
7871
8021
|
},
|
|
7872
|
-
bindPersistData: (priceData) => (
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
8022
|
+
bindPersistData: (priceData) => ({
|
|
8023
|
+
...((priceData?.price || 0) >= 0 && { price: priceData.price }),
|
|
8024
|
+
...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
|
|
8025
|
+
...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
|
|
8026
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
8027
|
+
}),
|
|
8028
|
+
...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
8029
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
8030
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
8031
|
+
}),
|
|
8032
|
+
}),
|
|
7877
8033
|
},
|
|
7878
8034
|
},
|
|
7879
8035
|
{ fullPrice: { columnName: 'full_price' } },
|
|
@@ -7885,7 +8041,7 @@ const fieldsConfiguration$1 = [
|
|
|
7885
8041
|
stock: {
|
|
7886
8042
|
columnName: 'stock',
|
|
7887
8043
|
from: (quantity) => ({ quantity }),
|
|
7888
|
-
to: (value) => (lodash.isNil(value
|
|
8044
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
7889
8045
|
},
|
|
7890
8046
|
},
|
|
7891
8047
|
{ hasStock: { columnName: 'has_stock' } },
|
|
@@ -7918,41 +8074,39 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7918
8074
|
});
|
|
7919
8075
|
}
|
|
7920
8076
|
async get(identifiers) {
|
|
7921
|
-
var _a;
|
|
7922
8077
|
if (!identifiers.id) {
|
|
7923
8078
|
throw new NotFoundError('Variant ID is required');
|
|
7924
8079
|
}
|
|
7925
8080
|
const variant = Number.isNaN(+identifiers.id)
|
|
7926
|
-
? (
|
|
8081
|
+
? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
|
|
7927
8082
|
: await super.get(identifiers);
|
|
7928
8083
|
if (!variant.productId)
|
|
7929
8084
|
throw new NotFoundError('Variant not found, it is a product');
|
|
7930
8085
|
return variant;
|
|
7931
8086
|
}
|
|
7932
8087
|
async find(params) {
|
|
7933
|
-
const
|
|
7934
|
-
return super.find(
|
|
8088
|
+
const { filters, ...options } = params || {};
|
|
8089
|
+
return super.find({ ...options, filters: { productId: { operator: exports.Where.ISNOTNULL }, ...filters } });
|
|
7935
8090
|
}
|
|
7936
8091
|
async update(params) {
|
|
7937
|
-
const { productId, id: checkId
|
|
8092
|
+
const { productId, id: checkId, ...data } = params;
|
|
7938
8093
|
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
7939
8094
|
if (!dataWithProductId.id) {
|
|
7940
8095
|
throw new NotFoundError('Variant ID is required for update');
|
|
7941
8096
|
}
|
|
7942
8097
|
const id = await this.getId(dataWithProductId.id);
|
|
7943
|
-
const product = await super.update(
|
|
8098
|
+
const product = await super.update({ id, ...data });
|
|
7944
8099
|
if (dataWithProductId.productId) {
|
|
7945
8100
|
product.productId = dataWithProductId.productId;
|
|
7946
8101
|
}
|
|
7947
8102
|
return product;
|
|
7948
8103
|
}
|
|
7949
8104
|
async getId(id) {
|
|
7950
|
-
var _a, _b;
|
|
7951
8105
|
if (!Number.isNaN(+id))
|
|
7952
8106
|
return id;
|
|
7953
8107
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
7954
|
-
if (
|
|
7955
|
-
return
|
|
8108
|
+
if (data?.[0]?.id)
|
|
8109
|
+
return data?.[0]?.id;
|
|
7956
8110
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7957
8111
|
}
|
|
7958
8112
|
}
|
|
@@ -7983,11 +8137,14 @@ const fieldsConfiguration = [
|
|
|
7983
8137
|
bindPersistData: (value) => {
|
|
7984
8138
|
return {
|
|
7985
8139
|
brand_condition: value.brand,
|
|
7986
|
-
tag_condition:
|
|
8140
|
+
tag_condition: value?.tags || [],
|
|
7987
8141
|
};
|
|
7988
8142
|
},
|
|
7989
8143
|
bindFindFilter: (sentence) => {
|
|
7990
|
-
return
|
|
8144
|
+
return {
|
|
8145
|
+
...(sentence.brand ? { brand_condition: sentence.brand } : {}),
|
|
8146
|
+
...(sentence.tags ? { tag_condition: sentence.tags } : {}),
|
|
8147
|
+
};
|
|
7991
8148
|
},
|
|
7992
8149
|
},
|
|
7993
8150
|
},
|
|
@@ -7999,7 +8156,7 @@ const fieldsConfiguration = [
|
|
|
7999
8156
|
bindPersistData: (value) => ({
|
|
8000
8157
|
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
8001
8158
|
}),
|
|
8002
|
-
from: (filters) =>
|
|
8159
|
+
from: (filters) => filters?.map((filter) => filter?.filter) || [],
|
|
8003
8160
|
},
|
|
8004
8161
|
},
|
|
8005
8162
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -8067,12 +8224,18 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8067
8224
|
this.categoryProductRepository = categoryProductRepository;
|
|
8068
8225
|
}
|
|
8069
8226
|
async create(params) {
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8227
|
+
const { images, mostRelevants, metadatas, ...data } = params;
|
|
8228
|
+
return super.create({
|
|
8229
|
+
...data,
|
|
8230
|
+
isWishlist: true,
|
|
8231
|
+
isCollection: true,
|
|
8232
|
+
brandCategory: false,
|
|
8233
|
+
metadatas: metadatas || [{ shop: data.shop ?? null, description: data.description, title: data.name }],
|
|
8234
|
+
mostRelevants: mostRelevants || {
|
|
8073
8235
|
[exports.Shops.GLAMSHOP]: null,
|
|
8074
8236
|
[exports.Shops.MENSMARKET]: null,
|
|
8075
|
-
},
|
|
8237
|
+
},
|
|
8238
|
+
images: images || {
|
|
8076
8239
|
[exports.Shops.GLAMSHOP]: {
|
|
8077
8240
|
brandBanner: null,
|
|
8078
8241
|
brandBannerMobile: null,
|
|
@@ -8083,7 +8246,8 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8083
8246
|
brandBannerMobile: null,
|
|
8084
8247
|
image: null,
|
|
8085
8248
|
},
|
|
8086
|
-
}
|
|
8249
|
+
},
|
|
8250
|
+
});
|
|
8087
8251
|
}
|
|
8088
8252
|
async get(identifiers) {
|
|
8089
8253
|
const data = await super.get(identifiers);
|
|
@@ -8092,14 +8256,20 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8092
8256
|
return data;
|
|
8093
8257
|
}
|
|
8094
8258
|
async find(params) {
|
|
8095
|
-
const { filters
|
|
8096
|
-
return await super.find(
|
|
8259
|
+
const { filters, ...rest } = params;
|
|
8260
|
+
return await super.find({
|
|
8261
|
+
...rest,
|
|
8262
|
+
filters: {
|
|
8263
|
+
...filters,
|
|
8264
|
+
isWishlist: { operator: exports.Where.EQUALS, value: true },
|
|
8265
|
+
},
|
|
8266
|
+
});
|
|
8097
8267
|
}
|
|
8098
8268
|
async update(params) {
|
|
8099
|
-
const
|
|
8269
|
+
const { id: checkId, metadatas, ...data } = lodash.omit(params, ['products', 'filters']);
|
|
8100
8270
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
8101
8271
|
const id = plainData.id;
|
|
8102
|
-
const category = await super.update(
|
|
8272
|
+
const category = await super.update({ id, ...data, isWishlist: true, isCollection: true, brandCategory: false });
|
|
8103
8273
|
category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
|
|
8104
8274
|
return category;
|
|
8105
8275
|
}
|
|
@@ -8162,11 +8332,22 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8162
8332
|
return data;
|
|
8163
8333
|
}
|
|
8164
8334
|
async findBfluOrGlamgirlWishlists(params, shops) {
|
|
8165
|
-
|
|
8166
|
-
|
|
8335
|
+
return this.find({
|
|
8336
|
+
...params,
|
|
8337
|
+
filters: {
|
|
8338
|
+
...params.filters,
|
|
8339
|
+
published: true,
|
|
8340
|
+
shops: { operator: exports.Where.LIKE, value: shops },
|
|
8341
|
+
personType: params.filters?.personType ?? {
|
|
8167
8342
|
operator: exports.Where.IN,
|
|
8168
8343
|
value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
|
|
8169
|
-
}
|
|
8344
|
+
},
|
|
8345
|
+
},
|
|
8346
|
+
orderBy: {
|
|
8347
|
+
personHasPhoto: 'desc',
|
|
8348
|
+
...lodash.omit(params.orderBy, ['personHasPhoto']),
|
|
8349
|
+
},
|
|
8350
|
+
});
|
|
8170
8351
|
}
|
|
8171
8352
|
getCategoriesForHome() {
|
|
8172
8353
|
return;
|
|
@@ -8374,7 +8555,7 @@ class PagarmePaymentFactoryHelper {
|
|
|
8374
8555
|
checkoutId: checkout.id,
|
|
8375
8556
|
totalPrice: checkout.totalPrice,
|
|
8376
8557
|
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
8377
|
-
transaction:
|
|
8558
|
+
transaction: { ...resultData, paidAt: new Date() },
|
|
8378
8559
|
});
|
|
8379
8560
|
return payment;
|
|
8380
8561
|
}
|
|
@@ -8401,7 +8582,6 @@ class PagarmeCardAxiosAdapter {
|
|
|
8401
8582
|
this.orderBlockedRepository = orderBlockedRepository;
|
|
8402
8583
|
}
|
|
8403
8584
|
async pay(checkout, card) {
|
|
8404
|
-
var _a;
|
|
8405
8585
|
try {
|
|
8406
8586
|
const result = await PagarmePaymentOperationsHelper.executePaymentRequest({
|
|
8407
8587
|
checkout,
|
|
@@ -8427,7 +8607,7 @@ class PagarmeCardAxiosAdapter {
|
|
|
8427
8607
|
if (error instanceof PaymentError) {
|
|
8428
8608
|
throw error;
|
|
8429
8609
|
}
|
|
8430
|
-
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout,
|
|
8610
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
8431
8611
|
}
|
|
8432
8612
|
}
|
|
8433
8613
|
async addCard(card) {
|
|
@@ -8494,7 +8674,10 @@ class PagarmeCardAxiosAdapter {
|
|
|
8494
8674
|
const { data } = await axios__default["default"]({
|
|
8495
8675
|
method: 'POST',
|
|
8496
8676
|
url: `${this.credentials.URL}/transactions`,
|
|
8497
|
-
data:
|
|
8677
|
+
data: {
|
|
8678
|
+
...info,
|
|
8679
|
+
api_key: this.credentials.API_KEY,
|
|
8680
|
+
},
|
|
8498
8681
|
});
|
|
8499
8682
|
return data;
|
|
8500
8683
|
}
|
|
@@ -8505,7 +8688,6 @@ class PagarmeCardAxiosAdapter {
|
|
|
8505
8688
|
}
|
|
8506
8689
|
}
|
|
8507
8690
|
createCardPayment(checkout, card) {
|
|
8508
|
-
var _a, _b, _c, _d, _e, _f;
|
|
8509
8691
|
return {
|
|
8510
8692
|
api_key: this.credentials.API_KEY,
|
|
8511
8693
|
amount: Math.floor(checkout.totalPrice * 100),
|
|
@@ -8532,14 +8714,14 @@ class PagarmeCardAxiosAdapter {
|
|
|
8532
8714
|
name: checkout.user.displayName,
|
|
8533
8715
|
address: {
|
|
8534
8716
|
country: 'br',
|
|
8535
|
-
state: checkout.billingAddress ? checkout.billingAddress.state :
|
|
8536
|
-
city: checkout.billingAddress ? checkout.billingAddress.city :
|
|
8537
|
-
neighborhood: checkout.billingAddress ? checkout.billingAddress.district :
|
|
8538
|
-
street: checkout.billingAddress ? checkout.billingAddress.street :
|
|
8539
|
-
street_number: checkout.billingAddress ? checkout.billingAddress.number :
|
|
8717
|
+
state: checkout.billingAddress ? checkout.billingAddress.state : checkout.shippingAddress?.state,
|
|
8718
|
+
city: checkout.billingAddress ? checkout.billingAddress.city : checkout.shippingAddress?.city,
|
|
8719
|
+
neighborhood: checkout.billingAddress ? checkout.billingAddress.district : checkout.shippingAddress?.district,
|
|
8720
|
+
street: checkout.billingAddress ? checkout.billingAddress.street : checkout.shippingAddress?.street,
|
|
8721
|
+
street_number: checkout.billingAddress ? checkout.billingAddress.number : checkout.shippingAddress?.number,
|
|
8540
8722
|
zipcode: checkout.billingAddress
|
|
8541
8723
|
? checkout.billingAddress.zip.replace('-', '')
|
|
8542
|
-
:
|
|
8724
|
+
: checkout.shippingAddress?.zip.replace('-', ''),
|
|
8543
8725
|
},
|
|
8544
8726
|
},
|
|
8545
8727
|
items: checkout.lineItems.map((item) => {
|
|
@@ -8561,7 +8743,6 @@ class PagarmePixAxiosAdapter {
|
|
|
8561
8743
|
this.paymentRepository = paymentRepository;
|
|
8562
8744
|
}
|
|
8563
8745
|
async pay(checkout) {
|
|
8564
|
-
var _a;
|
|
8565
8746
|
try {
|
|
8566
8747
|
const payload = this.createPixPayment(checkout);
|
|
8567
8748
|
const result = await axios__default["default"]({
|
|
@@ -8585,7 +8766,7 @@ class PagarmePixAxiosAdapter {
|
|
|
8585
8766
|
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
8586
8767
|
checkoutId: checkout.id,
|
|
8587
8768
|
userEmail: checkout.user.email,
|
|
8588
|
-
info:
|
|
8769
|
+
info: error.response?.data,
|
|
8589
8770
|
});
|
|
8590
8771
|
}
|
|
8591
8772
|
}
|