@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.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { __decorate, __metadata
|
|
2
|
+
import { __decorate, __metadata } from 'tslib';
|
|
3
3
|
import { plainToInstance, instanceToPlain, Type } from 'class-transformer';
|
|
4
4
|
import { parseISO, format, startOfDay, endOfDay, subDays, addDays } from 'date-fns';
|
|
5
5
|
export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub, subDays } from 'date-fns';
|
|
@@ -191,7 +191,7 @@ class ReflectHelper {
|
|
|
191
191
|
return Reflect.getMetadata(key, target, property) || null;
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
catch
|
|
194
|
+
catch {
|
|
195
195
|
return null;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
@@ -501,7 +501,7 @@ function Debug(opts) {
|
|
|
501
501
|
|
|
502
502
|
const ASYNC_IDENTIFIER = 'async';
|
|
503
503
|
function Log(options = {}) {
|
|
504
|
-
return Trace(
|
|
504
|
+
return Trace({ level: 'log', ...options });
|
|
505
505
|
}
|
|
506
506
|
function Trace(options = {}) {
|
|
507
507
|
return function (target, propertyKey, propertyDescriptor) {
|
|
@@ -601,7 +601,7 @@ class BaseModel {
|
|
|
601
601
|
get identifier() {
|
|
602
602
|
const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
|
|
603
603
|
const data = this;
|
|
604
|
-
return fields.reduce((object, field) => (
|
|
604
|
+
return fields.reduce((object, field) => ({ ...object, [field]: data[field] }), {});
|
|
605
605
|
}
|
|
606
606
|
get identifiersFields() {
|
|
607
607
|
return this.constructor.identifiersFields;
|
|
@@ -666,8 +666,7 @@ class Category extends BaseModel {
|
|
|
666
666
|
return ['id'];
|
|
667
667
|
}
|
|
668
668
|
get glamImages() {
|
|
669
|
-
|
|
670
|
-
return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[Shops.GLAMSHOP])
|
|
669
|
+
return this.images?.[Shops.GLAMSHOP]
|
|
671
670
|
? this.images[Shops.GLAMSHOP]
|
|
672
671
|
: {
|
|
673
672
|
brandBanner: null,
|
|
@@ -676,8 +675,7 @@ class Category extends BaseModel {
|
|
|
676
675
|
};
|
|
677
676
|
}
|
|
678
677
|
get mensImages() {
|
|
679
|
-
|
|
680
|
-
return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[Shops.MENSMARKET])
|
|
678
|
+
return this.images?.[Shops.MENSMARKET]
|
|
681
679
|
? this.images[Shops.MENSMARKET]
|
|
682
680
|
: {
|
|
683
681
|
brandBanner: null,
|
|
@@ -692,8 +690,7 @@ class Category extends BaseModel {
|
|
|
692
690
|
return this.metadatas.find((metadata) => metadata.shop === Shops.MENSMARKET);
|
|
693
691
|
}
|
|
694
692
|
getMostRelevantByShop(shop) {
|
|
695
|
-
|
|
696
|
-
return ((_a = this.mostRelevants) === null || _a === void 0 ? void 0 : _a[shop]) || [];
|
|
693
|
+
return this.mostRelevants?.[shop] || [];
|
|
697
694
|
}
|
|
698
695
|
}
|
|
699
696
|
__decorate([
|
|
@@ -1426,10 +1423,18 @@ class Authentication {
|
|
|
1426
1423
|
return signInMethod === SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
|
|
1427
1424
|
}
|
|
1428
1425
|
async createsUserByCredential(user) {
|
|
1429
|
-
|
|
1430
|
-
const
|
|
1431
|
-
|
|
1432
|
-
|
|
1426
|
+
const [firstName, lastName] = user.displayName?.split(/\s/) ?? [];
|
|
1427
|
+
const person = User.toInstance({
|
|
1428
|
+
...user,
|
|
1429
|
+
cpf: '',
|
|
1430
|
+
birthday: new Date(),
|
|
1431
|
+
firstName,
|
|
1432
|
+
lastName,
|
|
1433
|
+
acceptsNewsletter: false,
|
|
1434
|
+
area: Area.Transactional,
|
|
1435
|
+
officePosition: OfficePosition.Intern,
|
|
1436
|
+
type: UserType.Collaborator,
|
|
1437
|
+
});
|
|
1433
1438
|
return this.userRepository.create(person);
|
|
1434
1439
|
}
|
|
1435
1440
|
}
|
|
@@ -1478,8 +1483,15 @@ class Register {
|
|
|
1478
1483
|
password: params.password,
|
|
1479
1484
|
});
|
|
1480
1485
|
delete params.password;
|
|
1481
|
-
const user = await this.userRepository.create(
|
|
1482
|
-
|
|
1486
|
+
const user = await this.userRepository.create({
|
|
1487
|
+
...params,
|
|
1488
|
+
id: auth.id,
|
|
1489
|
+
email,
|
|
1490
|
+
displayName,
|
|
1491
|
+
type: UserType.B2C,
|
|
1492
|
+
dateCreated: new Date(),
|
|
1493
|
+
dateModified: new Date(),
|
|
1494
|
+
});
|
|
1483
1495
|
return user;
|
|
1484
1496
|
}
|
|
1485
1497
|
}
|
|
@@ -1673,8 +1685,7 @@ class AntifraudBankSlipService {
|
|
|
1673
1685
|
this.MAX_ORDER_VALUE = 5000;
|
|
1674
1686
|
}
|
|
1675
1687
|
async validate(checkout) {
|
|
1676
|
-
|
|
1677
|
-
if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
|
|
1688
|
+
if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !checkout.user?.isSubscriber) {
|
|
1678
1689
|
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
1679
1690
|
checkout,
|
|
1680
1691
|
blockType: 'Boleto not authorized',
|
|
@@ -1685,7 +1696,7 @@ class AntifraudBankSlipService {
|
|
|
1685
1696
|
checkoutId: checkout.id,
|
|
1686
1697
|
userEmail: checkout.user.email,
|
|
1687
1698
|
info: {
|
|
1688
|
-
isSubscriber:
|
|
1699
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1689
1700
|
subtotal: checkout.subTotalPrice,
|
|
1690
1701
|
total: checkout.totalPrice,
|
|
1691
1702
|
},
|
|
@@ -1709,14 +1720,13 @@ class AntifraudCardService {
|
|
|
1709
1720
|
return true;
|
|
1710
1721
|
}
|
|
1711
1722
|
async validateBlockedOrderAttempts(checkout, card) {
|
|
1712
|
-
var _a;
|
|
1713
1723
|
const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
|
|
1714
1724
|
if (!isValid) {
|
|
1715
1725
|
throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
|
|
1716
1726
|
checkoutId: checkout.id,
|
|
1717
1727
|
userEmail: checkout.user.email,
|
|
1718
1728
|
info: {
|
|
1719
|
-
isSubscriber:
|
|
1729
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1720
1730
|
subtotal: checkout.subTotalPrice,
|
|
1721
1731
|
total: checkout.totalPrice,
|
|
1722
1732
|
},
|
|
@@ -1724,14 +1734,13 @@ class AntifraudCardService {
|
|
|
1724
1734
|
}
|
|
1725
1735
|
}
|
|
1726
1736
|
async validateDayAndWeekOrderLimits(checkout, card) {
|
|
1727
|
-
var _a;
|
|
1728
1737
|
const isValid = await this.verifyDayAndWeekOrders(checkout, card);
|
|
1729
1738
|
if (!isValid) {
|
|
1730
1739
|
throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
|
|
1731
1740
|
checkoutId: checkout.id,
|
|
1732
1741
|
userEmail: checkout.user.email,
|
|
1733
1742
|
info: {
|
|
1734
|
-
isSubscriber:
|
|
1743
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1735
1744
|
subtotal: checkout.subTotalPrice,
|
|
1736
1745
|
total: checkout.totalPrice,
|
|
1737
1746
|
},
|
|
@@ -1760,17 +1769,16 @@ class AntifraudCardService {
|
|
|
1760
1769
|
return { day, endOfDay };
|
|
1761
1770
|
}
|
|
1762
1771
|
async getBlockedOrdersByMultipleCriteria(checkout, dateRange) {
|
|
1763
|
-
var _a, _b, _c, _d;
|
|
1764
1772
|
const { day, endOfDay } = dateRange;
|
|
1765
1773
|
const dateFilter = [
|
|
1766
1774
|
{ operator: Where.GTE, value: new Date(day) },
|
|
1767
1775
|
{ operator: Where.LTE, value: new Date(endOfDay) },
|
|
1768
1776
|
];
|
|
1769
1777
|
const [ordersBlockedWithCpf, ordersBlockedWithEmail, ordersBlockedWithCep, ordersBlockedWithPhone] = await Promise.all([
|
|
1770
|
-
this.getBlockedOrdersByCpf(
|
|
1771
|
-
this.getBlockedOrdersByEmail(
|
|
1772
|
-
this.getBlockedOrdersByZip(
|
|
1773
|
-
this.getBlockedOrdersByPhone(
|
|
1778
|
+
this.getBlockedOrdersByCpf(checkout.user?.cpf, dateFilter),
|
|
1779
|
+
this.getBlockedOrdersByEmail(checkout.user?.email, dateFilter),
|
|
1780
|
+
this.getBlockedOrdersByZip(checkout.shippingAddress?.zip, dateFilter),
|
|
1781
|
+
this.getBlockedOrdersByPhone(checkout.user?.phone, dateFilter),
|
|
1774
1782
|
]);
|
|
1775
1783
|
return {
|
|
1776
1784
|
ordersBlockedWithCpf,
|
|
@@ -1827,18 +1835,15 @@ class AntifraudCardService {
|
|
|
1827
1835
|
return ordersBlockedWithCpf.concat(blockedUniqueEmails).concat(blockedUniqueCeps).concat(blockedUniquePhone).length;
|
|
1828
1836
|
}
|
|
1829
1837
|
filterUniqueEmailBlocked(ordersBlockedWithEmail, checkout) {
|
|
1830
|
-
return ordersBlockedWithEmail.filter((e) =>
|
|
1838
|
+
return ordersBlockedWithEmail.filter((e) => e.customer.cpf !== checkout.user?.cpf);
|
|
1831
1839
|
}
|
|
1832
1840
|
filterUniqueZipBlocked(ordersBlockedWithCep, checkout) {
|
|
1833
|
-
return ordersBlockedWithCep.filter((e) =>
|
|
1841
|
+
return ordersBlockedWithCep.filter((e) => e.customer.cpf !== checkout.user?.cpf && e.customer.email !== checkout.user?.email);
|
|
1834
1842
|
}
|
|
1835
1843
|
filterUniquePhoneBlocked(ordersBlockedWithPhone, checkout) {
|
|
1836
|
-
return ordersBlockedWithPhone.filter((e) =>
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
|
|
1840
|
-
((_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());
|
|
1841
|
-
});
|
|
1844
|
+
return ordersBlockedWithPhone.filter((e) => e.customer.cpf !== checkout.user?.cpf &&
|
|
1845
|
+
e.customer.email !== checkout.user?.email &&
|
|
1846
|
+
e.customer.shippingAddress?.zip?.toString() !== checkout.shippingAddress?.zip?.toString());
|
|
1842
1847
|
}
|
|
1843
1848
|
async createBlockedOrderRecord(params) {
|
|
1844
1849
|
const { checkout, card, reason, key, period } = params;
|
|
@@ -1859,12 +1864,11 @@ class AntifraudCardService {
|
|
|
1859
1864
|
return isWeekLimitValid;
|
|
1860
1865
|
}
|
|
1861
1866
|
buildValidationParams(checkout, card) {
|
|
1862
|
-
var _a, _b, _c, _d;
|
|
1863
1867
|
return {
|
|
1864
|
-
cpf:
|
|
1865
|
-
email:
|
|
1866
|
-
phone:
|
|
1867
|
-
zip:
|
|
1868
|
+
cpf: checkout.user?.cpf,
|
|
1869
|
+
email: checkout.user?.email,
|
|
1870
|
+
phone: checkout.user?.phone,
|
|
1871
|
+
zip: checkout.shippingAddress?.zip,
|
|
1868
1872
|
card,
|
|
1869
1873
|
};
|
|
1870
1874
|
}
|
|
@@ -2000,10 +2004,9 @@ class GlampointsPaymentService {
|
|
|
2000
2004
|
return payment;
|
|
2001
2005
|
}
|
|
2002
2006
|
async rewardByOrder(order, user) {
|
|
2003
|
-
var _a;
|
|
2004
2007
|
try {
|
|
2005
2008
|
const points = order.lineItems.filter((item) => !item.isGift).reduce((acc, li) => acc + li.quantity, 0);
|
|
2006
|
-
const hasGlambeauty =
|
|
2009
|
+
const hasGlambeauty = order.lineItems?.some((doc) => doc.brand && doc.brand.toUpperCase() === 'GLAM BEAUTY');
|
|
2007
2010
|
const result = await axios({
|
|
2008
2011
|
method: 'POST',
|
|
2009
2012
|
url: `${this.glamCredentials.baseUrl}/integration/win/reward`,
|
|
@@ -2264,7 +2267,7 @@ class AdyenPaymentFactoryHelper {
|
|
|
2264
2267
|
checkoutId: checkout.id,
|
|
2265
2268
|
totalPrice: checkout.totalPrice,
|
|
2266
2269
|
paymentProvider: 'adyen',
|
|
2267
|
-
transaction:
|
|
2270
|
+
transaction: { ...adyenResponse, status: 'paid' },
|
|
2268
2271
|
});
|
|
2269
2272
|
return paymentRepository.create(paymentData);
|
|
2270
2273
|
}
|
|
@@ -2275,7 +2278,7 @@ class AdyenPaymentOperationsHelper {
|
|
|
2275
2278
|
return {
|
|
2276
2279
|
amount: {
|
|
2277
2280
|
currency: 'BRL',
|
|
2278
|
-
value: (
|
|
2281
|
+
value: (checkout?.totalPrice || 0) * 100,
|
|
2279
2282
|
},
|
|
2280
2283
|
paymentMethod: {
|
|
2281
2284
|
type: 'scheme',
|
|
@@ -2360,7 +2363,11 @@ class RestCacheAdapter {
|
|
|
2360
2363
|
this.logger = new DebugHelper('RestCacheAdapter');
|
|
2361
2364
|
this.client = axios.create({
|
|
2362
2365
|
baseURL: config.baseURL,
|
|
2363
|
-
headers:
|
|
2366
|
+
headers: {
|
|
2367
|
+
'Content-Type': 'application/json',
|
|
2368
|
+
...(isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` }),
|
|
2369
|
+
...(isNil(config.mobileApiKey) ? {} : { 'X-Mobile-API-Key': config.mobileApiKey }),
|
|
2370
|
+
},
|
|
2364
2371
|
});
|
|
2365
2372
|
}
|
|
2366
2373
|
async set(options) {
|
|
@@ -2616,7 +2623,10 @@ class ElasticSearchResultProcessorHelper {
|
|
|
2616
2623
|
});
|
|
2617
2624
|
}
|
|
2618
2625
|
static transformHitsToProducts(hits) {
|
|
2619
|
-
return hits.map((hit) => (
|
|
2626
|
+
return hits.map((hit) => ({
|
|
2627
|
+
...hit._source,
|
|
2628
|
+
stock: hit._source.stock.quantity,
|
|
2629
|
+
}));
|
|
2620
2630
|
}
|
|
2621
2631
|
}
|
|
2622
2632
|
|
|
@@ -2759,11 +2769,11 @@ class FirestoreDataConverterHelper {
|
|
|
2759
2769
|
return (data &&
|
|
2760
2770
|
!Array.isArray(data) &&
|
|
2761
2771
|
typeof data === 'object' &&
|
|
2762
|
-
|
|
2772
|
+
data?.constructor.name !== 'Timestamp' &&
|
|
2763
2773
|
!('seconds' in data));
|
|
2764
2774
|
}
|
|
2765
2775
|
static convertToDate(data, keyName) {
|
|
2766
|
-
if (
|
|
2776
|
+
if (data?.constructor.name === 'Timestamp')
|
|
2767
2777
|
return data.toDate();
|
|
2768
2778
|
if (data && typeof data === 'object' && 'seconds' in data)
|
|
2769
2779
|
return new Date(data.seconds * 1000);
|
|
@@ -2808,7 +2818,7 @@ class FirestoreModelConverterHelper {
|
|
|
2808
2818
|
}
|
|
2809
2819
|
buildToFirestoreConverter() {
|
|
2810
2820
|
return (data) => {
|
|
2811
|
-
const plain =
|
|
2821
|
+
const plain = data?.toPlain ? data.toPlain() : data;
|
|
2812
2822
|
return FirestoreModelConverterHelper.omitByRecursivelyInPlace(plain, (value) => value === undefined);
|
|
2813
2823
|
};
|
|
2814
2824
|
}
|
|
@@ -2818,7 +2828,7 @@ class FirestoreModelConverterHelper {
|
|
|
2818
2828
|
const data = snap.data();
|
|
2819
2829
|
const ids = { id: snap.id };
|
|
2820
2830
|
const bindedData = FirestoreDataConverterHelper.bindAllDateFromObject(data);
|
|
2821
|
-
return this.model.toInstance(
|
|
2831
|
+
return this.model.toInstance({ ...bindedData, ...ids });
|
|
2822
2832
|
}
|
|
2823
2833
|
catch (error) {
|
|
2824
2834
|
this.handleConversionError(snap.id, snap.data(), error);
|
|
@@ -2886,18 +2896,17 @@ const withHelpers = (MixinBase) => {
|
|
|
2886
2896
|
class AttributeOptionHelper {
|
|
2887
2897
|
}
|
|
2888
2898
|
AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
2889
|
-
var _a;
|
|
2890
2899
|
if (fields.includes(attributeName))
|
|
2891
2900
|
return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
|
|
2892
2901
|
const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
2893
|
-
const fieldOption =
|
|
2902
|
+
const fieldOption = is(field)?.[attributeName];
|
|
2894
2903
|
if (isNil(fieldOption))
|
|
2895
2904
|
return { columnName: attributeName.toString(), attributeName };
|
|
2896
2905
|
if (Array.isArray(fieldOption))
|
|
2897
2906
|
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
2898
|
-
return
|
|
2907
|
+
return { attributeName, columnName: attributeName.toString(), ...fieldOption };
|
|
2899
2908
|
};
|
|
2900
|
-
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!
|
|
2909
|
+
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
|
|
2901
2910
|
AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
2902
2911
|
if (fields.includes(columnName))
|
|
2903
2912
|
return { columnName, attributeName: columnName };
|
|
@@ -2905,13 +2914,17 @@ AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
|
2905
2914
|
if (!isObject(field))
|
|
2906
2915
|
return false;
|
|
2907
2916
|
const columnOption = Object.values(field).find((option) => AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName ? option : {});
|
|
2908
|
-
return AttributeOptionHelper.CheckIsColumnOption(columnOption) &&
|
|
2917
|
+
return AttributeOptionHelper.CheckIsColumnOption(columnOption) && columnOption?.columnName === columnName;
|
|
2909
2918
|
}) || {});
|
|
2910
2919
|
const attributeName = Object.keys(field).find((fieldOptionFromList) => AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) || Array.isArray(field[fieldOptionFromList]));
|
|
2911
|
-
const fieldOption = field
|
|
2920
|
+
const fieldOption = field?.[attributeName];
|
|
2912
2921
|
if (Array.isArray(fieldOption))
|
|
2913
2922
|
return { attributeName: attributeName, fields: fieldOption };
|
|
2914
|
-
return
|
|
2923
|
+
return {
|
|
2924
|
+
attributeName: attributeName || columnName,
|
|
2925
|
+
columnName,
|
|
2926
|
+
...fieldOption,
|
|
2927
|
+
};
|
|
2915
2928
|
};
|
|
2916
2929
|
|
|
2917
2930
|
var HasuraGraphQLWhere;
|
|
@@ -2949,7 +2962,7 @@ var HasuraGraphQLColumnType;
|
|
|
2949
2962
|
|
|
2950
2963
|
class FilterOptionHelper {
|
|
2951
2964
|
}
|
|
2952
|
-
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !isNil(filter
|
|
2965
|
+
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !isNil(filter?.operator);
|
|
2953
2966
|
FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
|
|
2954
2967
|
if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
|
|
2955
2968
|
return filter;
|
|
@@ -3010,25 +3023,37 @@ class BindFilterQueryHelper {
|
|
|
3010
3023
|
BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => {
|
|
3011
3024
|
const columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
|
|
3012
3025
|
if (!columnOption.bindFindFilter)
|
|
3013
|
-
return
|
|
3014
|
-
|
|
3015
|
-
|
|
3026
|
+
return {
|
|
3027
|
+
...variables,
|
|
3028
|
+
...{
|
|
3029
|
+
[columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
|
|
3030
|
+
},
|
|
3031
|
+
};
|
|
3016
3032
|
const builtFilter = columnOption.bindFindFilter(filter[fieldName]);
|
|
3017
|
-
return
|
|
3033
|
+
return {
|
|
3034
|
+
...variables,
|
|
3035
|
+
...Object.keys(builtFilter).reduce((variablesList, columnName) => ({
|
|
3036
|
+
...variablesList,
|
|
3037
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields),
|
|
3038
|
+
}), {}),
|
|
3039
|
+
};
|
|
3018
3040
|
}, {});
|
|
3019
3041
|
BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
3020
3042
|
const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
3021
3043
|
const isNestedField = !Array.isArray(options) &&
|
|
3022
3044
|
isObject(options) &&
|
|
3023
|
-
isNil(options
|
|
3024
|
-
isNil(options
|
|
3025
|
-
isNil(fieldSentenceOptions
|
|
3045
|
+
isNil(options?.operator) &&
|
|
3046
|
+
isNil(options?.value) &&
|
|
3047
|
+
isNil(fieldSentenceOptions?.to);
|
|
3026
3048
|
if (isNestedField)
|
|
3027
3049
|
return Object.keys(options).reduce((variables, key) => {
|
|
3028
|
-
const fieldOptions = AttributeOptionHelper.FindByAttribute(key,
|
|
3050
|
+
const fieldOptions = AttributeOptionHelper.FindByAttribute(key, fieldSentenceOptions?.fields || fields);
|
|
3029
3051
|
const columnName = fieldOptions.columnName;
|
|
3030
3052
|
const columnFields = fieldOptions.fields;
|
|
3031
|
-
return
|
|
3053
|
+
return {
|
|
3054
|
+
...variables,
|
|
3055
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), fieldSentenceOptions?.fields || columnFields || fields),
|
|
3056
|
+
};
|
|
3032
3057
|
}, {});
|
|
3033
3058
|
if (!Array.isArray(options) && !isNil(fieldSentenceOptions.fields))
|
|
3034
3059
|
return {
|
|
@@ -3037,7 +3062,10 @@ BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
|
3037
3062
|
if (!Array.isArray(options) && isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
3038
3063
|
options = Object.values(options)[0];
|
|
3039
3064
|
return Array.isArray(options)
|
|
3040
|
-
? options.reduce((whereSentence, option) => (
|
|
3065
|
+
? options.reduce((whereSentence, option) => ({
|
|
3066
|
+
...whereSentence,
|
|
3067
|
+
...BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions),
|
|
3068
|
+
}), {})
|
|
3041
3069
|
: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions);
|
|
3042
3070
|
};
|
|
3043
3071
|
BindFilterQueryHelper.BuildOperatorSentence = (options, fieldOption) => ({
|
|
@@ -3053,14 +3081,14 @@ BindFilterQueryHelper.GetHasuraOperator = (options, fieldOption) => FilterOption
|
|
|
3053
3081
|
: options.operator === Where.LIKE && options.ignoreCase
|
|
3054
3082
|
? HasuraGraphQLWhere.ILIKE
|
|
3055
3083
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3056
|
-
Object.keys(Where).find((operator) => Where[operator] ===
|
|
3084
|
+
Object.keys(Where).find((operator) => Where[operator] === options?.operator))]
|
|
3057
3085
|
: HasuraGraphQLWhere.EQUALS;
|
|
3058
3086
|
BindFilterQueryHelper.GetHasuraJsonbOperator = (options) => options.operator === Where.IN
|
|
3059
3087
|
? HasuraGraphQLWhere.JSON_CONTAINS
|
|
3060
3088
|
: options.operator === Where.LIKE
|
|
3061
3089
|
? HasuraGraphQLWhere.JSON_HAS_KEYS_ANY
|
|
3062
3090
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3063
|
-
Object.keys(Where).find((operator) => Where[operator] ===
|
|
3091
|
+
Object.keys(Where).find((operator) => Where[operator] === options?.operator))];
|
|
3064
3092
|
|
|
3065
3093
|
class CacheKeyGeneratorHelper {
|
|
3066
3094
|
static generateCacheKeyFromIdentifiers(modelOrModelName, identifiers) {
|
|
@@ -3075,7 +3103,8 @@ class GraphQLFieldHelper {
|
|
|
3075
3103
|
}
|
|
3076
3104
|
GraphQLFieldHelper.CheckIsGraphQLParams = (params) => !isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
|
|
3077
3105
|
GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
3078
|
-
return fields
|
|
3106
|
+
return fields
|
|
3107
|
+
?.map((field) => {
|
|
3079
3108
|
if (isString(field))
|
|
3080
3109
|
return field.toString();
|
|
3081
3110
|
if (field === 'affected_rows')
|
|
@@ -3090,41 +3119,55 @@ GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
|
3090
3119
|
if (isNestedField)
|
|
3091
3120
|
return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
|
|
3092
3121
|
return fieldValue.columnName;
|
|
3093
|
-
})
|
|
3122
|
+
})
|
|
3123
|
+
.filter((field) => !!field);
|
|
3094
3124
|
};
|
|
3095
3125
|
GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
|
|
3096
3126
|
const { attributeName, fields: attributeFields, from, } = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields);
|
|
3097
3127
|
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
3098
3128
|
if (Array.isArray(data[columnName]))
|
|
3099
|
-
return
|
|
3129
|
+
return {
|
|
3130
|
+
...result,
|
|
3131
|
+
[attributeName]: from
|
|
3100
3132
|
? from(data[columnName], data)
|
|
3101
|
-
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields))
|
|
3133
|
+
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)),
|
|
3134
|
+
};
|
|
3102
3135
|
if (isObject(data[columnName]))
|
|
3103
|
-
return
|
|
3136
|
+
return {
|
|
3137
|
+
...result,
|
|
3138
|
+
[attributeName]: from
|
|
3104
3139
|
? from(data[columnName])
|
|
3105
|
-
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields)
|
|
3140
|
+
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields),
|
|
3141
|
+
};
|
|
3106
3142
|
}
|
|
3107
3143
|
if (from)
|
|
3108
|
-
return
|
|
3109
|
-
return
|
|
3144
|
+
return { ...result, [attributeName]: from(data[columnName], data) };
|
|
3145
|
+
return {
|
|
3146
|
+
...result,
|
|
3147
|
+
[attributeName]: isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName],
|
|
3148
|
+
};
|
|
3110
3149
|
}, {});
|
|
3111
3150
|
GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
3112
|
-
|
|
3113
|
-
const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
3151
|
+
const data = instance.toPlain?.() || instance;
|
|
3114
3152
|
return Object.keys(data).reduce((result, attributeName) => {
|
|
3115
3153
|
const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
|
|
3116
3154
|
if (bindPersistData)
|
|
3117
|
-
return
|
|
3155
|
+
return {
|
|
3156
|
+
...result,
|
|
3157
|
+
...bindPersistData(data[attributeName], instance),
|
|
3158
|
+
};
|
|
3118
3159
|
if (isNil(columnName))
|
|
3119
3160
|
return result;
|
|
3120
3161
|
if (!!foreignKeyColumn &&
|
|
3121
3162
|
!isEmpty(foreignKeyColumn) &&
|
|
3122
|
-
!Object.keys(foreignKeyColumn).filter((key) =>
|
|
3163
|
+
!Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
|
|
3123
3164
|
return Object.keys(foreignKeyColumn).reduce((object, current) => {
|
|
3124
|
-
var _a;
|
|
3125
3165
|
const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
|
|
3126
|
-
return
|
|
3127
|
-
|
|
3166
|
+
return {
|
|
3167
|
+
...object,
|
|
3168
|
+
[foreignColumnName]: data[attributeName]?.[current],
|
|
3169
|
+
};
|
|
3170
|
+
}, { ...result });
|
|
3128
3171
|
if (update &&
|
|
3129
3172
|
isObject(data[attributeName]) &&
|
|
3130
3173
|
!isNil(attributeFields) &&
|
|
@@ -3136,19 +3179,25 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
3136
3179
|
const converted = !isNil(columnName) && to
|
|
3137
3180
|
? to(instance[attributeName], instance)
|
|
3138
3181
|
: data[attributeName];
|
|
3139
|
-
return
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
:
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3182
|
+
return {
|
|
3183
|
+
...result,
|
|
3184
|
+
...(converted !== undefined
|
|
3185
|
+
? {
|
|
3186
|
+
[columnName]: {
|
|
3187
|
+
data: instance[attributeName] instanceof BaseModel
|
|
3188
|
+
? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
|
|
3189
|
+
: converted,
|
|
3190
|
+
},
|
|
3191
|
+
}
|
|
3192
|
+
: {}),
|
|
3193
|
+
};
|
|
3148
3194
|
}
|
|
3149
3195
|
if (to)
|
|
3150
|
-
return
|
|
3151
|
-
|
|
3196
|
+
return {
|
|
3197
|
+
...result,
|
|
3198
|
+
[columnName]: to(instance[attributeName], instance),
|
|
3199
|
+
};
|
|
3200
|
+
return { ...result, [columnName]: data[attributeName] };
|
|
3152
3201
|
}, {});
|
|
3153
3202
|
};
|
|
3154
3203
|
GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
|
|
@@ -3206,13 +3255,17 @@ class MD5GeneratorHelper {
|
|
|
3206
3255
|
|
|
3207
3256
|
class HasuraAuthHelper {
|
|
3208
3257
|
static buildHeaders(authOptions) {
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
? {}
|
|
3212
|
-
: {
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3258
|
+
return {
|
|
3259
|
+
'Content-Type': 'application/json',
|
|
3260
|
+
...(isNil(authOptions?.authToken) ? {} : { Authorization: authOptions?.authToken }),
|
|
3261
|
+
...(isNil(authOptions?.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': authOptions?.adminSecret }),
|
|
3262
|
+
...(isNil(authOptions?.authRole)
|
|
3263
|
+
? {}
|
|
3264
|
+
: {
|
|
3265
|
+
'X-Hasura-Role': authOptions.authRole.role,
|
|
3266
|
+
'X-Hasura-User-Id': authOptions?.authRole?.userId,
|
|
3267
|
+
}),
|
|
3268
|
+
};
|
|
3216
3269
|
}
|
|
3217
3270
|
}
|
|
3218
3271
|
|
|
@@ -3302,17 +3355,22 @@ class HasuraGraphQLOperationsHelper {
|
|
|
3302
3355
|
return this.executeFetch({ query: resultQuery, operationParams });
|
|
3303
3356
|
}
|
|
3304
3357
|
static async executeQuery(params) {
|
|
3305
|
-
var _a, _b, _c, _d;
|
|
3306
3358
|
const { operation, fields, variables, operationParams, buildHasuraQueryFields } = params;
|
|
3307
3359
|
const builded = buildHasuraQueryFields({ operation, fields, variables });
|
|
3308
|
-
const intercepted = (await
|
|
3360
|
+
const intercepted = (await operationParams.interceptors?.request?.(builded)) || builded;
|
|
3309
3361
|
const resultQuery = HasuraQueryBuilderHelper.buildQuery(intercepted);
|
|
3362
|
+
console.warn(resultQuery);
|
|
3310
3363
|
const result = await this.executeFetch({ query: resultQuery, operationParams });
|
|
3311
|
-
return (await
|
|
3364
|
+
return (await operationParams.interceptors?.response?.(result, intercepted)) || result;
|
|
3312
3365
|
}
|
|
3313
3366
|
static async executeFetch(params) {
|
|
3314
3367
|
const { query, operationParams } = params;
|
|
3315
|
-
return HasuraRequestHelper.fetch(
|
|
3368
|
+
return HasuraRequestHelper.fetch({
|
|
3369
|
+
...query,
|
|
3370
|
+
endpoint: operationParams.endpoint,
|
|
3371
|
+
headers: HasuraAuthHelper.buildHeaders(operationParams.authOptions),
|
|
3372
|
+
logger: operationParams.logger,
|
|
3373
|
+
});
|
|
3316
3374
|
}
|
|
3317
3375
|
}
|
|
3318
3376
|
|
|
@@ -3326,12 +3384,10 @@ class HasuraColumnHelper {
|
|
|
3326
3384
|
const columnOptions = Object.values(field).shift();
|
|
3327
3385
|
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
3328
3386
|
columnOptions.foreignKeyColumn && [
|
|
3329
|
-
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) =>
|
|
3387
|
+
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => AttributeOptionHelper.FindByAttribute(foreignKeyName, fields)?.columnName),
|
|
3330
3388
|
{
|
|
3331
|
-
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) =>
|
|
3332
|
-
|
|
3333
|
-
return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || foreignKeyField;
|
|
3334
|
-
}),
|
|
3389
|
+
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
|
|
3390
|
+
?.columnName || foreignKeyField),
|
|
3335
3391
|
},
|
|
3336
3392
|
]);
|
|
3337
3393
|
})
|
|
@@ -3356,7 +3412,7 @@ class HasuraCreateOperationsHelper {
|
|
|
3356
3412
|
const { model } = params;
|
|
3357
3413
|
params.repository.logger = DebugHelper.from(params.repository, 'create');
|
|
3358
3414
|
const instance = model.toInstance(data);
|
|
3359
|
-
const newData = await this.executeSave(
|
|
3415
|
+
const newData = await this.executeSave({ ...params, data: instance });
|
|
3360
3416
|
return model.toInstance(newData);
|
|
3361
3417
|
}
|
|
3362
3418
|
static async executeSave(params) {
|
|
@@ -3370,14 +3426,14 @@ class HasuraCreateOperationsHelper {
|
|
|
3370
3426
|
},
|
|
3371
3427
|
});
|
|
3372
3428
|
const convertedResult = repository.convertDataFromHasura(result[insertGraphQLOperation]);
|
|
3373
|
-
return
|
|
3429
|
+
return { ...data.toPlain(), ...convertedResult.toPlain() };
|
|
3374
3430
|
}
|
|
3375
3431
|
}
|
|
3376
3432
|
|
|
3377
3433
|
class HasuraCacheOperationsHelper {
|
|
3378
3434
|
static async removeCacheData(cache, params) {
|
|
3379
3435
|
const { model, identifiers, logger } = params;
|
|
3380
|
-
if (!
|
|
3436
|
+
if (!cache?.cacheAdapter)
|
|
3381
3437
|
return;
|
|
3382
3438
|
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3383
3439
|
await cache.cacheAdapter.remove(cacheKey);
|
|
@@ -3397,13 +3453,16 @@ class HasuraDeleteVariablesHelper {
|
|
|
3397
3453
|
if (isNil(instance.identifier[identifierBinded]))
|
|
3398
3454
|
return ids;
|
|
3399
3455
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
|
|
3400
|
-
const value =
|
|
3456
|
+
const value = columnOption?.to(identifiers[identifier], instance) ||
|
|
3401
3457
|
identifiers[identifier];
|
|
3402
|
-
return
|
|
3458
|
+
return {
|
|
3459
|
+
...ids,
|
|
3460
|
+
[columnOption.columnName]: {
|
|
3403
3461
|
type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3404
3462
|
value,
|
|
3405
3463
|
required: true,
|
|
3406
|
-
}
|
|
3464
|
+
},
|
|
3465
|
+
};
|
|
3407
3466
|
}, {});
|
|
3408
3467
|
}
|
|
3409
3468
|
}
|
|
@@ -3441,16 +3500,15 @@ class HasuraFindBindingHelper {
|
|
|
3441
3500
|
], []);
|
|
3442
3501
|
}
|
|
3443
3502
|
static bindAggregateAttributes(aggregates, fields) {
|
|
3444
|
-
var _a, _b;
|
|
3445
3503
|
return [
|
|
3446
|
-
...(
|
|
3504
|
+
...(aggregates?.minimal?.length
|
|
3447
3505
|
? [
|
|
3448
3506
|
{
|
|
3449
3507
|
min: this.bindAttributesToColumns(aggregates.minimal, fields),
|
|
3450
3508
|
},
|
|
3451
3509
|
]
|
|
3452
3510
|
: []),
|
|
3453
|
-
...(
|
|
3511
|
+
...(aggregates?.maximum?.length
|
|
3454
3512
|
? [
|
|
3455
3513
|
{
|
|
3456
3514
|
max: this.bindAttributesToColumns(aggregates.maximum, fields),
|
|
@@ -3477,7 +3535,7 @@ class HasuraFindBindingHelper {
|
|
|
3477
3535
|
});
|
|
3478
3536
|
if (typeof fieldOption === 'object' && fieldOption !== null) {
|
|
3479
3537
|
const columnOption = fieldOption[attributeName];
|
|
3480
|
-
return
|
|
3538
|
+
return columnOption?.columnName || attributeName;
|
|
3481
3539
|
}
|
|
3482
3540
|
return attributeName;
|
|
3483
3541
|
}
|
|
@@ -3490,27 +3548,27 @@ class HasuraFindCacheHelper {
|
|
|
3490
3548
|
}
|
|
3491
3549
|
static async getCachedResult(params) {
|
|
3492
3550
|
const { cache, model, findParams, cacheOptions, logger } = params;
|
|
3493
|
-
if (!
|
|
3551
|
+
if (!cache?.cacheAdapter || !cacheOptions?.enabled)
|
|
3494
3552
|
return null;
|
|
3495
3553
|
const cacheKey = this.generateCacheKey(model, findParams);
|
|
3496
3554
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
3497
3555
|
if (cachedData) {
|
|
3498
|
-
logger
|
|
3556
|
+
logger?.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
3499
3557
|
return deserialize(cachedData);
|
|
3500
3558
|
}
|
|
3501
3559
|
return null;
|
|
3502
3560
|
}
|
|
3503
3561
|
static async setCachedResult(params) {
|
|
3504
3562
|
const { cache, model, findParams, cacheOptions, result, logger } = params;
|
|
3505
|
-
if (!
|
|
3563
|
+
if (!cache?.cacheAdapter || !cacheOptions?.enabled)
|
|
3506
3564
|
return;
|
|
3507
3565
|
const cacheKey = this.generateCacheKey(model, findParams);
|
|
3508
3566
|
await cache.cacheAdapter.set({
|
|
3509
3567
|
key: cacheKey,
|
|
3510
3568
|
data: serialize(result),
|
|
3511
|
-
expirationInSeconds:
|
|
3569
|
+
expirationInSeconds: cacheOptions?.ttl || cache.ttlDefault,
|
|
3512
3570
|
});
|
|
3513
|
-
logger
|
|
3571
|
+
logger?.log(`Dados salvos no cache: ${cacheKey}`);
|
|
3514
3572
|
}
|
|
3515
3573
|
}
|
|
3516
3574
|
|
|
@@ -3518,11 +3576,16 @@ class HasuraFindResultHelper {
|
|
|
3518
3576
|
static processResult(params) {
|
|
3519
3577
|
const { result, tableName, enableCount, findOptions, tableFiltersNamed, fields, convertDataFromHasura, lastDistinct, } = params;
|
|
3520
3578
|
const data = result[tableName].map((row) => convertDataFromHasura(row));
|
|
3521
|
-
const findResult =
|
|
3579
|
+
const findResult = {
|
|
3580
|
+
data,
|
|
3581
|
+
count: enableCount ? result[`${tableName}_aggregate`].aggregate.count : Infinity,
|
|
3582
|
+
...this.processMinimalAggregates({ result, tableName, findOptions, fields }),
|
|
3583
|
+
...this.processMaximumAggregates({ result, tableName, findOptions, fields }),
|
|
3584
|
+
...this.processDistinctResults({ result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct }),
|
|
3585
|
+
};
|
|
3522
3586
|
return findResult;
|
|
3523
3587
|
}
|
|
3524
3588
|
static bindAggregateAttributes(params) {
|
|
3525
|
-
var _a, _b;
|
|
3526
3589
|
const { aggregates, fields } = params;
|
|
3527
3590
|
const convertFieldName = (fieldName) => {
|
|
3528
3591
|
const finalFieldName = fieldName.toString().split('.').pop();
|
|
@@ -3534,19 +3597,19 @@ class HasuraFindResultHelper {
|
|
|
3534
3597
|
});
|
|
3535
3598
|
if (fieldOption && typeof fieldOption !== 'string') {
|
|
3536
3599
|
const fieldValue = Object.values(fieldOption)[0];
|
|
3537
|
-
return
|
|
3600
|
+
return fieldValue?.columnName || finalFieldName;
|
|
3538
3601
|
}
|
|
3539
3602
|
return finalFieldName;
|
|
3540
3603
|
};
|
|
3541
3604
|
return [
|
|
3542
|
-
...(
|
|
3605
|
+
...(aggregates?.minimal?.length
|
|
3543
3606
|
? [
|
|
3544
3607
|
{
|
|
3545
3608
|
min: aggregates.minimal.map(convertFieldName),
|
|
3546
3609
|
},
|
|
3547
3610
|
]
|
|
3548
3611
|
: []),
|
|
3549
|
-
...(
|
|
3612
|
+
...(aggregates?.maximum?.length
|
|
3550
3613
|
? [
|
|
3551
3614
|
{
|
|
3552
3615
|
max: aggregates.maximum.map(convertFieldName),
|
|
@@ -3556,48 +3619,52 @@ class HasuraFindResultHelper {
|
|
|
3556
3619
|
];
|
|
3557
3620
|
}
|
|
3558
3621
|
static processMinimalAggregates(params) {
|
|
3559
|
-
var _a;
|
|
3560
3622
|
const { result, tableName, findOptions, fields } = params;
|
|
3561
|
-
return
|
|
3623
|
+
return findOptions?.minimal?.length
|
|
3562
3624
|
? {
|
|
3563
3625
|
minimal: findOptions.minimal.reduce((minimals, current) => {
|
|
3564
|
-
|
|
3565
|
-
return
|
|
3626
|
+
const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
|
|
3627
|
+
return {
|
|
3628
|
+
...minimals,
|
|
3629
|
+
...set(minimals, current, result[`${tableName}_aggregate`].aggregate.min[columnName]),
|
|
3630
|
+
};
|
|
3566
3631
|
}, {}),
|
|
3567
3632
|
}
|
|
3568
3633
|
: {};
|
|
3569
3634
|
}
|
|
3570
3635
|
static processMaximumAggregates(params) {
|
|
3571
|
-
var _a;
|
|
3572
3636
|
const { result, tableName, findOptions, fields } = params;
|
|
3573
|
-
return
|
|
3637
|
+
return findOptions?.maximum?.length
|
|
3574
3638
|
? {
|
|
3575
3639
|
maximum: findOptions.maximum.reduce((maximums, current) => {
|
|
3576
|
-
|
|
3577
|
-
return
|
|
3640
|
+
const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
|
|
3641
|
+
return {
|
|
3642
|
+
...maximums,
|
|
3643
|
+
...set(maximums, current, result[`${tableName}_aggregate`].aggregate.max[columnName]),
|
|
3644
|
+
};
|
|
3578
3645
|
}, {}),
|
|
3579
3646
|
}
|
|
3580
3647
|
: {};
|
|
3581
3648
|
}
|
|
3582
3649
|
static processDistinctResults(params) {
|
|
3583
|
-
var _a, _b;
|
|
3584
3650
|
const { result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct } = params;
|
|
3585
|
-
return
|
|
3651
|
+
return findOptions?.distinct?.length
|
|
3586
3652
|
? {
|
|
3587
|
-
distinct:
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3653
|
+
distinct: lastDistinct[tableFiltersNamed] ??
|
|
3654
|
+
(lastDistinct[tableFiltersNamed] = findOptions?.distinct.reduce((distinct, current) => {
|
|
3655
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === current) ??
|
|
3656
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
|
|
3657
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || current;
|
|
3658
|
+
return {
|
|
3659
|
+
...distinct,
|
|
3660
|
+
[current.toString()]: result[`${tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]),
|
|
3661
|
+
};
|
|
3662
|
+
}, {})),
|
|
3593
3663
|
}
|
|
3594
3664
|
: {};
|
|
3595
3665
|
}
|
|
3596
3666
|
static bindAttributesToColumns(attributes, fields) {
|
|
3597
|
-
return attributes.map((attr) =>
|
|
3598
|
-
var _a;
|
|
3599
|
-
return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
|
|
3600
|
-
});
|
|
3667
|
+
return attributes.map((attr) => AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)?.columnName || attr);
|
|
3601
3668
|
}
|
|
3602
3669
|
}
|
|
3603
3670
|
|
|
@@ -3627,16 +3694,19 @@ class HasuraFindVariablesHelper {
|
|
|
3627
3694
|
};
|
|
3628
3695
|
}
|
|
3629
3696
|
static buildDistinctVariables(params) {
|
|
3630
|
-
var _a, _b;
|
|
3631
3697
|
const { distinct, tableName, fields, filtersVariables } = params;
|
|
3632
|
-
const distinctOption =
|
|
3633
|
-
|
|
3634
|
-
|
|
3698
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
|
|
3699
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
3700
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || distinct;
|
|
3701
|
+
return {
|
|
3702
|
+
...filtersVariables,
|
|
3703
|
+
[`${tableName}_${fieldName}_distinct`]: {
|
|
3635
3704
|
type: `${tableName}_select_column!`,
|
|
3636
3705
|
list: true,
|
|
3637
3706
|
value: fieldName,
|
|
3638
3707
|
name: 'distinct_on',
|
|
3639
|
-
}
|
|
3708
|
+
},
|
|
3709
|
+
};
|
|
3640
3710
|
}
|
|
3641
3711
|
static bindOrderByAttributes(orderBy, fields) {
|
|
3642
3712
|
return Object.keys(orderBy).reduce((acc, current) => [
|
|
@@ -3656,11 +3726,17 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3656
3726
|
const { tableName, fields, params, lastDistinct } = queryParams;
|
|
3657
3727
|
const { filters, limits, orderBy, options: findOptions } = params || {};
|
|
3658
3728
|
const filtersVariables = HasuraFindVariablesHelper.buildFiltersVariables({ filters, tableName, fields });
|
|
3659
|
-
const countVariables =
|
|
3660
|
-
|
|
3729
|
+
const countVariables = {
|
|
3730
|
+
...HasuraFindVariablesHelper.buildOrderByVariables({ orderBy, tableName, fields }),
|
|
3731
|
+
...filtersVariables,
|
|
3732
|
+
};
|
|
3733
|
+
const mainVariables = {
|
|
3734
|
+
...(isNil(limits) ? {} : limits),
|
|
3735
|
+
...countVariables,
|
|
3736
|
+
};
|
|
3661
3737
|
const queries = [
|
|
3662
3738
|
this.buildMainQuery({ tableName, fields, params, mainVariables }),
|
|
3663
|
-
...this.buildAggregateQuery({ tableName, findOptions, countVariables }),
|
|
3739
|
+
...this.buildAggregateQuery({ tableName, findOptions, countVariables, fields }),
|
|
3664
3740
|
...this.buildDistinctQueries({ tableName, fields, findOptions, filtersVariables, lastDistinct }),
|
|
3665
3741
|
];
|
|
3666
3742
|
return queries.filter(Boolean);
|
|
@@ -3669,26 +3745,23 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3669
3745
|
const { tableName, fields, params: findParams, mainVariables } = params;
|
|
3670
3746
|
return {
|
|
3671
3747
|
operation: tableName,
|
|
3672
|
-
fields:
|
|
3748
|
+
fields: findParams?.fields
|
|
3673
3749
|
? findParams.fields
|
|
3674
|
-
.map((fieldName) =>
|
|
3675
|
-
|
|
3676
|
-
return (_a = fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
|
|
3677
|
-
})
|
|
3750
|
+
.map((fieldName) => fields.find((fieldOption) => fieldOption === fieldName) ??
|
|
3751
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
|
|
3678
3752
|
.filter(Boolean)
|
|
3679
3753
|
: fields,
|
|
3680
3754
|
variables: mainVariables,
|
|
3681
3755
|
};
|
|
3682
3756
|
}
|
|
3683
3757
|
static buildAggregateQuery(params) {
|
|
3684
|
-
var _a;
|
|
3685
3758
|
const { tableName, findOptions, countVariables } = params;
|
|
3686
|
-
const enableCount =
|
|
3759
|
+
const enableCount = findOptions?.enableCount ?? true;
|
|
3687
3760
|
const aggregateFields = [
|
|
3688
3761
|
...(enableCount ? ['count'] : []),
|
|
3689
3762
|
...HasuraFindResultHelper.bindAggregateAttributes({
|
|
3690
|
-
aggregates: { minimal: findOptions
|
|
3691
|
-
fields:
|
|
3763
|
+
aggregates: { minimal: findOptions?.minimal, maximum: findOptions?.maximum },
|
|
3764
|
+
fields: params.fields,
|
|
3692
3765
|
}),
|
|
3693
3766
|
];
|
|
3694
3767
|
return aggregateFields.length > 0
|
|
@@ -3706,15 +3779,14 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3706
3779
|
: [];
|
|
3707
3780
|
}
|
|
3708
3781
|
static buildDistinctQueries(params) {
|
|
3709
|
-
var _a;
|
|
3710
3782
|
const { tableName, fields, findOptions, filtersVariables, lastDistinct } = params;
|
|
3711
3783
|
const tableFiltersNamed = `${tableName}:${JSON.stringify(filtersVariables)}`;
|
|
3712
|
-
if (!
|
|
3784
|
+
if (!findOptions?.distinct?.length || lastDistinct[tableFiltersNamed]) {
|
|
3713
3785
|
return [];
|
|
3714
3786
|
}
|
|
3715
3787
|
return findOptions.distinct.map((distinct) => {
|
|
3716
|
-
|
|
3717
|
-
|
|
3788
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
|
|
3789
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
3718
3790
|
return {
|
|
3719
3791
|
operation: {
|
|
3720
3792
|
name: tableName,
|
|
@@ -3734,18 +3806,17 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3734
3806
|
|
|
3735
3807
|
class HasuraFindOperationsHelper {
|
|
3736
3808
|
static async executeFindOperation(operationParams) {
|
|
3737
|
-
var _a;
|
|
3738
3809
|
const { params, cacheOptions, model, tableName, fields, cache, query, convertDataFromHasura, lastDistinct } = operationParams;
|
|
3739
3810
|
const logger = DebugHelper.from(operationParams, 'find');
|
|
3740
3811
|
const { filters, options: findOptions } = params || {};
|
|
3741
3812
|
const tableFiltersNamed = `${tableName}:${JSON.stringify(filters)}`;
|
|
3742
|
-
const enableCount =
|
|
3813
|
+
const enableCount = findOptions?.enableCount ?? true;
|
|
3743
3814
|
// Verifica cache primeiro
|
|
3744
3815
|
const cachedResult = await HasuraFindCacheHelper.getCachedResult({
|
|
3745
3816
|
cache,
|
|
3746
3817
|
model,
|
|
3747
3818
|
findParams: params,
|
|
3748
|
-
cacheOptions: cacheOptions
|
|
3819
|
+
cacheOptions: cacheOptions?.cache,
|
|
3749
3820
|
logger,
|
|
3750
3821
|
});
|
|
3751
3822
|
if (cachedResult) {
|
|
@@ -3773,7 +3844,7 @@ class HasuraFindOperationsHelper {
|
|
|
3773
3844
|
cache,
|
|
3774
3845
|
model,
|
|
3775
3846
|
findParams: params,
|
|
3776
|
-
cacheOptions: cacheOptions
|
|
3847
|
+
cacheOptions: cacheOptions?.cache,
|
|
3777
3848
|
result,
|
|
3778
3849
|
logger,
|
|
3779
3850
|
});
|
|
@@ -3796,9 +3867,8 @@ class HasuraGetCacheHelper {
|
|
|
3796
3867
|
return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3797
3868
|
}
|
|
3798
3869
|
static async getCachedData(cache, params) {
|
|
3799
|
-
var _a;
|
|
3800
3870
|
const { identifiers, options, model, logger } = params;
|
|
3801
|
-
if (!
|
|
3871
|
+
if (!cache?.cacheAdapter || !options?.cache?.enabled)
|
|
3802
3872
|
return null;
|
|
3803
3873
|
const cacheKey = this.generateCacheKey(model, identifiers);
|
|
3804
3874
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -3808,15 +3878,14 @@ class HasuraGetCacheHelper {
|
|
|
3808
3878
|
return model.toInstance(deserialize(cachedData));
|
|
3809
3879
|
}
|
|
3810
3880
|
static async saveCacheData(cache, params) {
|
|
3811
|
-
var _a, _b;
|
|
3812
3881
|
const { identifiers, options, data, logger } = params;
|
|
3813
|
-
if (!
|
|
3882
|
+
if (!cache?.cacheAdapter || !options?.cache?.enabled)
|
|
3814
3883
|
return;
|
|
3815
3884
|
const cacheKey = this.generateCacheKey(params.data.constructor, identifiers);
|
|
3816
3885
|
await cache.cacheAdapter.set({
|
|
3817
3886
|
key: cacheKey,
|
|
3818
3887
|
data: serialize(data),
|
|
3819
|
-
expirationInSeconds:
|
|
3888
|
+
expirationInSeconds: options?.cache?.ttl || cache.ttlDefault,
|
|
3820
3889
|
});
|
|
3821
3890
|
logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
3822
3891
|
}
|
|
@@ -3827,18 +3896,20 @@ class HasuraGetVariablesHelper {
|
|
|
3827
3896
|
const { model, fields, repository } = params;
|
|
3828
3897
|
const instance = model.toInstance(identifiers);
|
|
3829
3898
|
return model.identifiersFields.reduce((ids, identifier) => {
|
|
3830
|
-
var _a;
|
|
3831
3899
|
const identifierBinded = identifier;
|
|
3832
3900
|
if (isNil(instance[identifierBinded]))
|
|
3833
3901
|
return ids;
|
|
3834
3902
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
|
|
3835
|
-
const value =
|
|
3903
|
+
const value = columnOption?.to?.(identifiers[identifier], instance) ||
|
|
3836
3904
|
identifiers[identifier];
|
|
3837
|
-
return
|
|
3905
|
+
return {
|
|
3906
|
+
...ids,
|
|
3907
|
+
[columnOption.columnName]: {
|
|
3838
3908
|
type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3839
3909
|
value,
|
|
3840
3910
|
required: true,
|
|
3841
|
-
}
|
|
3911
|
+
},
|
|
3912
|
+
};
|
|
3842
3913
|
}, {});
|
|
3843
3914
|
}
|
|
3844
3915
|
}
|
|
@@ -3895,7 +3966,7 @@ class HasuraUpdateDataHelper {
|
|
|
3895
3966
|
static getValueByAction(options) {
|
|
3896
3967
|
if (options instanceof BaseModel)
|
|
3897
3968
|
return options.toPlain();
|
|
3898
|
-
if (isNil(options
|
|
3969
|
+
if (isNil(options?.action))
|
|
3899
3970
|
return options;
|
|
3900
3971
|
if ([UpdateOptionActions.REMOVE_FIELD.toString(), UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
3901
3972
|
return null;
|
|
@@ -3904,9 +3975,12 @@ class HasuraUpdateDataHelper {
|
|
|
3904
3975
|
static paramsToPlain(params, model) {
|
|
3905
3976
|
if (model.isModel(params))
|
|
3906
3977
|
return params.toPlain();
|
|
3907
|
-
return Object.keys(params).reduce((data, currentKey) => (
|
|
3908
|
-
|
|
3909
|
-
|
|
3978
|
+
return Object.keys(params).reduce((data, currentKey) => ({
|
|
3979
|
+
...data,
|
|
3980
|
+
...(params[currentKey] !== undefined && {
|
|
3981
|
+
[currentKey]: this.getValueByAction(is(params[currentKey])),
|
|
3982
|
+
}),
|
|
3983
|
+
}), {});
|
|
3910
3984
|
}
|
|
3911
3985
|
static getIdentifiersFromData(data, model) {
|
|
3912
3986
|
const instance = model.toInstance(data);
|
|
@@ -3925,13 +3999,15 @@ class HasuraUpdateVariablesHelper {
|
|
|
3925
3999
|
static getUpdateModelKeys(data, model, fields) {
|
|
3926
4000
|
const instance = model.toInstance(data);
|
|
3927
4001
|
return model.identifiersFields.reduce((ids, identifier) => {
|
|
3928
|
-
var _a;
|
|
3929
4002
|
const identifierBinded = identifier;
|
|
3930
4003
|
if (isNil(instance.identifier[identifierBinded]))
|
|
3931
4004
|
return ids;
|
|
3932
4005
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifierBinded, fields);
|
|
3933
|
-
const value =
|
|
3934
|
-
return
|
|
4006
|
+
const value = columnOption?.to?.(data[identifierBinded], instance) || data[columnOption.attributeName];
|
|
4007
|
+
return {
|
|
4008
|
+
...ids,
|
|
4009
|
+
[columnOption.columnName]: value,
|
|
4010
|
+
};
|
|
3935
4011
|
}, {});
|
|
3936
4012
|
}
|
|
3937
4013
|
static getIdentifierFields(model, fields) {
|
|
@@ -3976,13 +4052,13 @@ class HasuraUpdateOperationsHelper {
|
|
|
3976
4052
|
}
|
|
3977
4053
|
static async handleCacheRemoval(params) {
|
|
3978
4054
|
const { plainData, model, cache, logger } = params;
|
|
3979
|
-
if (!
|
|
4055
|
+
if (!cache?.cacheAdapter)
|
|
3980
4056
|
return;
|
|
3981
4057
|
const identifiers = HasuraUpdateDataHelper.getIdentifiersFromData(plainData, model);
|
|
3982
4058
|
if (Object.keys(identifiers).length > 0) {
|
|
3983
4059
|
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3984
4060
|
await cache.cacheAdapter.remove(cacheKey);
|
|
3985
|
-
logger
|
|
4061
|
+
logger?.log(`Cache removido: ${cacheKey}`);
|
|
3986
4062
|
}
|
|
3987
4063
|
}
|
|
3988
4064
|
}
|
|
@@ -4004,9 +4080,8 @@ class FirestoreCacheKeyGeneratorHelper {
|
|
|
4004
4080
|
|
|
4005
4081
|
class FirestoreCacheHelper {
|
|
4006
4082
|
static async getCachedData(cache, params) {
|
|
4007
|
-
var _a;
|
|
4008
4083
|
const { model, identifiers, options, logger, req } = params;
|
|
4009
|
-
if (!
|
|
4084
|
+
if (!cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4010
4085
|
return null;
|
|
4011
4086
|
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(model, identifiers);
|
|
4012
4087
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -4017,9 +4092,8 @@ class FirestoreCacheHelper {
|
|
|
4017
4092
|
return null;
|
|
4018
4093
|
}
|
|
4019
4094
|
static async getCachedFindData(cache, params) {
|
|
4020
|
-
var _a;
|
|
4021
4095
|
const { model, find, options, logger } = params;
|
|
4022
|
-
if (!
|
|
4096
|
+
if (!cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4023
4097
|
return null;
|
|
4024
4098
|
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(model, find);
|
|
4025
4099
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -4031,7 +4105,7 @@ class FirestoreCacheHelper {
|
|
|
4031
4105
|
}
|
|
4032
4106
|
static async saveCacheData(cache, params) {
|
|
4033
4107
|
const { cacheKey, data, expirationInSeconds, logger, req } = params;
|
|
4034
|
-
if (!
|
|
4108
|
+
if (!cache?.cacheAdapter)
|
|
4035
4109
|
return;
|
|
4036
4110
|
await cache.cacheAdapter.set({
|
|
4037
4111
|
key: cacheKey,
|
|
@@ -4043,7 +4117,7 @@ class FirestoreCacheHelper {
|
|
|
4043
4117
|
}
|
|
4044
4118
|
static async removeCacheData(cache, params) {
|
|
4045
4119
|
const { cacheKey, logger } = params;
|
|
4046
|
-
if (!
|
|
4120
|
+
if (!cache?.cacheAdapter)
|
|
4047
4121
|
return;
|
|
4048
4122
|
await cache.cacheAdapter.remove(cacheKey);
|
|
4049
4123
|
logger.log(`Cache removido: ${cacheKey}`);
|
|
@@ -4061,7 +4135,7 @@ class FirestoreOperationsHelper {
|
|
|
4061
4135
|
this.model = model;
|
|
4062
4136
|
}
|
|
4063
4137
|
buildInstanceFromIdentifiers(identifiers) {
|
|
4064
|
-
return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (
|
|
4138
|
+
return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
|
|
4065
4139
|
}
|
|
4066
4140
|
async validateDocumentExists(docRef, collectionName, identifiers) {
|
|
4067
4141
|
const docSnapshot = await docRef.get();
|
|
@@ -4083,7 +4157,7 @@ class FirestoreOperationsHelper {
|
|
|
4083
4157
|
calculateCount(data, limits) {
|
|
4084
4158
|
if (data.length <= 0)
|
|
4085
4159
|
return 0;
|
|
4086
|
-
if (data.length <
|
|
4160
|
+
if (data.length < limits?.limit)
|
|
4087
4161
|
return data.length;
|
|
4088
4162
|
return Infinity;
|
|
4089
4163
|
}
|
|
@@ -4096,8 +4170,8 @@ class FirestoreOperationsHelper {
|
|
|
4096
4170
|
const { isSubCollection, collectionName, parentRepository, parentIdField, identifiers } = params;
|
|
4097
4171
|
if (!isSubCollection)
|
|
4098
4172
|
return collectionName;
|
|
4099
|
-
const parentId = identifiers
|
|
4100
|
-
return `${parentRepository
|
|
4173
|
+
const parentId = identifiers?.[parentIdField];
|
|
4174
|
+
return `${parentRepository?.collectionName}/${parentId}/${collectionName}`;
|
|
4101
4175
|
}
|
|
4102
4176
|
getKeyField() {
|
|
4103
4177
|
const model = new this.model();
|
|
@@ -4148,27 +4222,25 @@ const createGetFirestoreClass = (MixinBase) => {
|
|
|
4148
4222
|
}
|
|
4149
4223
|
}
|
|
4150
4224
|
async executeGet(params) {
|
|
4151
|
-
var _a, _b, _c, _d;
|
|
4152
4225
|
const { instance, collectionName, identifiers, logger, req } = params;
|
|
4153
|
-
const intercepted = await
|
|
4154
|
-
const builded =
|
|
4226
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4227
|
+
const builded = intercepted?.instance || instance;
|
|
4155
4228
|
const docRef = await this.operationsHelper.getDocumentSnapshot(this.collection(collectionName), builded);
|
|
4156
4229
|
const data = docRef.data();
|
|
4157
4230
|
this.operationsHelper.validateDocumentData(data, collectionName, identifiers);
|
|
4158
|
-
const result = (await
|
|
4231
|
+
const result = (await this.interceptors?.response?.(data, intercepted)) || data;
|
|
4159
4232
|
logger.log({ req, res: result });
|
|
4160
4233
|
return result;
|
|
4161
4234
|
}
|
|
4162
4235
|
async saveCacheData(params) {
|
|
4163
|
-
var _a, _b, _c;
|
|
4164
4236
|
const { identifiers, options, result, logger, req } = params;
|
|
4165
|
-
if (!
|
|
4237
|
+
if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4166
4238
|
return;
|
|
4167
4239
|
const cacheKey = FirestoreCacheHelper.generateGetCacheKey(this.model, identifiers);
|
|
4168
4240
|
await FirestoreCacheHelper.saveCacheData(this.cache, {
|
|
4169
4241
|
cacheKey,
|
|
4170
4242
|
data: result,
|
|
4171
|
-
expirationInSeconds:
|
|
4243
|
+
expirationInSeconds: options?.cache?.ttl,
|
|
4172
4244
|
logger,
|
|
4173
4245
|
req,
|
|
4174
4246
|
});
|
|
@@ -4199,14 +4271,13 @@ class FirestoreQueryBuilderHelper {
|
|
|
4199
4271
|
this.config = config;
|
|
4200
4272
|
}
|
|
4201
4273
|
buildWhereSentence(fieldName, options) {
|
|
4202
|
-
|
|
4203
|
-
if (((_b = (_a = this.config).isSubCollection) === null || _b === void 0 ? void 0 : _b.call(_a, this)) && fieldName === this.config.parentIdField)
|
|
4274
|
+
if (this.config.isSubCollection?.(this) && fieldName === this.config.parentIdField)
|
|
4204
4275
|
return [];
|
|
4205
4276
|
const firestoreFieldName = this.getFirestoreFieldName(fieldName, options);
|
|
4206
4277
|
return this.buildWhereConditions(firestoreFieldName, options, fieldName);
|
|
4207
4278
|
}
|
|
4208
4279
|
getFirestoreFieldName(fieldName, options) {
|
|
4209
|
-
const value =
|
|
4280
|
+
const value = options?.value || options;
|
|
4210
4281
|
const object = {};
|
|
4211
4282
|
set(object, fieldName.toString(), value);
|
|
4212
4283
|
const plainInstance = new this.config.model(object).toPlain();
|
|
@@ -4215,19 +4286,19 @@ class FirestoreQueryBuilderHelper {
|
|
|
4215
4286
|
: Object.keys(plainInstance).find((key) => plainInstance[key]);
|
|
4216
4287
|
}
|
|
4217
4288
|
buildWhereConditions(firestoreFieldName, options, fieldName) {
|
|
4218
|
-
if (
|
|
4289
|
+
if (options?.operator === Where.LIKE) {
|
|
4219
4290
|
return this.buildLikeConditions(firestoreFieldName, options);
|
|
4220
4291
|
}
|
|
4221
|
-
if (
|
|
4292
|
+
if (options?.operator === Where.IN && Array.isArray(options?.value)) {
|
|
4222
4293
|
return this.buildInConditions(firestoreFieldName, options);
|
|
4223
4294
|
}
|
|
4224
4295
|
if (this.isNestedObjectFilter(options)) {
|
|
4225
4296
|
return this.buildNestedObjectConditions(fieldName, options);
|
|
4226
4297
|
}
|
|
4227
|
-
return [[firestoreFieldName, (
|
|
4298
|
+
return [[firestoreFieldName, (options?.operator || '=='), options?.value || options]];
|
|
4228
4299
|
}
|
|
4229
4300
|
buildLikeConditions(firestoreFieldName, options) {
|
|
4230
|
-
if (this.isArrayField(firestoreFieldName) && Array.isArray(options
|
|
4301
|
+
if (this.isArrayField(firestoreFieldName) && Array.isArray(options?.value)) {
|
|
4231
4302
|
return [[firestoreFieldName, 'array-contains-any', options.value]];
|
|
4232
4303
|
}
|
|
4233
4304
|
return [
|
|
@@ -4248,13 +4319,12 @@ class FirestoreQueryBuilderHelper {
|
|
|
4248
4319
|
], []);
|
|
4249
4320
|
}
|
|
4250
4321
|
isArrayField(firestoreFieldName) {
|
|
4251
|
-
|
|
4252
|
-
return (((_a = this.config.fields) === null || _a === void 0 ? void 0 : _a[firestoreFieldName]) ===
|
|
4322
|
+
return (this.config.fields?.[firestoreFieldName] ===
|
|
4253
4323
|
FirestoreFieldType.Array ||
|
|
4254
|
-
!
|
|
4324
|
+
!this.config.fields?.[firestoreFieldName]);
|
|
4255
4325
|
}
|
|
4256
4326
|
isNestedObjectFilter(options) {
|
|
4257
|
-
return isObject(options) && isNil(options
|
|
4327
|
+
return isObject(options) && isNil(options?.operator) && isNil(options?.value);
|
|
4258
4328
|
}
|
|
4259
4329
|
buildOrderBy(filters, fieldsToOrderBy) {
|
|
4260
4330
|
const orderByKeys = Object.keys(fieldsToOrderBy || {});
|
|
@@ -4270,8 +4340,8 @@ class FirestoreQueryBuilderHelper {
|
|
|
4270
4340
|
filtersKeysWithUnordered.forEach((filterKey) => {
|
|
4271
4341
|
const filterValue = filters[filterKey];
|
|
4272
4342
|
const filterOptions = is(filterValue);
|
|
4273
|
-
if (
|
|
4274
|
-
updatedOrderBy =
|
|
4343
|
+
if (filterOptions?.operator && ![Where.EQUALS].includes(filterOptions.operator)) {
|
|
4344
|
+
updatedOrderBy = { [filterKey]: 'asc', ...updatedOrderBy };
|
|
4275
4345
|
}
|
|
4276
4346
|
});
|
|
4277
4347
|
return updatedOrderBy;
|
|
@@ -4285,21 +4355,21 @@ class FirestoreQueryBuilderHelper {
|
|
|
4285
4355
|
async buildLimits(params) {
|
|
4286
4356
|
const { filters, limits, collection, buildCollectionPath } = params;
|
|
4287
4357
|
const queries = [];
|
|
4288
|
-
if (limits
|
|
4358
|
+
if (limits?.offset) {
|
|
4289
4359
|
await this.addOffsetQuery({ queries, limits, filters, collection, buildCollectionPath });
|
|
4290
4360
|
}
|
|
4291
|
-
if (limits
|
|
4361
|
+
if (limits?.limit) {
|
|
4292
4362
|
queries.push(['limit', limits.limit]);
|
|
4293
4363
|
}
|
|
4294
4364
|
return queries;
|
|
4295
4365
|
}
|
|
4296
4366
|
async addOffsetQuery(params) {
|
|
4297
|
-
var _a;
|
|
4298
4367
|
const { queries, limits, filters, collection, buildCollectionPath } = params;
|
|
4299
4368
|
if (this.config.model.isModel(limits.offset)) {
|
|
4300
4369
|
const docSnapshot = await collection(buildCollectionPath(filters))
|
|
4301
|
-
.getDoc(
|
|
4302
|
-
.shift()
|
|
4370
|
+
.getDoc(Object.values(limits.offset.identifier)
|
|
4371
|
+
.shift()
|
|
4372
|
+
?.toString())
|
|
4303
4373
|
.get();
|
|
4304
4374
|
queries.push(['fromStartAfter', docSnapshot]);
|
|
4305
4375
|
}
|
|
@@ -4314,7 +4384,7 @@ class FirestoreQueryBuilderHelper {
|
|
|
4314
4384
|
}
|
|
4315
4385
|
|
|
4316
4386
|
const createFilterHelpers = () => {
|
|
4317
|
-
const checkIfIsFilterOption = (filter) => !isNil(filter
|
|
4387
|
+
const checkIfIsFilterOption = (filter) => !isNil(filter?.operator);
|
|
4318
4388
|
const getValueFromFilter = (filter) => {
|
|
4319
4389
|
return checkIfIsFilterOption(filter) ? filter.value : filter;
|
|
4320
4390
|
};
|
|
@@ -4372,20 +4442,19 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4372
4442
|
}
|
|
4373
4443
|
}
|
|
4374
4444
|
async executeFind(params) {
|
|
4375
|
-
var _a, _b, _c, _d, _e, _f;
|
|
4376
4445
|
const { find, collectionName, logger, req } = params;
|
|
4377
4446
|
const collection = this.collection(collectionName);
|
|
4378
|
-
const enableCount =
|
|
4379
|
-
const intercepted = await
|
|
4380
|
-
const { filters, limits, orderBy } =
|
|
4447
|
+
const enableCount = find?.options?.enableCount ?? true;
|
|
4448
|
+
const intercepted = await this.interceptors?.request?.({ find });
|
|
4449
|
+
const { filters, limits, orderBy } = intercepted?.find || find;
|
|
4381
4450
|
const queryData = await this.buildQueryData(filters, orderBy, limits);
|
|
4382
4451
|
const docs = await this.executeQuery(collection, queryData);
|
|
4383
4452
|
const data = docs.docs.map((doc) => doc.data());
|
|
4384
4453
|
const result = {
|
|
4385
|
-
data: (await
|
|
4454
|
+
data: (await this.interceptors?.response?.(data, intercepted)) || data,
|
|
4386
4455
|
count: enableCount ? this.operationsHelper.calculateCount(data, limits) : Infinity,
|
|
4387
4456
|
};
|
|
4388
|
-
logger.log(
|
|
4457
|
+
logger.log({ req, ...queryData, res: result });
|
|
4389
4458
|
return result;
|
|
4390
4459
|
}
|
|
4391
4460
|
async buildQueryData(filters, orderBy, limits) {
|
|
@@ -4401,19 +4470,21 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4401
4470
|
}
|
|
4402
4471
|
async executeQuery(collection, queryData) {
|
|
4403
4472
|
return this.queryBuilder
|
|
4404
|
-
.buildQuery(
|
|
4473
|
+
.buildQuery({
|
|
4474
|
+
collection,
|
|
4475
|
+
...queryData,
|
|
4476
|
+
})
|
|
4405
4477
|
.getDocs();
|
|
4406
4478
|
}
|
|
4407
4479
|
async saveCacheData(params) {
|
|
4408
|
-
var _a, _b, _c;
|
|
4409
4480
|
const { find, options, result, logger } = params;
|
|
4410
|
-
if (!
|
|
4481
|
+
if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4411
4482
|
return;
|
|
4412
4483
|
const cacheKey = this.generateCacheKey(find);
|
|
4413
4484
|
await FirestoreCacheHelper.saveCacheData(this.cache, {
|
|
4414
4485
|
cacheKey,
|
|
4415
4486
|
data: result,
|
|
4416
|
-
expirationInSeconds:
|
|
4487
|
+
expirationInSeconds: options?.cache?.ttl,
|
|
4417
4488
|
logger,
|
|
4418
4489
|
});
|
|
4419
4490
|
}
|
|
@@ -4421,7 +4492,7 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4421
4492
|
if (!this.isSubCollection(this))
|
|
4422
4493
|
return this.collectionName;
|
|
4423
4494
|
const parentIdField = this.parentIdField;
|
|
4424
|
-
const parentId = getValueFromFilter(filters
|
|
4495
|
+
const parentId = getValueFromFilter(filters?.[parentIdField]);
|
|
4425
4496
|
return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
|
|
4426
4497
|
}
|
|
4427
4498
|
};
|
|
@@ -4430,16 +4501,15 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4430
4501
|
const withCreateFirestore = (MixinBase) => {
|
|
4431
4502
|
return class CreateFirestore extends MixinBase {
|
|
4432
4503
|
async create(data) {
|
|
4433
|
-
var _a, _b, _c, _d;
|
|
4434
4504
|
const logger = this.logger.with('create');
|
|
4435
4505
|
const instance = this.model.toInstance(data);
|
|
4436
|
-
const intercepted = await
|
|
4437
|
-
const builded =
|
|
4506
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4507
|
+
const builded = intercepted?.instance || instance;
|
|
4438
4508
|
const req = { collection: this.buildCollectionPathForAdd(builded), data };
|
|
4439
4509
|
try {
|
|
4440
4510
|
const docRef = await this.save(builded);
|
|
4441
4511
|
const doc = (await docRef.get()).data();
|
|
4442
|
-
const docBuilded = (await
|
|
4512
|
+
const docBuilded = (await this.interceptors?.response?.(doc, intercepted)) || doc;
|
|
4443
4513
|
logger.log({ req, res: docBuilded });
|
|
4444
4514
|
return docBuilded;
|
|
4445
4515
|
}
|
|
@@ -4450,10 +4520,9 @@ const withCreateFirestore = (MixinBase) => {
|
|
|
4450
4520
|
}
|
|
4451
4521
|
}
|
|
4452
4522
|
async save(data) {
|
|
4453
|
-
var _a, _b;
|
|
4454
4523
|
const collectionPath = this.buildCollectionPathForAdd(data);
|
|
4455
4524
|
const collection = this.collection(collectionPath);
|
|
4456
|
-
return collection.add(data,
|
|
4525
|
+
return collection.add(data, Object.values(data.identifier).shift()?.toString?.());
|
|
4457
4526
|
}
|
|
4458
4527
|
buildCollectionPathForAdd(identifiers) {
|
|
4459
4528
|
return this.isSubCollection(this)
|
|
@@ -4464,26 +4533,23 @@ const withCreateFirestore = (MixinBase) => {
|
|
|
4464
4533
|
};
|
|
4465
4534
|
|
|
4466
4535
|
const createUpdateHelpers = () => {
|
|
4467
|
-
const getValueFromParams = (params, field) =>
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
? is(params[field])
|
|
4471
|
-
: is(params[field]).value) || null;
|
|
4472
|
-
};
|
|
4536
|
+
const getValueFromParams = (params, field) => (isNil(is(params[field])?.value)
|
|
4537
|
+
? is(params[field])
|
|
4538
|
+
: is(params[field]).value) || null;
|
|
4473
4539
|
const getValueByAction = (options) => {
|
|
4474
|
-
if (isNil(options
|
|
4540
|
+
if (isNil(options?.action))
|
|
4475
4541
|
return options;
|
|
4476
|
-
if (
|
|
4542
|
+
if (options?.action === UpdateOptionActions.REMOVE_FIELD)
|
|
4477
4543
|
return deleteField();
|
|
4478
|
-
if (
|
|
4544
|
+
if (options?.action === UpdateOptionActions.NULL)
|
|
4479
4545
|
return null;
|
|
4480
|
-
if (Array.isArray(options
|
|
4481
|
-
if (
|
|
4546
|
+
if (Array.isArray(options?.value)) {
|
|
4547
|
+
if (options?.action === UpdateOptionActions.MERGE)
|
|
4482
4548
|
return arrayUnion(...options.value);
|
|
4483
|
-
if (
|
|
4549
|
+
if (options?.action === UpdateOptionActions.REMOVE)
|
|
4484
4550
|
return arrayRemove(...options.value);
|
|
4485
4551
|
}
|
|
4486
|
-
return options
|
|
4552
|
+
return options?.value;
|
|
4487
4553
|
};
|
|
4488
4554
|
return { getValueFromParams, getValueByAction };
|
|
4489
4555
|
};
|
|
@@ -4534,14 +4600,13 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
|
|
|
4534
4600
|
await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
|
|
4535
4601
|
}
|
|
4536
4602
|
async executeUpdate(params) {
|
|
4537
|
-
var _a, _b, _c, _d;
|
|
4538
4603
|
const { data, docRef, logger, req, identifiers } = params;
|
|
4539
4604
|
const plainFromData = this.model.toInstance(this.paramsToPlain(data));
|
|
4540
|
-
const intercepted = await
|
|
4541
|
-
const builded =
|
|
4605
|
+
const intercepted = await this.interceptors?.request?.({ instance: plainFromData });
|
|
4606
|
+
const builded = intercepted?.instance || plainFromData;
|
|
4542
4607
|
await docRef.save(builded.toPlain());
|
|
4543
4608
|
const docData = await docRef.get();
|
|
4544
|
-
const result =
|
|
4609
|
+
const result = this.interceptors?.response?.(docData.data(), intercepted) || docData.data();
|
|
4545
4610
|
logger.log({ req, res: result, identifiers });
|
|
4546
4611
|
return result;
|
|
4547
4612
|
}
|
|
@@ -4557,7 +4622,10 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
|
|
|
4557
4622
|
return this.convertParamsToPlainObject(params);
|
|
4558
4623
|
}
|
|
4559
4624
|
convertParamsToPlainObject(params) {
|
|
4560
|
-
return Object.keys(params).reduce((data, currentKey) => (
|
|
4625
|
+
return Object.keys(params).reduce((data, currentKey) => ({
|
|
4626
|
+
...data,
|
|
4627
|
+
...this.processParamValue(currentKey, params[currentKey]),
|
|
4628
|
+
}), {});
|
|
4561
4629
|
}
|
|
4562
4630
|
processParamValue(key, value) {
|
|
4563
4631
|
const processedValue = getValueByAction(value);
|
|
@@ -4598,12 +4666,11 @@ const createDeleteFirestoreClass = (MixinBase) => {
|
|
|
4598
4666
|
await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
|
|
4599
4667
|
}
|
|
4600
4668
|
async executeDeleteOperation(params) {
|
|
4601
|
-
var _a, _b, _c, _d;
|
|
4602
4669
|
const { instance, collectionName, logger, req } = params;
|
|
4603
|
-
const intercepted = await
|
|
4604
|
-
const builded =
|
|
4670
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4671
|
+
const builded = intercepted?.instance || instance;
|
|
4605
4672
|
await this.operationsHelper.executeDelete(this.collection(collectionName), builded);
|
|
4606
|
-
await
|
|
4673
|
+
await this.interceptors?.response?.(instance, intercepted);
|
|
4607
4674
|
logger.log({ req, res: undefined });
|
|
4608
4675
|
}
|
|
4609
4676
|
buildCollectionPathForRemove(identifiers) {
|
|
@@ -4683,15 +4750,15 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
4683
4750
|
const products = [];
|
|
4684
4751
|
const wheres = [];
|
|
4685
4752
|
for (const productIds of chunks) {
|
|
4686
|
-
if (
|
|
4753
|
+
if (options?.limit && products.length >= options?.limit)
|
|
4687
4754
|
break;
|
|
4688
4755
|
wheres.push(['published', '==', true], ['id', 'in', productIds]);
|
|
4689
|
-
if (options
|
|
4756
|
+
if (options?.hasStock)
|
|
4690
4757
|
wheres.push(['stock.quantity', '>', 0]);
|
|
4691
|
-
if (options
|
|
4692
|
-
wheres.push(['tags', 'array-contains', options
|
|
4758
|
+
if (options?.gender)
|
|
4759
|
+
wheres.push(['tags', 'array-contains', options?.gender]);
|
|
4693
4760
|
const productSnap = await wheres
|
|
4694
|
-
.reduce((collection, where) => collection.where(...where),
|
|
4761
|
+
.reduce((collection, where) => collection.where(...where), options?.limit
|
|
4695
4762
|
? this.collection('productsErpVitrine').limit(options.limit)
|
|
4696
4763
|
: this.collection('productsErpVitrine'))
|
|
4697
4764
|
.getDocs();
|
|
@@ -4756,19 +4823,17 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
4756
4823
|
throw new Error('Method not implemented.');
|
|
4757
4824
|
}
|
|
4758
4825
|
async getBySlug(slug) {
|
|
4759
|
-
var _a;
|
|
4760
4826
|
const result = await this.find({
|
|
4761
4827
|
filters: {
|
|
4762
4828
|
slug: { operator: Where.EQUALS, value: slug },
|
|
4763
4829
|
},
|
|
4764
4830
|
});
|
|
4765
|
-
return
|
|
4831
|
+
return result?.data?.shift();
|
|
4766
4832
|
}
|
|
4767
4833
|
async fetchReviews(status) {
|
|
4768
4834
|
const { data: products } = await this.find();
|
|
4769
4835
|
products.forEach((product) => {
|
|
4770
|
-
|
|
4771
|
-
if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
|
|
4836
|
+
if ([undefined, 0].includes(product.reviews?.length))
|
|
4772
4837
|
return;
|
|
4773
4838
|
const productInfo = {
|
|
4774
4839
|
productId: product.id,
|
|
@@ -4780,11 +4845,11 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
4780
4845
|
this.reviews.rejected = [];
|
|
4781
4846
|
product.reviews.forEach((review) => {
|
|
4782
4847
|
if ([null, undefined].includes(review.status))
|
|
4783
|
-
return this.reviews.pending.push(
|
|
4848
|
+
return this.reviews.pending.push({ ...review, ...productInfo });
|
|
4784
4849
|
if (review.status === false)
|
|
4785
|
-
return this.reviews.rejected.push(
|
|
4850
|
+
return this.reviews.rejected.push({ ...review, ...productInfo });
|
|
4786
4851
|
if (review.status)
|
|
4787
|
-
return this.reviews.approved.push(
|
|
4852
|
+
return this.reviews.approved.push({ ...review, ...productInfo });
|
|
4788
4853
|
return review;
|
|
4789
4854
|
});
|
|
4790
4855
|
});
|
|
@@ -4871,22 +4936,18 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
4871
4936
|
interceptors,
|
|
4872
4937
|
cache,
|
|
4873
4938
|
});
|
|
4874
|
-
this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
|
|
4887
|
-
products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
|
|
4888
|
-
});
|
|
4889
|
-
};
|
|
4939
|
+
this.homeCategoryGroupToPlain = (homeCategoryGroup) => ({
|
|
4940
|
+
category: homeCategoryGroup?.category?.toPlain
|
|
4941
|
+
? homeCategoryGroup?.category?.toPlain()
|
|
4942
|
+
: homeCategoryGroup?.category,
|
|
4943
|
+
products: homeCategoryGroup?.products
|
|
4944
|
+
?.map((product) => (product?.toPlain ? product?.toPlain() : product))
|
|
4945
|
+
.filter(Boolean) || [],
|
|
4946
|
+
});
|
|
4947
|
+
this.plainToHomeCategoryGroup = (homeCategoryGroup) => ({
|
|
4948
|
+
category: Category.toInstance(homeCategoryGroup?.category),
|
|
4949
|
+
products: homeCategoryGroup.products?.map((product) => Product.toInstance(product)),
|
|
4950
|
+
});
|
|
4890
4951
|
}
|
|
4891
4952
|
buildModelInstance() {
|
|
4892
4953
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -4902,17 +4963,15 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
4902
4963
|
};
|
|
4903
4964
|
}
|
|
4904
4965
|
homeToFirestore(home) {
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
home.data.data.
|
|
4908
|
-
home.data.data.
|
|
4909
|
-
home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
|
|
4966
|
+
if (home.data?.data) {
|
|
4967
|
+
home.data.data.discoverProducts = home.data.data.discoverProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4968
|
+
home.data.data.featuredProducts = home.data.data.featuredProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4969
|
+
home.data.data.verticalProducts = home.data.data.verticalProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4910
4970
|
}
|
|
4911
4971
|
return home;
|
|
4912
4972
|
}
|
|
4913
4973
|
homeFromFirestore(home) {
|
|
4914
|
-
|
|
4915
|
-
if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
|
|
4974
|
+
if (home.data?.data) {
|
|
4916
4975
|
home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
|
|
4917
4976
|
home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
|
|
4918
4977
|
home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
|
|
@@ -5051,8 +5110,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
5051
5110
|
},
|
|
5052
5111
|
});
|
|
5053
5112
|
this.orderFromFirestore = (order) => {
|
|
5054
|
-
|
|
5055
|
-
if ((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length) {
|
|
5113
|
+
if (order?.lineItems?.length) {
|
|
5056
5114
|
order.lineItems = order.lineItems.map((lineItem) => {
|
|
5057
5115
|
const prices = !!lineItem.price;
|
|
5058
5116
|
const shopPrice = prices[order.shop];
|
|
@@ -5067,7 +5125,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
5067
5125
|
buildModelInstance() {
|
|
5068
5126
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
5069
5127
|
return {
|
|
5070
|
-
toFirestore: (data) => toFirestore(
|
|
5128
|
+
toFirestore: (data) => toFirestore(data?.toPlain ? data.toPlain() : data),
|
|
5071
5129
|
fromFirestore: (snap) => {
|
|
5072
5130
|
const instance = fromFirestore(snap);
|
|
5073
5131
|
return this.orderFromFirestore(instance);
|
|
@@ -5098,18 +5156,20 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
|
|
|
5098
5156
|
});
|
|
5099
5157
|
}
|
|
5100
5158
|
async createBlockedOrderOrPayment(params) {
|
|
5101
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5102
5159
|
const { checkout, blockType, type, limiteRange, card = null } = params;
|
|
5103
5160
|
return this.create(OrderBlocked.toInstance({
|
|
5104
5161
|
customer: {
|
|
5105
|
-
name:
|
|
5106
|
-
cpf:
|
|
5107
|
-
id:
|
|
5108
|
-
email:
|
|
5109
|
-
phoneNumber: '+55' +
|
|
5110
|
-
isSubscriber:
|
|
5111
|
-
subscriptionPlan:
|
|
5112
|
-
shippingAddress:
|
|
5162
|
+
name: checkout.user?.displayName || '',
|
|
5163
|
+
cpf: checkout.user?.cpf || '',
|
|
5164
|
+
id: checkout.user?.id,
|
|
5165
|
+
email: checkout.user?.email || '',
|
|
5166
|
+
phoneNumber: '+55' + checkout.user?.phone,
|
|
5167
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
5168
|
+
subscriptionPlan: checkout.user?.subscriptionPlan || '',
|
|
5169
|
+
shippingAddress: {
|
|
5170
|
+
...checkout.shippingAddress,
|
|
5171
|
+
zip: this.formatZip(checkout.shippingAddress?.zip),
|
|
5172
|
+
},
|
|
5113
5173
|
},
|
|
5114
5174
|
blockType,
|
|
5115
5175
|
limiteRange,
|
|
@@ -5357,7 +5417,7 @@ class ConnectDocumentService {
|
|
|
5357
5417
|
this.reference = doc(this.firestore, this.path).withConverter({
|
|
5358
5418
|
toFirestore: (data) => data,
|
|
5359
5419
|
fromFirestore: (snapshot) => {
|
|
5360
|
-
return
|
|
5420
|
+
return { id: snapshot.id, ...snapshot.data() };
|
|
5361
5421
|
},
|
|
5362
5422
|
});
|
|
5363
5423
|
}
|
|
@@ -5395,7 +5455,7 @@ class ConnectCollectionService {
|
|
|
5395
5455
|
this.reference = collection(firestore, path).withConverter({
|
|
5396
5456
|
toFirestore: (data) => data,
|
|
5397
5457
|
fromFirestore: (snapshot) => {
|
|
5398
|
-
return
|
|
5458
|
+
return { id: snapshot.id, ...snapshot.data() };
|
|
5399
5459
|
},
|
|
5400
5460
|
});
|
|
5401
5461
|
}
|
|
@@ -5490,10 +5550,10 @@ class FirebaseFileUploaderService {
|
|
|
5490
5550
|
function createCreateHasuraGraphQLClass(MixinBase) {
|
|
5491
5551
|
return class CreateHasuraGraphQLMixin extends MixinBase {
|
|
5492
5552
|
constructor(...params) {
|
|
5493
|
-
const options = params
|
|
5553
|
+
const options = params?.[0];
|
|
5494
5554
|
super(...params);
|
|
5495
|
-
this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options
|
|
5496
|
-
this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options
|
|
5555
|
+
this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options?.insertGraphQLOperation);
|
|
5556
|
+
this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options?.insertGraphQLObjectType);
|
|
5497
5557
|
}
|
|
5498
5558
|
async create(data) {
|
|
5499
5559
|
return HasuraCreateOperationsHelper.executeCreate(data, {
|
|
@@ -5520,9 +5580,9 @@ function createCreateHasuraGraphQLClass(MixinBase) {
|
|
|
5520
5580
|
function createDeleteHasuraGraphQLClass(MixinBase) {
|
|
5521
5581
|
return class DeleteHasuraGraphQLMixin extends MixinBase {
|
|
5522
5582
|
constructor(...params) {
|
|
5523
|
-
const options = params
|
|
5583
|
+
const options = params?.[0];
|
|
5524
5584
|
super(...params);
|
|
5525
|
-
this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options
|
|
5585
|
+
this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options?.deleteGraphQLOperation);
|
|
5526
5586
|
}
|
|
5527
5587
|
async delete(identifiers) {
|
|
5528
5588
|
await HasuraDeleteOperationsHelper.executeDelete({
|
|
@@ -5568,9 +5628,9 @@ function createFindHasuraGraphQLClass(MixinBase) {
|
|
|
5568
5628
|
function createGetHasuraGraphQLClass(MixinBase) {
|
|
5569
5629
|
return class GetHasuraGraphQLMixin extends MixinBase {
|
|
5570
5630
|
constructor(...params) {
|
|
5571
|
-
const options = params
|
|
5631
|
+
const options = params?.[0];
|
|
5572
5632
|
super(...params);
|
|
5573
|
-
this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options
|
|
5633
|
+
this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options?.getGraphQLOperation);
|
|
5574
5634
|
}
|
|
5575
5635
|
generateCacheKey(identifiers) {
|
|
5576
5636
|
return HasuraGetCacheHelper.generateCacheKey(this.model, identifiers);
|
|
@@ -5646,11 +5706,11 @@ function createHasuraGraphQLClass(MixinBase) {
|
|
|
5646
5706
|
function createUpdateHasuraGraphQLClass(MixinBase) {
|
|
5647
5707
|
return class UpdateHasuraGraphQLMixin extends MixinBase {
|
|
5648
5708
|
constructor(...params) {
|
|
5649
|
-
const options = params
|
|
5709
|
+
const options = params?.[0];
|
|
5650
5710
|
super(...params);
|
|
5651
|
-
this.updateGraphQLOperation =
|
|
5652
|
-
this.updateGraphQLObjectType =
|
|
5653
|
-
this.updateGraphQLPKType =
|
|
5711
|
+
this.updateGraphQLOperation = options?.updateGraphQLOperation || `update_${this.tableName}_by_pk`;
|
|
5712
|
+
this.updateGraphQLObjectType = options?.updateGraphQLObjectType || `${this.tableName}_set_input`;
|
|
5713
|
+
this.updateGraphQLPKType = options?.updateGraphQLPKType || `${this.tableName}_pk_columns_input`;
|
|
5654
5714
|
}
|
|
5655
5715
|
getIdentifiersFromData(data) {
|
|
5656
5716
|
return HasuraUpdateDataHelper.getIdentifiersFromData(data, this.model);
|
|
@@ -5840,7 +5900,7 @@ const fieldsConfiguration$5 = [
|
|
|
5840
5900
|
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
5841
5901
|
}),
|
|
5842
5902
|
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
5843
|
-
from: (categories) =>
|
|
5903
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
5844
5904
|
},
|
|
5845
5905
|
},
|
|
5846
5906
|
],
|
|
@@ -5921,8 +5981,7 @@ class CategoryCacheOperationsHelper {
|
|
|
5921
5981
|
logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5922
5982
|
}
|
|
5923
5983
|
static shouldUseCache(cacheAdapter, optionsCache) {
|
|
5924
|
-
|
|
5925
|
-
return !!(cacheAdapter && ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.enabled));
|
|
5984
|
+
return !!(cacheAdapter && optionsCache?.cache?.enabled);
|
|
5926
5985
|
}
|
|
5927
5986
|
}
|
|
5928
5987
|
|
|
@@ -6090,19 +6149,25 @@ class CategoryProductOperationsHelper {
|
|
|
6090
6149
|
}
|
|
6091
6150
|
static buildProductQuery(params) {
|
|
6092
6151
|
const { productIds, fields, hasStock, limit } = params;
|
|
6093
|
-
return
|
|
6152
|
+
return {
|
|
6153
|
+
filters: this.buildProductFilters(productIds, hasStock),
|
|
6154
|
+
...(limit ? { limits: { limit } } : {}),
|
|
6155
|
+
fields,
|
|
6156
|
+
options: { enableCount: false },
|
|
6157
|
+
orderBy: {
|
|
6094
6158
|
stock: 'desc',
|
|
6095
6159
|
shoppingCount: 'desc',
|
|
6096
6160
|
rate: 'desc',
|
|
6097
6161
|
name: 'asc',
|
|
6098
|
-
}
|
|
6162
|
+
},
|
|
6163
|
+
};
|
|
6099
6164
|
}
|
|
6100
6165
|
static getGenderParam(shop) {
|
|
6101
6166
|
return shop === Shops.MENSMARKET ? 'male' : 'female';
|
|
6102
6167
|
}
|
|
6103
6168
|
static async fetchMostRelevantProducts(params) {
|
|
6104
6169
|
const { productRepository, mostRelevantsIds, fields, shop, hasStock, optionsCache } = params;
|
|
6105
|
-
if (!
|
|
6170
|
+
if (!mostRelevantsIds?.length)
|
|
6106
6171
|
return [];
|
|
6107
6172
|
const query = this.buildProductQuery({ productIds: mostRelevantsIds, fields, hasStock });
|
|
6108
6173
|
const { data } = await productRepository.findCatalog(query, this.getGenderParam(shop), optionsCache);
|
|
@@ -6131,9 +6196,8 @@ class CategoryProductOperationsHelper {
|
|
|
6131
6196
|
|
|
6132
6197
|
class CategoryMountOperationsHelper {
|
|
6133
6198
|
static async executeMount(params, dependencies) {
|
|
6134
|
-
var _a;
|
|
6135
6199
|
const { category, shop, options = {}, optionsCache } = params;
|
|
6136
|
-
if (!
|
|
6200
|
+
if (!category?.products?.length)
|
|
6137
6201
|
return [];
|
|
6138
6202
|
const cachedResult = await this.tryGetFromCache({
|
|
6139
6203
|
category,
|
|
@@ -6231,7 +6295,6 @@ class CategoryMountOperationsHelper {
|
|
|
6231
6295
|
return result;
|
|
6232
6296
|
}
|
|
6233
6297
|
static async saveToCacheIfNeeded(params) {
|
|
6234
|
-
var _a;
|
|
6235
6298
|
const { category, shop, options, optionsCache, result, dependencies } = params;
|
|
6236
6299
|
const shouldUseCache = CategoryCacheOperationsHelper.shouldUseCache(dependencies.cacheAdapter, optionsCache);
|
|
6237
6300
|
if (!shouldUseCache)
|
|
@@ -6241,7 +6304,7 @@ class CategoryMountOperationsHelper {
|
|
|
6241
6304
|
cacheAdapter: dependencies.cacheAdapter,
|
|
6242
6305
|
cacheKey,
|
|
6243
6306
|
products: result,
|
|
6244
|
-
ttl:
|
|
6307
|
+
ttl: optionsCache?.cache?.ttl || dependencies.defaultCacheTtl,
|
|
6245
6308
|
logger: dependencies.logger,
|
|
6246
6309
|
});
|
|
6247
6310
|
}
|
|
@@ -6267,7 +6330,12 @@ class ProductFetchReviewsHelper {
|
|
|
6267
6330
|
...reviews,
|
|
6268
6331
|
...product.reviews
|
|
6269
6332
|
.filter((review) => this.matchesStatus(review, status))
|
|
6270
|
-
.map((review) => (
|
|
6333
|
+
.map((review) => ({
|
|
6334
|
+
...bindReviewToModel(review),
|
|
6335
|
+
productId: product.id,
|
|
6336
|
+
productName: product.name,
|
|
6337
|
+
productSku: product.sku,
|
|
6338
|
+
})),
|
|
6271
6339
|
], []);
|
|
6272
6340
|
}
|
|
6273
6341
|
static matchesStatus(review, status) {
|
|
@@ -6314,8 +6382,7 @@ class ProductReviewCacheHelper {
|
|
|
6314
6382
|
dependencies.logger.log(`Dados salvos no cache: ${key}`);
|
|
6315
6383
|
}
|
|
6316
6384
|
static shouldUseCache(cacheAdapter, options) {
|
|
6317
|
-
|
|
6318
|
-
return !!(cacheAdapter && ((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled));
|
|
6385
|
+
return !!(cacheAdapter && options?.cache?.enabled);
|
|
6319
6386
|
}
|
|
6320
6387
|
}
|
|
6321
6388
|
|
|
@@ -6326,9 +6393,12 @@ class ProductReviewOperationsHelper {
|
|
|
6326
6393
|
let count = 0;
|
|
6327
6394
|
let offset = 0;
|
|
6328
6395
|
do {
|
|
6329
|
-
const result = await repository.find(
|
|
6330
|
-
|
|
6331
|
-
|
|
6396
|
+
const result = await repository.find({
|
|
6397
|
+
fields: ['id', 'name', 'sku', 'reviews'],
|
|
6398
|
+
...(limit && {
|
|
6399
|
+
limits: { offset, limit },
|
|
6400
|
+
}),
|
|
6401
|
+
});
|
|
6332
6402
|
data = data.concat(result.data);
|
|
6333
6403
|
count = result.data.length;
|
|
6334
6404
|
offset += limit;
|
|
@@ -6339,7 +6409,13 @@ class ProductReviewOperationsHelper {
|
|
|
6339
6409
|
const { data, getReviewStatus } = params;
|
|
6340
6410
|
return data.reduce((reviews, product) => [
|
|
6341
6411
|
...reviews,
|
|
6342
|
-
...product.reviews.map((review) => (
|
|
6412
|
+
...product.reviews.map((review) => ({
|
|
6413
|
+
...review,
|
|
6414
|
+
reviewStatus: getReviewStatus(review),
|
|
6415
|
+
productId: product.id,
|
|
6416
|
+
productName: product.name,
|
|
6417
|
+
productSku: product.sku,
|
|
6418
|
+
})),
|
|
6343
6419
|
], []);
|
|
6344
6420
|
}
|
|
6345
6421
|
static applyReviewFilters(params) {
|
|
@@ -6383,7 +6459,7 @@ class ProductReviewUpdateHelper {
|
|
|
6383
6459
|
const { productId, reviews, dependencies } = params;
|
|
6384
6460
|
const reviewIds = await Promise.all(reviews.value.map(async (reviewData) => {
|
|
6385
6461
|
const review = await dependencies.findReview(reviewData, productId);
|
|
6386
|
-
return review
|
|
6462
|
+
return review?.id;
|
|
6387
6463
|
}));
|
|
6388
6464
|
await dependencies.mutation('delete_product_review', ['affected_rows'], {
|
|
6389
6465
|
where: {
|
|
@@ -6422,7 +6498,7 @@ class ProductReviewUpdateHelper {
|
|
|
6422
6498
|
static async insertNewReview(reviewData, productId, dependencies) {
|
|
6423
6499
|
const result = await dependencies.mutation('insert_product_review_one', dependencies.reviewsFields, {
|
|
6424
6500
|
object: {
|
|
6425
|
-
value: omit(
|
|
6501
|
+
value: omit({ ...dependencies.bindReviewToHasura(reviewData), product_id: productId.toString() }, ['id']),
|
|
6426
6502
|
type: 'product_review_insert_input',
|
|
6427
6503
|
required: true,
|
|
6428
6504
|
},
|
|
@@ -6515,11 +6591,14 @@ const fieldsConfiguration$4 = [
|
|
|
6515
6591
|
bindPersistData: (value) => {
|
|
6516
6592
|
return {
|
|
6517
6593
|
brand_condition: value.brand,
|
|
6518
|
-
tag_condition:
|
|
6594
|
+
tag_condition: value?.tags || [],
|
|
6519
6595
|
};
|
|
6520
6596
|
},
|
|
6521
6597
|
bindFindFilter: (sentence) => {
|
|
6522
|
-
return
|
|
6598
|
+
return {
|
|
6599
|
+
...(sentence.brand ? { brand_condition: sentence.brand } : {}),
|
|
6600
|
+
...(sentence.tags ? { tag_condition: sentence.tags } : {}),
|
|
6601
|
+
};
|
|
6523
6602
|
},
|
|
6524
6603
|
},
|
|
6525
6604
|
},
|
|
@@ -6531,7 +6610,7 @@ const fieldsConfiguration$4 = [
|
|
|
6531
6610
|
bindPersistData: (value) => ({
|
|
6532
6611
|
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
6533
6612
|
}),
|
|
6534
|
-
from: (filters) =>
|
|
6613
|
+
from: (filters) => filters?.map((filter) => filter?.filter).filter((filter) => filter.enabled) || [],
|
|
6535
6614
|
},
|
|
6536
6615
|
},
|
|
6537
6616
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -6596,11 +6675,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6596
6675
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
6597
6676
|
}
|
|
6598
6677
|
async create(params) {
|
|
6599
|
-
const { images, mostRelevants, metadatas
|
|
6600
|
-
return super.create(
|
|
6678
|
+
const { images, mostRelevants, metadatas, ...data } = params;
|
|
6679
|
+
return super.create({
|
|
6680
|
+
...data,
|
|
6681
|
+
isWishlist: false,
|
|
6682
|
+
metadatas: metadatas || [{ shop: null, description: null, title: null }],
|
|
6683
|
+
mostRelevants: mostRelevants || {
|
|
6601
6684
|
[Shops.GLAMSHOP]: null,
|
|
6602
6685
|
[Shops.MENSMARKET]: null,
|
|
6603
|
-
},
|
|
6686
|
+
},
|
|
6687
|
+
images: images || {
|
|
6604
6688
|
[Shops.GLAMSHOP]: {
|
|
6605
6689
|
brandBanner: null,
|
|
6606
6690
|
brandBannerMobile: null,
|
|
@@ -6611,17 +6695,18 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6611
6695
|
brandBannerMobile: null,
|
|
6612
6696
|
image: null,
|
|
6613
6697
|
},
|
|
6614
|
-
}
|
|
6698
|
+
},
|
|
6699
|
+
});
|
|
6615
6700
|
}
|
|
6616
6701
|
async get(identifiers, optionsCache) {
|
|
6617
6702
|
const id = await this.getId(identifiers.id);
|
|
6618
6703
|
return super.get({ id }, optionsCache);
|
|
6619
6704
|
}
|
|
6620
6705
|
async update(params) {
|
|
6621
|
-
const { id, products, metadatas, filters
|
|
6706
|
+
const { id, products, metadatas, filters, ...data } = params;
|
|
6622
6707
|
const categoryId = +(await this.getId(id));
|
|
6623
6708
|
const [category] = await Promise.all([
|
|
6624
|
-
super.update(
|
|
6709
|
+
super.update({ id: categoryId?.toString(), ...data }),
|
|
6625
6710
|
...(products ? [this.updateProducts(categoryId, { products })] : []),
|
|
6626
6711
|
...(metadatas ? [this.updateMetadata(categoryId, { metadatas })] : []),
|
|
6627
6712
|
...(filters ? [this.updateFilters(categoryId, { filters })] : []),
|
|
@@ -6661,7 +6746,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6661
6746
|
}
|
|
6662
6747
|
async getCategoriesForHome(params) {
|
|
6663
6748
|
const { categoryIds, shop, limit = 4, optionsCache } = params;
|
|
6664
|
-
if (!
|
|
6749
|
+
if (!categoryIds?.length)
|
|
6665
6750
|
return [];
|
|
6666
6751
|
const { firestore, hasura } = CategoryHomeOperationsHelper.separateCategoryIds(categoryIds);
|
|
6667
6752
|
const categories = [];
|
|
@@ -6682,11 +6767,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6682
6767
|
});
|
|
6683
6768
|
}
|
|
6684
6769
|
async mountCategory(params) {
|
|
6685
|
-
var _a, _b;
|
|
6686
6770
|
return CategoryMountOperationsHelper.executeMount(params, {
|
|
6687
6771
|
productRepository: this.productRepository,
|
|
6688
|
-
cacheAdapter:
|
|
6689
|
-
defaultCacheTtl:
|
|
6772
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
6773
|
+
defaultCacheTtl: this.cache?.ttlDefault,
|
|
6690
6774
|
logger: this.logger,
|
|
6691
6775
|
});
|
|
6692
6776
|
}
|
|
@@ -6705,12 +6789,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6705
6789
|
return categoryTree.some((c) => c.id == id.toString());
|
|
6706
6790
|
}
|
|
6707
6791
|
async getId(id) {
|
|
6708
|
-
var _a, _b;
|
|
6709
6792
|
if (!Number.isNaN(+id))
|
|
6710
6793
|
return id;
|
|
6711
6794
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
6712
|
-
if (
|
|
6713
|
-
return
|
|
6795
|
+
if (data?.[0]?.id)
|
|
6796
|
+
return data?.[0]?.id;
|
|
6714
6797
|
throw new NotFoundError(`Category with id ${id} not found`);
|
|
6715
6798
|
}
|
|
6716
6799
|
async updateProducts(categoryId, { products }) {
|
|
@@ -6764,7 +6847,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6764
6847
|
objects: {
|
|
6765
6848
|
type: '[category_metadata_insert_input!]',
|
|
6766
6849
|
required: true,
|
|
6767
|
-
value: metadatas.map((m) => (
|
|
6850
|
+
value: metadatas.map((m) => ({ category_id: categoryId, ...m })),
|
|
6768
6851
|
},
|
|
6769
6852
|
});
|
|
6770
6853
|
return metadatas;
|
|
@@ -6930,7 +7013,7 @@ const fieldsConfiguration$3 = [
|
|
|
6930
7013
|
bindPersistData: (value) => ({
|
|
6931
7014
|
categories: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
6932
7015
|
}),
|
|
6933
|
-
from: (categories) =>
|
|
7016
|
+
from: (categories) => categories?.map((category) => category?.category) || [],
|
|
6934
7017
|
},
|
|
6935
7018
|
},
|
|
6936
7019
|
];
|
|
@@ -6949,7 +7032,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6949
7032
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
6950
7033
|
}
|
|
6951
7034
|
async update(params) {
|
|
6952
|
-
const { options
|
|
7035
|
+
const { options, ...data } = params;
|
|
6953
7036
|
const filter = await super.update(data);
|
|
6954
7037
|
filter.options = await this.updateOptions(+data.id, { options });
|
|
6955
7038
|
return filter;
|
|
@@ -6971,8 +7054,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6971
7054
|
if (hasFilter)
|
|
6972
7055
|
filterOptions.push(hasFilter);
|
|
6973
7056
|
}
|
|
6974
|
-
catch
|
|
6975
|
-
const newOption = await this.filterOptionRepository.create(
|
|
7057
|
+
catch {
|
|
7058
|
+
const newOption = await this.filterOptionRepository.create({ ...options.value[i], filterId });
|
|
6976
7059
|
filterOptions.push(newOption);
|
|
6977
7060
|
}
|
|
6978
7061
|
}
|
|
@@ -6986,8 +7069,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6986
7069
|
if (hasFilter)
|
|
6987
7070
|
filterOptions.push(hasFilter);
|
|
6988
7071
|
}
|
|
6989
|
-
catch
|
|
6990
|
-
const newOption = await this.filterOptionRepository.create(
|
|
7072
|
+
catch {
|
|
7073
|
+
const newOption = await this.filterOptionRepository.create({ ...options[i], filterId });
|
|
6991
7074
|
filterOptions.push(newOption);
|
|
6992
7075
|
}
|
|
6993
7076
|
}
|
|
@@ -7108,13 +7191,13 @@ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
|
|
|
7108
7191
|
filters: {
|
|
7109
7192
|
id: {
|
|
7110
7193
|
operator: Where.IN,
|
|
7111
|
-
value: Array.from(new Set(variantsWithNoData.map((item) =>
|
|
7194
|
+
value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
|
|
7112
7195
|
},
|
|
7113
7196
|
},
|
|
7114
7197
|
});
|
|
7115
7198
|
products.forEach((product) => {
|
|
7116
7199
|
result.data
|
|
7117
|
-
.filter((variant) =>
|
|
7200
|
+
.filter((variant) => variant.product.productId?.toString() === product.id.toString())
|
|
7118
7201
|
.forEach((variant) => {
|
|
7119
7202
|
variant.product.name = product.name;
|
|
7120
7203
|
variant.product.group = product.group;
|
|
@@ -7147,21 +7230,37 @@ const commonFields = [
|
|
|
7147
7230
|
purpose: data.purpose,
|
|
7148
7231
|
}),
|
|
7149
7232
|
bindFindFilter: (filters) => {
|
|
7150
|
-
return
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
|
|
7233
|
+
return {
|
|
7234
|
+
...(filters?.description && { description: filters.description }),
|
|
7235
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
7236
|
+
...(filters.whoMustUse && {
|
|
7237
|
+
who_must_use: filters.whoMustUse,
|
|
7238
|
+
}),
|
|
7239
|
+
...(filters.howToUse && {
|
|
7240
|
+
how_to_use: filters.howToUse,
|
|
7241
|
+
}),
|
|
7242
|
+
...(filters.brand && {
|
|
7243
|
+
brand_description: filters.brand,
|
|
7244
|
+
}),
|
|
7245
|
+
...(filters.ingredients && {
|
|
7246
|
+
ingredients: filters.ingredients,
|
|
7247
|
+
}),
|
|
7248
|
+
...(filters.purpose && {
|
|
7249
|
+
purpose: filters.purpose,
|
|
7250
|
+
}),
|
|
7251
|
+
};
|
|
7161
7252
|
},
|
|
7162
|
-
bindPersistData: (descriptionData) => (
|
|
7163
|
-
|
|
7164
|
-
|
|
7253
|
+
bindPersistData: (descriptionData) => ({
|
|
7254
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
7255
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
7256
|
+
...(descriptionData.whoMustUse && {
|
|
7257
|
+
who_must_use: descriptionData.whoMustUse,
|
|
7258
|
+
}),
|
|
7259
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
7260
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
7261
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
7262
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
7263
|
+
}),
|
|
7165
7264
|
},
|
|
7166
7265
|
},
|
|
7167
7266
|
{ differentials: { columnName: 'differentials' } },
|
|
@@ -7174,13 +7273,13 @@ const commonFields = [
|
|
|
7174
7273
|
{
|
|
7175
7274
|
images: {
|
|
7176
7275
|
columnName: 'images',
|
|
7177
|
-
to: (value) =>
|
|
7276
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7178
7277
|
},
|
|
7179
7278
|
},
|
|
7180
7279
|
{
|
|
7181
7280
|
miniatures: {
|
|
7182
7281
|
columnName: 'miniatures',
|
|
7183
|
-
to: (value) =>
|
|
7282
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7184
7283
|
},
|
|
7185
7284
|
},
|
|
7186
7285
|
'name',
|
|
@@ -7195,19 +7294,31 @@ const commonFields = [
|
|
|
7195
7294
|
subscriberPrice: data.subscriber_price,
|
|
7196
7295
|
}),
|
|
7197
7296
|
bindFindFilter: (filters) => {
|
|
7198
|
-
return
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7297
|
+
return {
|
|
7298
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7299
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7300
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7301
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7302
|
+
}),
|
|
7303
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7304
|
+
subscriber_price: filters.subscriberPrice,
|
|
7305
|
+
}),
|
|
7306
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7307
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7308
|
+
}),
|
|
7309
|
+
};
|
|
7205
7310
|
},
|
|
7206
|
-
bindPersistData: (priceData) => (
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7311
|
+
bindPersistData: (priceData) => ({
|
|
7312
|
+
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
7313
|
+
...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
|
|
7314
|
+
...(priceData.subscriberDiscountPercentage >= 0 && {
|
|
7315
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
7316
|
+
}),
|
|
7317
|
+
...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
7318
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
7319
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
7320
|
+
}),
|
|
7321
|
+
}),
|
|
7211
7322
|
},
|
|
7212
7323
|
},
|
|
7213
7324
|
{ fullPrice: { columnName: 'full_price' } },
|
|
@@ -7222,7 +7333,7 @@ const commonFields = [
|
|
|
7222
7333
|
stock: {
|
|
7223
7334
|
columnName: 'stock',
|
|
7224
7335
|
from: (quantity) => ({ quantity }),
|
|
7225
|
-
to: (value) => (isNil(value
|
|
7336
|
+
to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
|
|
7226
7337
|
},
|
|
7227
7338
|
},
|
|
7228
7339
|
{ hasStock: { columnName: 'has_stock' } },
|
|
@@ -7261,7 +7372,7 @@ const fieldsConfiguration$2 = [
|
|
|
7261
7372
|
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
7262
7373
|
}),
|
|
7263
7374
|
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
7264
|
-
from: (categories) =>
|
|
7375
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
7265
7376
|
},
|
|
7266
7377
|
},
|
|
7267
7378
|
{
|
|
@@ -7337,12 +7448,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7337
7448
|
fields: fieldsConfiguration$2,
|
|
7338
7449
|
cache,
|
|
7339
7450
|
});
|
|
7340
|
-
this.bindReviewToModel = (plain) => ProductReview.toInstance(
|
|
7341
|
-
|
|
7451
|
+
this.bindReviewToModel = (plain) => ProductReview.toInstance({
|
|
7452
|
+
...is(omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
|
|
7453
|
+
createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
|
|
7454
|
+
updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
|
|
7455
|
+
personId: plain.person_id,
|
|
7456
|
+
orderId: plain.order_id,
|
|
7457
|
+
});
|
|
7458
|
+
this.bindReviewToHasura = (review) => ({
|
|
7459
|
+
...is(omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
|
|
7460
|
+
person_id: review.personId,
|
|
7461
|
+
order_id: review.orderId,
|
|
7462
|
+
});
|
|
7342
7463
|
}
|
|
7343
7464
|
async create(params) {
|
|
7344
|
-
const { metadata
|
|
7345
|
-
const product = await super.create(omit(
|
|
7465
|
+
const { metadata, ...data } = params;
|
|
7466
|
+
const product = await super.create(omit({ ...data, metadata: metadata || { description: null, title: null } }, ['reviews']));
|
|
7346
7467
|
try {
|
|
7347
7468
|
product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
|
|
7348
7469
|
}
|
|
@@ -7353,10 +7474,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7353
7474
|
return product;
|
|
7354
7475
|
}
|
|
7355
7476
|
async get(identifiers, options) {
|
|
7356
|
-
var _a;
|
|
7357
7477
|
const product = Number.isNaN(+identifiers.id)
|
|
7358
|
-
? (
|
|
7359
|
-
.data
|
|
7478
|
+
? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
|
|
7479
|
+
.data?.[0]
|
|
7360
7480
|
: await super.get(identifiers, options);
|
|
7361
7481
|
if (product.productId)
|
|
7362
7482
|
throw new NotFoundError('Product not found, it is a variant');
|
|
@@ -7364,19 +7484,21 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7364
7484
|
return product;
|
|
7365
7485
|
}
|
|
7366
7486
|
async find(params, optionsParams) {
|
|
7367
|
-
|
|
7368
|
-
const _o = params || {}, { filters, fields } = _o, options = __rest(_o, ["filters", "fields"]);
|
|
7487
|
+
const { filters, fields, ...options } = params || {};
|
|
7369
7488
|
const bindFields = fields ||
|
|
7370
7489
|
this.fields
|
|
7371
7490
|
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
7372
7491
|
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
7373
|
-
if (
|
|
7374
|
-
|
|
7375
|
-
if (
|
|
7376
|
-
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
return super.find(
|
|
7492
|
+
if (options.options?.minimal?.includes('price'))
|
|
7493
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7494
|
+
if (options.options?.maximum?.includes('price'))
|
|
7495
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7496
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
7497
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
7498
|
+
return super.find({
|
|
7499
|
+
...options,
|
|
7500
|
+
filters: { ...filters, productId: { operator: Where.ISNULL } },
|
|
7501
|
+
fields: [
|
|
7380
7502
|
...bindFields,
|
|
7381
7503
|
...(bindFields.includes('price')
|
|
7382
7504
|
? [
|
|
@@ -7385,11 +7507,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7385
7507
|
'fullPrice',
|
|
7386
7508
|
]
|
|
7387
7509
|
: []),
|
|
7388
|
-
]
|
|
7510
|
+
],
|
|
7511
|
+
}, optionsParams);
|
|
7389
7512
|
}
|
|
7390
7513
|
async getBySlug(slug, options) {
|
|
7391
|
-
|
|
7392
|
-
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)) {
|
|
7514
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7393
7515
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
7394
7516
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7395
7517
|
if (cachedData) {
|
|
@@ -7408,70 +7530,68 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7408
7530
|
});
|
|
7409
7531
|
if (!result.data.length)
|
|
7410
7532
|
return null;
|
|
7411
|
-
const product =
|
|
7533
|
+
const product = result?.data?.shift();
|
|
7412
7534
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
7413
|
-
if (
|
|
7535
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7414
7536
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
7415
7537
|
await this.cache.cacheAdapter.set({
|
|
7416
7538
|
key: cacheKey,
|
|
7417
7539
|
data: serialize(product),
|
|
7418
|
-
expirationInSeconds:
|
|
7540
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7419
7541
|
});
|
|
7420
7542
|
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7421
7543
|
}
|
|
7422
7544
|
return product;
|
|
7423
7545
|
}
|
|
7424
7546
|
async update(params) {
|
|
7425
|
-
const
|
|
7547
|
+
const { kitProducts, reviews, id: checkId, metadata, ...data } = omit(params, ['categories', 'rate']);
|
|
7426
7548
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
7427
7549
|
const id = await this.getId(plainData.id);
|
|
7428
|
-
const product = await super.update(
|
|
7550
|
+
const product = await super.update({ id, ...data });
|
|
7429
7551
|
product.kitProducts = kitProducts && (await this.updateKitProducts(+id, { kitProducts }));
|
|
7430
7552
|
product.reviews = reviews && (await this.updateReviews(+id, { reviews }));
|
|
7431
7553
|
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
7432
7554
|
return product;
|
|
7433
7555
|
}
|
|
7434
7556
|
async fetchProductReviews(filters, options) {
|
|
7435
|
-
var _a, _b, _c, _d, _e;
|
|
7436
7557
|
const cacheKey = ProductReviewCacheHelper.generateProductReviewsCacheKey(filters, this.model.name);
|
|
7437
7558
|
const dependencies = {
|
|
7438
|
-
cacheAdapter:
|
|
7559
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
7439
7560
|
logger: this.logger,
|
|
7440
7561
|
modelName: this.model.name,
|
|
7441
|
-
defaultTtl:
|
|
7562
|
+
defaultTtl: this.cache?.ttlDefault,
|
|
7442
7563
|
};
|
|
7443
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7564
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7444
7565
|
const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
|
|
7445
7566
|
if (cachedData)
|
|
7446
7567
|
return cachedData;
|
|
7447
7568
|
}
|
|
7448
|
-
const limit =
|
|
7569
|
+
const limit = filters?.limit || 500;
|
|
7449
7570
|
const data = await ProductReviewOperationsHelper.fetchAllProductsWithReviews({ repository: this, limit });
|
|
7450
7571
|
const reviews = ProductReviewOperationsHelper.processProductsToReviews({
|
|
7451
7572
|
data,
|
|
7452
7573
|
getReviewStatus: this.getReviewStatus.bind(this),
|
|
7453
7574
|
});
|
|
7454
7575
|
const filteredReviews = ProductReviewOperationsHelper.applyReviewFilters({ reviews, filters });
|
|
7455
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7576
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7456
7577
|
await ProductReviewCacheHelper.saveToCache({
|
|
7457
7578
|
key: cacheKey,
|
|
7458
7579
|
data: filteredReviews,
|
|
7459
|
-
ttl:
|
|
7580
|
+
ttl: options?.cache?.ttl,
|
|
7460
7581
|
dependencies,
|
|
7461
7582
|
});
|
|
7462
7583
|
}
|
|
7463
7584
|
return filteredReviews;
|
|
7464
7585
|
}
|
|
7465
7586
|
async fetchReviews(status, options) {
|
|
7466
|
-
var _a, _b, _c, _d, _e;
|
|
7467
7587
|
const cacheKey = ProductReviewCacheHelper.generateReviewsStatusCacheKey(status, this.model.name);
|
|
7468
7588
|
const dependencies = {
|
|
7469
|
-
cacheAdapter:
|
|
7589
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
7470
7590
|
logger: this.logger,
|
|
7471
7591
|
modelName: this.model.name,
|
|
7472
|
-
defaultTtl:
|
|
7592
|
+
defaultTtl: this.cache?.ttlDefault,
|
|
7473
7593
|
};
|
|
7474
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7594
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7475
7595
|
const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
|
|
7476
7596
|
if (cachedData)
|
|
7477
7597
|
return cachedData;
|
|
@@ -7482,18 +7602,26 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7482
7602
|
reviewsFields: this.reviewsFields,
|
|
7483
7603
|
};
|
|
7484
7604
|
const reviews = await ProductFetchReviewsHelper.executeQuery(status, fetchDependencies);
|
|
7485
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7605
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7486
7606
|
await ProductReviewCacheHelper.saveToCache({
|
|
7487
7607
|
key: cacheKey,
|
|
7488
7608
|
data: reviews,
|
|
7489
|
-
ttl:
|
|
7609
|
+
ttl: options?.cache?.ttl,
|
|
7490
7610
|
dependencies,
|
|
7491
7611
|
});
|
|
7492
7612
|
}
|
|
7493
7613
|
return reviews;
|
|
7494
7614
|
}
|
|
7495
7615
|
async findCatalog(params, mainGender, options) {
|
|
7496
|
-
const result = await this.find(
|
|
7616
|
+
const result = await this.find({
|
|
7617
|
+
...params,
|
|
7618
|
+
filters: { ...params.filters, published: true },
|
|
7619
|
+
orderBy: {
|
|
7620
|
+
hasStock: 'desc',
|
|
7621
|
+
...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
|
|
7622
|
+
...omit(params.orderBy, ['hasStock', 'intGender']),
|
|
7623
|
+
},
|
|
7624
|
+
}, options);
|
|
7497
7625
|
return result;
|
|
7498
7626
|
}
|
|
7499
7627
|
async cleanShoppingCountFromIds(ids) {
|
|
@@ -7564,17 +7692,15 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7564
7692
|
return plainData.metadata;
|
|
7565
7693
|
}
|
|
7566
7694
|
async getId(id) {
|
|
7567
|
-
var _a, _b;
|
|
7568
7695
|
if (!Number.isNaN(+id))
|
|
7569
7696
|
return id;
|
|
7570
7697
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
7571
|
-
if (
|
|
7572
|
-
return
|
|
7698
|
+
if (data?.[0]?.id)
|
|
7699
|
+
return data?.[0]?.id;
|
|
7573
7700
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7574
7701
|
}
|
|
7575
7702
|
async findReviewsByProduct(productId, options) {
|
|
7576
|
-
|
|
7577
|
-
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)) {
|
|
7703
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7578
7704
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7579
7705
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7580
7706
|
if (cachedData) {
|
|
@@ -7591,13 +7717,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7591
7717
|
required: true,
|
|
7592
7718
|
},
|
|
7593
7719
|
});
|
|
7594
|
-
const reviews = data
|
|
7595
|
-
if (
|
|
7720
|
+
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
7721
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
7596
7722
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7597
7723
|
await this.cache.cacheAdapter.set({
|
|
7598
7724
|
key: cacheKey,
|
|
7599
7725
|
data: serialize(reviews),
|
|
7600
|
-
expirationInSeconds:
|
|
7726
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7601
7727
|
});
|
|
7602
7728
|
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7603
7729
|
}
|
|
@@ -7621,23 +7747,32 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7621
7747
|
async getReviewByPersonId(personId, productId, orderId) {
|
|
7622
7748
|
const { product_review: data } = await this.query('product_review', this.reviewsFields, {
|
|
7623
7749
|
where: {
|
|
7624
|
-
value:
|
|
7750
|
+
value: {
|
|
7751
|
+
product_id: { _eq: productId },
|
|
7752
|
+
person_id: { _eq: personId },
|
|
7753
|
+
...(orderId && { order_id: { _eq: orderId } }),
|
|
7754
|
+
},
|
|
7625
7755
|
type: 'product_review_bool_exp',
|
|
7626
7756
|
required: true,
|
|
7627
7757
|
},
|
|
7628
7758
|
});
|
|
7629
|
-
return
|
|
7759
|
+
return data?.[0] && this.bindReviewToModel(data[0]);
|
|
7630
7760
|
}
|
|
7631
7761
|
async getReviewByAuthorAndEmail(params) {
|
|
7632
7762
|
const { author, email, productId, orderId } = params;
|
|
7633
7763
|
const { product_review: data } = await this.query('product_review', this.reviewsFields, {
|
|
7634
7764
|
where: {
|
|
7635
|
-
value:
|
|
7765
|
+
value: {
|
|
7766
|
+
product_id: { _eq: productId },
|
|
7767
|
+
author: { _eq: author },
|
|
7768
|
+
email: { _eq: email },
|
|
7769
|
+
...(orderId && { order_id: { _eq: orderId } }),
|
|
7770
|
+
},
|
|
7636
7771
|
type: 'product_review_bool_exp',
|
|
7637
7772
|
required: true,
|
|
7638
7773
|
},
|
|
7639
7774
|
});
|
|
7640
|
-
return
|
|
7775
|
+
return data?.[0] && this.bindReviewToModel(data[0]);
|
|
7641
7776
|
}
|
|
7642
7777
|
async productVariantFullReport() {
|
|
7643
7778
|
const dependencies = {
|
|
@@ -7786,7 +7921,16 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
|
|
|
7786
7921
|
});
|
|
7787
7922
|
}
|
|
7788
7923
|
async getNotificationsReport(params, orderBy, pagination) {
|
|
7789
|
-
const query =
|
|
7924
|
+
const query = {
|
|
7925
|
+
...(params.productId && { product_id: { _eq: params.productId } }),
|
|
7926
|
+
...(params.ean && { ean: { _eq: params.ean } }),
|
|
7927
|
+
...(params.sku && { sku: { _eq: params.sku } }),
|
|
7928
|
+
...(params.name && { name: { _iregex: params.name } }),
|
|
7929
|
+
...(params.categoryId && { category_id: { _eq: params.categoryId } }),
|
|
7930
|
+
...(params.category && { category: { _iregex: params.category } }),
|
|
7931
|
+
...(params.reference && { category_reference: { _eq: params.reference } }),
|
|
7932
|
+
...(params.emailsCount && { emails_registered: { _eq: params.emailsCount } }),
|
|
7933
|
+
};
|
|
7790
7934
|
const orderByField = {
|
|
7791
7935
|
[orderBy.field]: orderBy.direction,
|
|
7792
7936
|
};
|
|
@@ -7802,8 +7946,8 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
|
|
|
7802
7946
|
required: true,
|
|
7803
7947
|
},
|
|
7804
7948
|
});
|
|
7805
|
-
const data =
|
|
7806
|
-
? reportStockNotification.slice(pagination
|
|
7949
|
+
const data = pagination?.limit
|
|
7950
|
+
? reportStockNotification.slice(pagination?.offset, pagination?.offset + pagination?.limit)
|
|
7807
7951
|
: reportStockNotification;
|
|
7808
7952
|
return {
|
|
7809
7953
|
data,
|
|
@@ -7819,7 +7963,7 @@ const fieldsConfiguration$1 = [
|
|
|
7819
7963
|
productId: {
|
|
7820
7964
|
columnName: 'main_product_id',
|
|
7821
7965
|
to: (value) => +value,
|
|
7822
|
-
from: (value) => value
|
|
7966
|
+
from: (value) => value?.toString(),
|
|
7823
7967
|
},
|
|
7824
7968
|
},
|
|
7825
7969
|
{ EAN: { columnName: 'ean' } },
|
|
@@ -7836,19 +7980,31 @@ const fieldsConfiguration$1 = [
|
|
|
7836
7980
|
}),
|
|
7837
7981
|
bindFindFilter: (sentence) => {
|
|
7838
7982
|
const filters = Object.values(sentence).shift();
|
|
7839
|
-
return
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7983
|
+
return {
|
|
7984
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7985
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7986
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7987
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7988
|
+
}),
|
|
7989
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7990
|
+
subscriber_price: filters.subscriberPrice,
|
|
7991
|
+
}),
|
|
7992
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7993
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7994
|
+
}),
|
|
7995
|
+
};
|
|
7846
7996
|
},
|
|
7847
|
-
bindPersistData: (priceData) => (
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
|
|
7997
|
+
bindPersistData: (priceData) => ({
|
|
7998
|
+
...((priceData?.price || 0) >= 0 && { price: priceData.price }),
|
|
7999
|
+
...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
|
|
8000
|
+
...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
|
|
8001
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
8002
|
+
}),
|
|
8003
|
+
...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
8004
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
8005
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
8006
|
+
}),
|
|
8007
|
+
}),
|
|
7852
8008
|
},
|
|
7853
8009
|
},
|
|
7854
8010
|
{ fullPrice: { columnName: 'full_price' } },
|
|
@@ -7860,7 +8016,7 @@ const fieldsConfiguration$1 = [
|
|
|
7860
8016
|
stock: {
|
|
7861
8017
|
columnName: 'stock',
|
|
7862
8018
|
from: (quantity) => ({ quantity }),
|
|
7863
|
-
to: (value) => (isNil(value
|
|
8019
|
+
to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
|
|
7864
8020
|
},
|
|
7865
8021
|
},
|
|
7866
8022
|
{ hasStock: { columnName: 'has_stock' } },
|
|
@@ -7893,41 +8049,39 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7893
8049
|
});
|
|
7894
8050
|
}
|
|
7895
8051
|
async get(identifiers) {
|
|
7896
|
-
var _a;
|
|
7897
8052
|
if (!identifiers.id) {
|
|
7898
8053
|
throw new NotFoundError('Variant ID is required');
|
|
7899
8054
|
}
|
|
7900
8055
|
const variant = Number.isNaN(+identifiers.id)
|
|
7901
|
-
? (
|
|
8056
|
+
? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
|
|
7902
8057
|
: await super.get(identifiers);
|
|
7903
8058
|
if (!variant.productId)
|
|
7904
8059
|
throw new NotFoundError('Variant not found, it is a product');
|
|
7905
8060
|
return variant;
|
|
7906
8061
|
}
|
|
7907
8062
|
async find(params) {
|
|
7908
|
-
const
|
|
7909
|
-
return super.find(
|
|
8063
|
+
const { filters, ...options } = params || {};
|
|
8064
|
+
return super.find({ ...options, filters: { productId: { operator: Where.ISNOTNULL }, ...filters } });
|
|
7910
8065
|
}
|
|
7911
8066
|
async update(params) {
|
|
7912
|
-
const { productId, id: checkId
|
|
8067
|
+
const { productId, id: checkId, ...data } = params;
|
|
7913
8068
|
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
7914
8069
|
if (!dataWithProductId.id) {
|
|
7915
8070
|
throw new NotFoundError('Variant ID is required for update');
|
|
7916
8071
|
}
|
|
7917
8072
|
const id = await this.getId(dataWithProductId.id);
|
|
7918
|
-
const product = await super.update(
|
|
8073
|
+
const product = await super.update({ id, ...data });
|
|
7919
8074
|
if (dataWithProductId.productId) {
|
|
7920
8075
|
product.productId = dataWithProductId.productId;
|
|
7921
8076
|
}
|
|
7922
8077
|
return product;
|
|
7923
8078
|
}
|
|
7924
8079
|
async getId(id) {
|
|
7925
|
-
var _a, _b;
|
|
7926
8080
|
if (!Number.isNaN(+id))
|
|
7927
8081
|
return id;
|
|
7928
8082
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
7929
|
-
if (
|
|
7930
|
-
return
|
|
8083
|
+
if (data?.[0]?.id)
|
|
8084
|
+
return data?.[0]?.id;
|
|
7931
8085
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7932
8086
|
}
|
|
7933
8087
|
}
|
|
@@ -7958,11 +8112,14 @@ const fieldsConfiguration = [
|
|
|
7958
8112
|
bindPersistData: (value) => {
|
|
7959
8113
|
return {
|
|
7960
8114
|
brand_condition: value.brand,
|
|
7961
|
-
tag_condition:
|
|
8115
|
+
tag_condition: value?.tags || [],
|
|
7962
8116
|
};
|
|
7963
8117
|
},
|
|
7964
8118
|
bindFindFilter: (sentence) => {
|
|
7965
|
-
return
|
|
8119
|
+
return {
|
|
8120
|
+
...(sentence.brand ? { brand_condition: sentence.brand } : {}),
|
|
8121
|
+
...(sentence.tags ? { tag_condition: sentence.tags } : {}),
|
|
8122
|
+
};
|
|
7966
8123
|
},
|
|
7967
8124
|
},
|
|
7968
8125
|
},
|
|
@@ -7974,7 +8131,7 @@ const fieldsConfiguration = [
|
|
|
7974
8131
|
bindPersistData: (value) => ({
|
|
7975
8132
|
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
7976
8133
|
}),
|
|
7977
|
-
from: (filters) =>
|
|
8134
|
+
from: (filters) => filters?.map((filter) => filter?.filter) || [],
|
|
7978
8135
|
},
|
|
7979
8136
|
},
|
|
7980
8137
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -8042,12 +8199,18 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8042
8199
|
this.categoryProductRepository = categoryProductRepository;
|
|
8043
8200
|
}
|
|
8044
8201
|
async create(params) {
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8202
|
+
const { images, mostRelevants, metadatas, ...data } = params;
|
|
8203
|
+
return super.create({
|
|
8204
|
+
...data,
|
|
8205
|
+
isWishlist: true,
|
|
8206
|
+
isCollection: true,
|
|
8207
|
+
brandCategory: false,
|
|
8208
|
+
metadatas: metadatas || [{ shop: data.shop ?? null, description: data.description, title: data.name }],
|
|
8209
|
+
mostRelevants: mostRelevants || {
|
|
8048
8210
|
[Shops.GLAMSHOP]: null,
|
|
8049
8211
|
[Shops.MENSMARKET]: null,
|
|
8050
|
-
},
|
|
8212
|
+
},
|
|
8213
|
+
images: images || {
|
|
8051
8214
|
[Shops.GLAMSHOP]: {
|
|
8052
8215
|
brandBanner: null,
|
|
8053
8216
|
brandBannerMobile: null,
|
|
@@ -8058,7 +8221,8 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8058
8221
|
brandBannerMobile: null,
|
|
8059
8222
|
image: null,
|
|
8060
8223
|
},
|
|
8061
|
-
}
|
|
8224
|
+
},
|
|
8225
|
+
});
|
|
8062
8226
|
}
|
|
8063
8227
|
async get(identifiers) {
|
|
8064
8228
|
const data = await super.get(identifiers);
|
|
@@ -8067,14 +8231,20 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8067
8231
|
return data;
|
|
8068
8232
|
}
|
|
8069
8233
|
async find(params) {
|
|
8070
|
-
const { filters
|
|
8071
|
-
return await super.find(
|
|
8234
|
+
const { filters, ...rest } = params;
|
|
8235
|
+
return await super.find({
|
|
8236
|
+
...rest,
|
|
8237
|
+
filters: {
|
|
8238
|
+
...filters,
|
|
8239
|
+
isWishlist: { operator: Where.EQUALS, value: true },
|
|
8240
|
+
},
|
|
8241
|
+
});
|
|
8072
8242
|
}
|
|
8073
8243
|
async update(params) {
|
|
8074
|
-
const
|
|
8244
|
+
const { id: checkId, metadatas, ...data } = omit(params, ['products', 'filters']);
|
|
8075
8245
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
8076
8246
|
const id = plainData.id;
|
|
8077
|
-
const category = await super.update(
|
|
8247
|
+
const category = await super.update({ id, ...data, isWishlist: true, isCollection: true, brandCategory: false });
|
|
8078
8248
|
category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
|
|
8079
8249
|
return category;
|
|
8080
8250
|
}
|
|
@@ -8137,11 +8307,22 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8137
8307
|
return data;
|
|
8138
8308
|
}
|
|
8139
8309
|
async findBfluOrGlamgirlWishlists(params, shops) {
|
|
8140
|
-
|
|
8141
|
-
|
|
8310
|
+
return this.find({
|
|
8311
|
+
...params,
|
|
8312
|
+
filters: {
|
|
8313
|
+
...params.filters,
|
|
8314
|
+
published: true,
|
|
8315
|
+
shops: { operator: Where.LIKE, value: shops },
|
|
8316
|
+
personType: params.filters?.personType ?? {
|
|
8142
8317
|
operator: Where.IN,
|
|
8143
8318
|
value: [PersonTypes.BFLU, PersonTypes.GLAMGIRL],
|
|
8144
|
-
}
|
|
8319
|
+
},
|
|
8320
|
+
},
|
|
8321
|
+
orderBy: {
|
|
8322
|
+
personHasPhoto: 'desc',
|
|
8323
|
+
...omit(params.orderBy, ['personHasPhoto']),
|
|
8324
|
+
},
|
|
8325
|
+
});
|
|
8145
8326
|
}
|
|
8146
8327
|
getCategoriesForHome() {
|
|
8147
8328
|
return;
|
|
@@ -8349,7 +8530,7 @@ class PagarmePaymentFactoryHelper {
|
|
|
8349
8530
|
checkoutId: checkout.id,
|
|
8350
8531
|
totalPrice: checkout.totalPrice,
|
|
8351
8532
|
paymentProvider: PaymentProviders.PAGARME,
|
|
8352
|
-
transaction:
|
|
8533
|
+
transaction: { ...resultData, paidAt: new Date() },
|
|
8353
8534
|
});
|
|
8354
8535
|
return payment;
|
|
8355
8536
|
}
|
|
@@ -8376,7 +8557,6 @@ class PagarmeCardAxiosAdapter {
|
|
|
8376
8557
|
this.orderBlockedRepository = orderBlockedRepository;
|
|
8377
8558
|
}
|
|
8378
8559
|
async pay(checkout, card) {
|
|
8379
|
-
var _a;
|
|
8380
8560
|
try {
|
|
8381
8561
|
const result = await PagarmePaymentOperationsHelper.executePaymentRequest({
|
|
8382
8562
|
checkout,
|
|
@@ -8402,7 +8582,7 @@ class PagarmeCardAxiosAdapter {
|
|
|
8402
8582
|
if (error instanceof PaymentError) {
|
|
8403
8583
|
throw error;
|
|
8404
8584
|
}
|
|
8405
|
-
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout,
|
|
8585
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
8406
8586
|
}
|
|
8407
8587
|
}
|
|
8408
8588
|
async addCard(card) {
|
|
@@ -8469,7 +8649,10 @@ class PagarmeCardAxiosAdapter {
|
|
|
8469
8649
|
const { data } = await axios({
|
|
8470
8650
|
method: 'POST',
|
|
8471
8651
|
url: `${this.credentials.URL}/transactions`,
|
|
8472
|
-
data:
|
|
8652
|
+
data: {
|
|
8653
|
+
...info,
|
|
8654
|
+
api_key: this.credentials.API_KEY,
|
|
8655
|
+
},
|
|
8473
8656
|
});
|
|
8474
8657
|
return data;
|
|
8475
8658
|
}
|
|
@@ -8480,7 +8663,6 @@ class PagarmeCardAxiosAdapter {
|
|
|
8480
8663
|
}
|
|
8481
8664
|
}
|
|
8482
8665
|
createCardPayment(checkout, card) {
|
|
8483
|
-
var _a, _b, _c, _d, _e, _f;
|
|
8484
8666
|
return {
|
|
8485
8667
|
api_key: this.credentials.API_KEY,
|
|
8486
8668
|
amount: Math.floor(checkout.totalPrice * 100),
|
|
@@ -8507,14 +8689,14 @@ class PagarmeCardAxiosAdapter {
|
|
|
8507
8689
|
name: checkout.user.displayName,
|
|
8508
8690
|
address: {
|
|
8509
8691
|
country: 'br',
|
|
8510
|
-
state: checkout.billingAddress ? checkout.billingAddress.state :
|
|
8511
|
-
city: checkout.billingAddress ? checkout.billingAddress.city :
|
|
8512
|
-
neighborhood: checkout.billingAddress ? checkout.billingAddress.district :
|
|
8513
|
-
street: checkout.billingAddress ? checkout.billingAddress.street :
|
|
8514
|
-
street_number: checkout.billingAddress ? checkout.billingAddress.number :
|
|
8692
|
+
state: checkout.billingAddress ? checkout.billingAddress.state : checkout.shippingAddress?.state,
|
|
8693
|
+
city: checkout.billingAddress ? checkout.billingAddress.city : checkout.shippingAddress?.city,
|
|
8694
|
+
neighborhood: checkout.billingAddress ? checkout.billingAddress.district : checkout.shippingAddress?.district,
|
|
8695
|
+
street: checkout.billingAddress ? checkout.billingAddress.street : checkout.shippingAddress?.street,
|
|
8696
|
+
street_number: checkout.billingAddress ? checkout.billingAddress.number : checkout.shippingAddress?.number,
|
|
8515
8697
|
zipcode: checkout.billingAddress
|
|
8516
8698
|
? checkout.billingAddress.zip.replace('-', '')
|
|
8517
|
-
:
|
|
8699
|
+
: checkout.shippingAddress?.zip.replace('-', ''),
|
|
8518
8700
|
},
|
|
8519
8701
|
},
|
|
8520
8702
|
items: checkout.lineItems.map((item) => {
|
|
@@ -8536,7 +8718,6 @@ class PagarmePixAxiosAdapter {
|
|
|
8536
8718
|
this.paymentRepository = paymentRepository;
|
|
8537
8719
|
}
|
|
8538
8720
|
async pay(checkout) {
|
|
8539
|
-
var _a;
|
|
8540
8721
|
try {
|
|
8541
8722
|
const payload = this.createPixPayment(checkout);
|
|
8542
8723
|
const result = await axios({
|
|
@@ -8560,7 +8741,7 @@ class PagarmePixAxiosAdapter {
|
|
|
8560
8741
|
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
8561
8742
|
checkoutId: checkout.id,
|
|
8562
8743
|
userEmail: checkout.user.email,
|
|
8563
|
-
info:
|
|
8744
|
+
info: error.response?.data,
|
|
8564
8745
|
});
|
|
8565
8746
|
}
|
|
8566
8747
|
}
|