@infrab4a/connect 5.0.0-alpha.9 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +707 -533
- package/index.esm.js +708 -534
- package/package.json +1 -1
- package/src/infra/firebase/firestore/mixins/helpers/firestore-operations.helper.d.ts +1 -1
- package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
- package/src/utils/circular-dependencies.d.ts +0 -4
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';
|
|
@@ -99,25 +99,15 @@ class PaymentProviderFactory {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
/**
|
|
103
|
-
* Este arquivo define funções para resolver dependências circulares
|
|
104
|
-
* em ambiente ESM, onde não podemos usar require()
|
|
105
|
-
*/
|
|
106
|
-
// Armazenamento global para classes registradas
|
|
107
102
|
const registry = new Map();
|
|
108
|
-
// Registrar uma classe na resolução de dependências circulares
|
|
109
103
|
function registerClass(name, classConstructor) {
|
|
110
104
|
registry.set(name, classConstructor);
|
|
111
105
|
}
|
|
112
|
-
// Obter uma classe registrada
|
|
113
106
|
function getClass(name) {
|
|
114
107
|
return registry.get(name);
|
|
115
108
|
}
|
|
116
|
-
// Função de resolução para class-transformer
|
|
117
109
|
function resolveClass(name) {
|
|
118
110
|
return () => {
|
|
119
|
-
// Forçamos o retorno de uma função que retorna a classe
|
|
120
|
-
// ao invés da classe diretamente para evitar problemas com o decorator
|
|
121
111
|
return getClass(name);
|
|
122
112
|
};
|
|
123
113
|
}
|
|
@@ -191,7 +181,7 @@ class ReflectHelper {
|
|
|
191
181
|
return Reflect.getMetadata(key, target, property) || null;
|
|
192
182
|
}
|
|
193
183
|
}
|
|
194
|
-
catch
|
|
184
|
+
catch {
|
|
195
185
|
return null;
|
|
196
186
|
}
|
|
197
187
|
}
|
|
@@ -501,7 +491,7 @@ function Debug(opts) {
|
|
|
501
491
|
|
|
502
492
|
const ASYNC_IDENTIFIER = 'async';
|
|
503
493
|
function Log(options = {}) {
|
|
504
|
-
return Trace(
|
|
494
|
+
return Trace({ level: 'log', ...options });
|
|
505
495
|
}
|
|
506
496
|
function Trace(options = {}) {
|
|
507
497
|
return function (target, propertyKey, propertyDescriptor) {
|
|
@@ -601,7 +591,7 @@ class BaseModel {
|
|
|
601
591
|
get identifier() {
|
|
602
592
|
const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
|
|
603
593
|
const data = this;
|
|
604
|
-
return fields.reduce((object, field) => (
|
|
594
|
+
return fields.reduce((object, field) => ({ ...object, [field]: data[field] }), {});
|
|
605
595
|
}
|
|
606
596
|
get identifiersFields() {
|
|
607
597
|
return this.constructor.identifiersFields;
|
|
@@ -666,8 +656,7 @@ class Category extends BaseModel {
|
|
|
666
656
|
return ['id'];
|
|
667
657
|
}
|
|
668
658
|
get glamImages() {
|
|
669
|
-
|
|
670
|
-
return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[Shops.GLAMSHOP])
|
|
659
|
+
return this.images?.[Shops.GLAMSHOP]
|
|
671
660
|
? this.images[Shops.GLAMSHOP]
|
|
672
661
|
: {
|
|
673
662
|
brandBanner: null,
|
|
@@ -676,8 +665,7 @@ class Category extends BaseModel {
|
|
|
676
665
|
};
|
|
677
666
|
}
|
|
678
667
|
get mensImages() {
|
|
679
|
-
|
|
680
|
-
return ((_a = this.images) === null || _a === void 0 ? void 0 : _a[Shops.MENSMARKET])
|
|
668
|
+
return this.images?.[Shops.MENSMARKET]
|
|
681
669
|
? this.images[Shops.MENSMARKET]
|
|
682
670
|
: {
|
|
683
671
|
brandBanner: null,
|
|
@@ -692,8 +680,7 @@ class Category extends BaseModel {
|
|
|
692
680
|
return this.metadatas.find((metadata) => metadata.shop === Shops.MENSMARKET);
|
|
693
681
|
}
|
|
694
682
|
getMostRelevantByShop(shop) {
|
|
695
|
-
|
|
696
|
-
return ((_a = this.mostRelevants) === null || _a === void 0 ? void 0 : _a[shop]) || [];
|
|
683
|
+
return this.mostRelevants?.[shop] || [];
|
|
697
684
|
}
|
|
698
685
|
}
|
|
699
686
|
__decorate([
|
|
@@ -1426,10 +1413,18 @@ class Authentication {
|
|
|
1426
1413
|
return signInMethod === SignInMethods.EMAIL_PASSWORD ? 'signInWithEmailAndPassword' : 'signInWithGoogle';
|
|
1427
1414
|
}
|
|
1428
1415
|
async createsUserByCredential(user) {
|
|
1429
|
-
|
|
1430
|
-
const
|
|
1431
|
-
|
|
1432
|
-
|
|
1416
|
+
const [firstName, lastName] = user.displayName?.split(/\s/) ?? [];
|
|
1417
|
+
const person = User.toInstance({
|
|
1418
|
+
...user,
|
|
1419
|
+
cpf: '',
|
|
1420
|
+
birthday: new Date(),
|
|
1421
|
+
firstName,
|
|
1422
|
+
lastName,
|
|
1423
|
+
acceptsNewsletter: false,
|
|
1424
|
+
area: Area.Transactional,
|
|
1425
|
+
officePosition: OfficePosition.Intern,
|
|
1426
|
+
type: UserType.Collaborator,
|
|
1427
|
+
});
|
|
1433
1428
|
return this.userRepository.create(person);
|
|
1434
1429
|
}
|
|
1435
1430
|
}
|
|
@@ -1478,8 +1473,15 @@ class Register {
|
|
|
1478
1473
|
password: params.password,
|
|
1479
1474
|
});
|
|
1480
1475
|
delete params.password;
|
|
1481
|
-
const user = await this.userRepository.create(
|
|
1482
|
-
|
|
1476
|
+
const user = await this.userRepository.create({
|
|
1477
|
+
...params,
|
|
1478
|
+
id: auth.id,
|
|
1479
|
+
email,
|
|
1480
|
+
displayName,
|
|
1481
|
+
type: UserType.B2C,
|
|
1482
|
+
dateCreated: new Date(),
|
|
1483
|
+
dateModified: new Date(),
|
|
1484
|
+
});
|
|
1483
1485
|
return user;
|
|
1484
1486
|
}
|
|
1485
1487
|
}
|
|
@@ -1673,8 +1675,7 @@ class AntifraudBankSlipService {
|
|
|
1673
1675
|
this.MAX_ORDER_VALUE = 5000;
|
|
1674
1676
|
}
|
|
1675
1677
|
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)) {
|
|
1678
|
+
if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !checkout.user?.isSubscriber) {
|
|
1678
1679
|
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
1679
1680
|
checkout,
|
|
1680
1681
|
blockType: 'Boleto not authorized',
|
|
@@ -1685,7 +1686,7 @@ class AntifraudBankSlipService {
|
|
|
1685
1686
|
checkoutId: checkout.id,
|
|
1686
1687
|
userEmail: checkout.user.email,
|
|
1687
1688
|
info: {
|
|
1688
|
-
isSubscriber:
|
|
1689
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1689
1690
|
subtotal: checkout.subTotalPrice,
|
|
1690
1691
|
total: checkout.totalPrice,
|
|
1691
1692
|
},
|
|
@@ -1709,14 +1710,13 @@ class AntifraudCardService {
|
|
|
1709
1710
|
return true;
|
|
1710
1711
|
}
|
|
1711
1712
|
async validateBlockedOrderAttempts(checkout, card) {
|
|
1712
|
-
var _a;
|
|
1713
1713
|
const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
|
|
1714
1714
|
if (!isValid) {
|
|
1715
1715
|
throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
|
|
1716
1716
|
checkoutId: checkout.id,
|
|
1717
1717
|
userEmail: checkout.user.email,
|
|
1718
1718
|
info: {
|
|
1719
|
-
isSubscriber:
|
|
1719
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1720
1720
|
subtotal: checkout.subTotalPrice,
|
|
1721
1721
|
total: checkout.totalPrice,
|
|
1722
1722
|
},
|
|
@@ -1724,14 +1724,13 @@ class AntifraudCardService {
|
|
|
1724
1724
|
}
|
|
1725
1725
|
}
|
|
1726
1726
|
async validateDayAndWeekOrderLimits(checkout, card) {
|
|
1727
|
-
var _a;
|
|
1728
1727
|
const isValid = await this.verifyDayAndWeekOrders(checkout, card);
|
|
1729
1728
|
if (!isValid) {
|
|
1730
1729
|
throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
|
|
1731
1730
|
checkoutId: checkout.id,
|
|
1732
1731
|
userEmail: checkout.user.email,
|
|
1733
1732
|
info: {
|
|
1734
|
-
isSubscriber:
|
|
1733
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1735
1734
|
subtotal: checkout.subTotalPrice,
|
|
1736
1735
|
total: checkout.totalPrice,
|
|
1737
1736
|
},
|
|
@@ -1760,17 +1759,16 @@ class AntifraudCardService {
|
|
|
1760
1759
|
return { day, endOfDay };
|
|
1761
1760
|
}
|
|
1762
1761
|
async getBlockedOrdersByMultipleCriteria(checkout, dateRange) {
|
|
1763
|
-
var _a, _b, _c, _d;
|
|
1764
1762
|
const { day, endOfDay } = dateRange;
|
|
1765
1763
|
const dateFilter = [
|
|
1766
1764
|
{ operator: Where.GTE, value: new Date(day) },
|
|
1767
1765
|
{ operator: Where.LTE, value: new Date(endOfDay) },
|
|
1768
1766
|
];
|
|
1769
1767
|
const [ordersBlockedWithCpf, ordersBlockedWithEmail, ordersBlockedWithCep, ordersBlockedWithPhone] = await Promise.all([
|
|
1770
|
-
this.getBlockedOrdersByCpf(
|
|
1771
|
-
this.getBlockedOrdersByEmail(
|
|
1772
|
-
this.getBlockedOrdersByZip(
|
|
1773
|
-
this.getBlockedOrdersByPhone(
|
|
1768
|
+
this.getBlockedOrdersByCpf(checkout.user?.cpf, dateFilter),
|
|
1769
|
+
this.getBlockedOrdersByEmail(checkout.user?.email, dateFilter),
|
|
1770
|
+
this.getBlockedOrdersByZip(checkout.shippingAddress?.zip, dateFilter),
|
|
1771
|
+
this.getBlockedOrdersByPhone(checkout.user?.phone, dateFilter),
|
|
1774
1772
|
]);
|
|
1775
1773
|
return {
|
|
1776
1774
|
ordersBlockedWithCpf,
|
|
@@ -1827,18 +1825,15 @@ class AntifraudCardService {
|
|
|
1827
1825
|
return ordersBlockedWithCpf.concat(blockedUniqueEmails).concat(blockedUniqueCeps).concat(blockedUniquePhone).length;
|
|
1828
1826
|
}
|
|
1829
1827
|
filterUniqueEmailBlocked(ordersBlockedWithEmail, checkout) {
|
|
1830
|
-
return ordersBlockedWithEmail.filter((e) =>
|
|
1828
|
+
return ordersBlockedWithEmail.filter((e) => e.customer.cpf !== checkout.user?.cpf);
|
|
1831
1829
|
}
|
|
1832
1830
|
filterUniqueZipBlocked(ordersBlockedWithCep, checkout) {
|
|
1833
|
-
return ordersBlockedWithCep.filter((e) =>
|
|
1831
|
+
return ordersBlockedWithCep.filter((e) => e.customer.cpf !== checkout.user?.cpf && e.customer.email !== checkout.user?.email);
|
|
1834
1832
|
}
|
|
1835
1833
|
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
|
-
});
|
|
1834
|
+
return ordersBlockedWithPhone.filter((e) => e.customer.cpf !== checkout.user?.cpf &&
|
|
1835
|
+
e.customer.email !== checkout.user?.email &&
|
|
1836
|
+
e.customer.shippingAddress?.zip?.toString() !== checkout.shippingAddress?.zip?.toString());
|
|
1842
1837
|
}
|
|
1843
1838
|
async createBlockedOrderRecord(params) {
|
|
1844
1839
|
const { checkout, card, reason, key, period } = params;
|
|
@@ -1859,12 +1854,11 @@ class AntifraudCardService {
|
|
|
1859
1854
|
return isWeekLimitValid;
|
|
1860
1855
|
}
|
|
1861
1856
|
buildValidationParams(checkout, card) {
|
|
1862
|
-
var _a, _b, _c, _d;
|
|
1863
1857
|
return {
|
|
1864
|
-
cpf:
|
|
1865
|
-
email:
|
|
1866
|
-
phone:
|
|
1867
|
-
zip:
|
|
1858
|
+
cpf: checkout.user?.cpf,
|
|
1859
|
+
email: checkout.user?.email,
|
|
1860
|
+
phone: checkout.user?.phone,
|
|
1861
|
+
zip: checkout.shippingAddress?.zip,
|
|
1868
1862
|
card,
|
|
1869
1863
|
};
|
|
1870
1864
|
}
|
|
@@ -1889,7 +1883,7 @@ class AntifraudCardService {
|
|
|
1889
1883
|
async checkOrderLimitsAndBlock(params) {
|
|
1890
1884
|
const { checkout, orderCounts, limit, period } = params;
|
|
1891
1885
|
for (const key in orderCounts) {
|
|
1892
|
-
if (orderCounts[key]
|
|
1886
|
+
if (orderCounts[key] >= limit) {
|
|
1893
1887
|
await this.createBlockedOrderRecord({
|
|
1894
1888
|
checkout,
|
|
1895
1889
|
card: null,
|
|
@@ -1903,18 +1897,20 @@ class AntifraudCardService {
|
|
|
1903
1897
|
return true;
|
|
1904
1898
|
}
|
|
1905
1899
|
async validateOrdersByRange(params, range) {
|
|
1906
|
-
const { cpf, email, phone, zip } = params;
|
|
1907
|
-
const [ordersCpf, ordersByEmail, ordersByPhone, ordersByZip] = await Promise.all([
|
|
1900
|
+
const { cpf, email, phone, zip, card } = params;
|
|
1901
|
+
const [ordersCpf, ordersByEmail, ordersByPhone, ordersByZip, ordersByCard] = await Promise.all([
|
|
1908
1902
|
this.countOrdersByField({ property: 'user', field: 'cpf', value: cpf, range }),
|
|
1909
1903
|
this.countOrdersByField({ property: 'user', field: 'email', value: email, range }),
|
|
1910
1904
|
this.countOrdersByField({ property: 'user', field: 'phone', value: phone, range }),
|
|
1911
1905
|
this.countOrdersByField({ property: 'shippingAddress', field: 'zip', value: zip, range }),
|
|
1906
|
+
this.countOrdersByField({ property: 'payment', field: 'card.id', value: card.cardId, range }),
|
|
1912
1907
|
]);
|
|
1913
1908
|
return {
|
|
1914
1909
|
cpf: ordersCpf,
|
|
1915
1910
|
email: ordersByEmail,
|
|
1916
1911
|
phone: ordersByPhone,
|
|
1917
1912
|
zip: ordersByZip,
|
|
1913
|
+
card: ordersByCard,
|
|
1918
1914
|
};
|
|
1919
1915
|
}
|
|
1920
1916
|
async countOrdersByField(params) {
|
|
@@ -1928,8 +1924,8 @@ class AntifraudCardService {
|
|
|
1928
1924
|
{ operator: Where.LTE, value: range.lastDate },
|
|
1929
1925
|
],
|
|
1930
1926
|
};
|
|
1931
|
-
const
|
|
1932
|
-
return
|
|
1927
|
+
const { count } = await this.orderRepository.find({ filters });
|
|
1928
|
+
return count;
|
|
1933
1929
|
}
|
|
1934
1930
|
getDateRange(range = 'day') {
|
|
1935
1931
|
switch (range) {
|
|
@@ -2000,10 +1996,9 @@ class GlampointsPaymentService {
|
|
|
2000
1996
|
return payment;
|
|
2001
1997
|
}
|
|
2002
1998
|
async rewardByOrder(order, user) {
|
|
2003
|
-
var _a;
|
|
2004
1999
|
try {
|
|
2005
2000
|
const points = order.lineItems.filter((item) => !item.isGift).reduce((acc, li) => acc + li.quantity, 0);
|
|
2006
|
-
const hasGlambeauty =
|
|
2001
|
+
const hasGlambeauty = order.lineItems?.some((doc) => doc.brand && doc.brand.toUpperCase() === 'GLAM BEAUTY');
|
|
2007
2002
|
const result = await axios({
|
|
2008
2003
|
method: 'POST',
|
|
2009
2004
|
url: `${this.glamCredentials.baseUrl}/integration/win/reward`,
|
|
@@ -2264,7 +2259,7 @@ class AdyenPaymentFactoryHelper {
|
|
|
2264
2259
|
checkoutId: checkout.id,
|
|
2265
2260
|
totalPrice: checkout.totalPrice,
|
|
2266
2261
|
paymentProvider: 'adyen',
|
|
2267
|
-
transaction:
|
|
2262
|
+
transaction: { ...adyenResponse, status: 'paid' },
|
|
2268
2263
|
});
|
|
2269
2264
|
return paymentRepository.create(paymentData);
|
|
2270
2265
|
}
|
|
@@ -2275,7 +2270,7 @@ class AdyenPaymentOperationsHelper {
|
|
|
2275
2270
|
return {
|
|
2276
2271
|
amount: {
|
|
2277
2272
|
currency: 'BRL',
|
|
2278
|
-
value: (
|
|
2273
|
+
value: (checkout?.totalPrice || 0) * 100,
|
|
2279
2274
|
},
|
|
2280
2275
|
paymentMethod: {
|
|
2281
2276
|
type: 'scheme',
|
|
@@ -2360,7 +2355,11 @@ class RestCacheAdapter {
|
|
|
2360
2355
|
this.logger = new DebugHelper('RestCacheAdapter');
|
|
2361
2356
|
this.client = axios.create({
|
|
2362
2357
|
baseURL: config.baseURL,
|
|
2363
|
-
headers:
|
|
2358
|
+
headers: {
|
|
2359
|
+
'Content-Type': 'application/json',
|
|
2360
|
+
...(isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` }),
|
|
2361
|
+
...(isNil(config.mobileApiKey) ? {} : { 'X-Mobile-API-Key': config.mobileApiKey }),
|
|
2362
|
+
},
|
|
2364
2363
|
});
|
|
2365
2364
|
}
|
|
2366
2365
|
async set(options) {
|
|
@@ -2616,7 +2615,10 @@ class ElasticSearchResultProcessorHelper {
|
|
|
2616
2615
|
});
|
|
2617
2616
|
}
|
|
2618
2617
|
static transformHitsToProducts(hits) {
|
|
2619
|
-
return hits.map((hit) => (
|
|
2618
|
+
return hits.map((hit) => ({
|
|
2619
|
+
...hit._source,
|
|
2620
|
+
stock: hit._source.stock.quantity,
|
|
2621
|
+
}));
|
|
2620
2622
|
}
|
|
2621
2623
|
}
|
|
2622
2624
|
|
|
@@ -2759,11 +2761,11 @@ class FirestoreDataConverterHelper {
|
|
|
2759
2761
|
return (data &&
|
|
2760
2762
|
!Array.isArray(data) &&
|
|
2761
2763
|
typeof data === 'object' &&
|
|
2762
|
-
|
|
2764
|
+
data?.constructor.name !== 'Timestamp' &&
|
|
2763
2765
|
!('seconds' in data));
|
|
2764
2766
|
}
|
|
2765
2767
|
static convertToDate(data, keyName) {
|
|
2766
|
-
if (
|
|
2768
|
+
if (data?.constructor.name === 'Timestamp')
|
|
2767
2769
|
return data.toDate();
|
|
2768
2770
|
if (data && typeof data === 'object' && 'seconds' in data)
|
|
2769
2771
|
return new Date(data.seconds * 1000);
|
|
@@ -2808,7 +2810,7 @@ class FirestoreModelConverterHelper {
|
|
|
2808
2810
|
}
|
|
2809
2811
|
buildToFirestoreConverter() {
|
|
2810
2812
|
return (data) => {
|
|
2811
|
-
const plain =
|
|
2813
|
+
const plain = data?.toPlain ? data.toPlain() : data;
|
|
2812
2814
|
return FirestoreModelConverterHelper.omitByRecursivelyInPlace(plain, (value) => value === undefined);
|
|
2813
2815
|
};
|
|
2814
2816
|
}
|
|
@@ -2818,7 +2820,7 @@ class FirestoreModelConverterHelper {
|
|
|
2818
2820
|
const data = snap.data();
|
|
2819
2821
|
const ids = { id: snap.id };
|
|
2820
2822
|
const bindedData = FirestoreDataConverterHelper.bindAllDateFromObject(data);
|
|
2821
|
-
return this.model.toInstance(
|
|
2823
|
+
return this.model.toInstance({ ...bindedData, ...ids });
|
|
2822
2824
|
}
|
|
2823
2825
|
catch (error) {
|
|
2824
2826
|
this.handleConversionError(snap.id, snap.data(), error);
|
|
@@ -2886,18 +2888,17 @@ const withHelpers = (MixinBase) => {
|
|
|
2886
2888
|
class AttributeOptionHelper {
|
|
2887
2889
|
}
|
|
2888
2890
|
AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
2889
|
-
var _a;
|
|
2890
2891
|
if (fields.includes(attributeName))
|
|
2891
2892
|
return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
|
|
2892
2893
|
const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
2893
|
-
const fieldOption =
|
|
2894
|
+
const fieldOption = is(field)?.[attributeName];
|
|
2894
2895
|
if (isNil(fieldOption))
|
|
2895
2896
|
return { columnName: attributeName.toString(), attributeName };
|
|
2896
2897
|
if (Array.isArray(fieldOption))
|
|
2897
2898
|
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
2898
|
-
return
|
|
2899
|
+
return { attributeName, columnName: attributeName.toString(), ...fieldOption };
|
|
2899
2900
|
};
|
|
2900
|
-
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!
|
|
2901
|
+
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
|
|
2901
2902
|
AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
2902
2903
|
if (fields.includes(columnName))
|
|
2903
2904
|
return { columnName, attributeName: columnName };
|
|
@@ -2905,13 +2906,17 @@ AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
|
2905
2906
|
if (!isObject(field))
|
|
2906
2907
|
return false;
|
|
2907
2908
|
const columnOption = Object.values(field).find((option) => AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName ? option : {});
|
|
2908
|
-
return AttributeOptionHelper.CheckIsColumnOption(columnOption) &&
|
|
2909
|
+
return AttributeOptionHelper.CheckIsColumnOption(columnOption) && columnOption?.columnName === columnName;
|
|
2909
2910
|
}) || {});
|
|
2910
2911
|
const attributeName = Object.keys(field).find((fieldOptionFromList) => AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) || Array.isArray(field[fieldOptionFromList]));
|
|
2911
|
-
const fieldOption = field
|
|
2912
|
+
const fieldOption = field?.[attributeName];
|
|
2912
2913
|
if (Array.isArray(fieldOption))
|
|
2913
2914
|
return { attributeName: attributeName, fields: fieldOption };
|
|
2914
|
-
return
|
|
2915
|
+
return {
|
|
2916
|
+
attributeName: attributeName || columnName,
|
|
2917
|
+
columnName,
|
|
2918
|
+
...fieldOption,
|
|
2919
|
+
};
|
|
2915
2920
|
};
|
|
2916
2921
|
|
|
2917
2922
|
var HasuraGraphQLWhere;
|
|
@@ -2949,7 +2954,7 @@ var HasuraGraphQLColumnType;
|
|
|
2949
2954
|
|
|
2950
2955
|
class FilterOptionHelper {
|
|
2951
2956
|
}
|
|
2952
|
-
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !isNil(filter
|
|
2957
|
+
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !isNil(filter?.operator);
|
|
2953
2958
|
FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
|
|
2954
2959
|
if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
|
|
2955
2960
|
return filter;
|
|
@@ -3010,25 +3015,37 @@ class BindFilterQueryHelper {
|
|
|
3010
3015
|
BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => {
|
|
3011
3016
|
const columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
|
|
3012
3017
|
if (!columnOption.bindFindFilter)
|
|
3013
|
-
return
|
|
3014
|
-
|
|
3015
|
-
|
|
3018
|
+
return {
|
|
3019
|
+
...variables,
|
|
3020
|
+
...{
|
|
3021
|
+
[columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
|
|
3022
|
+
},
|
|
3023
|
+
};
|
|
3016
3024
|
const builtFilter = columnOption.bindFindFilter(filter[fieldName]);
|
|
3017
|
-
return
|
|
3025
|
+
return {
|
|
3026
|
+
...variables,
|
|
3027
|
+
...Object.keys(builtFilter).reduce((variablesList, columnName) => ({
|
|
3028
|
+
...variablesList,
|
|
3029
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields),
|
|
3030
|
+
}), {}),
|
|
3031
|
+
};
|
|
3018
3032
|
}, {});
|
|
3019
3033
|
BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
3020
3034
|
const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
3021
3035
|
const isNestedField = !Array.isArray(options) &&
|
|
3022
3036
|
isObject(options) &&
|
|
3023
|
-
isNil(options
|
|
3024
|
-
isNil(options
|
|
3025
|
-
isNil(fieldSentenceOptions
|
|
3037
|
+
isNil(options?.operator) &&
|
|
3038
|
+
isNil(options?.value) &&
|
|
3039
|
+
isNil(fieldSentenceOptions?.to);
|
|
3026
3040
|
if (isNestedField)
|
|
3027
3041
|
return Object.keys(options).reduce((variables, key) => {
|
|
3028
|
-
const fieldOptions = AttributeOptionHelper.FindByAttribute(key,
|
|
3042
|
+
const fieldOptions = AttributeOptionHelper.FindByAttribute(key, fieldSentenceOptions?.fields || fields);
|
|
3029
3043
|
const columnName = fieldOptions.columnName;
|
|
3030
3044
|
const columnFields = fieldOptions.fields;
|
|
3031
|
-
return
|
|
3045
|
+
return {
|
|
3046
|
+
...variables,
|
|
3047
|
+
[columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), fieldSentenceOptions?.fields || columnFields || fields),
|
|
3048
|
+
};
|
|
3032
3049
|
}, {});
|
|
3033
3050
|
if (!Array.isArray(options) && !isNil(fieldSentenceOptions.fields))
|
|
3034
3051
|
return {
|
|
@@ -3037,7 +3054,10 @@ BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
|
3037
3054
|
if (!Array.isArray(options) && isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
3038
3055
|
options = Object.values(options)[0];
|
|
3039
3056
|
return Array.isArray(options)
|
|
3040
|
-
? options.reduce((whereSentence, option) => (
|
|
3057
|
+
? options.reduce((whereSentence, option) => ({
|
|
3058
|
+
...whereSentence,
|
|
3059
|
+
...BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions),
|
|
3060
|
+
}), {})
|
|
3041
3061
|
: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions);
|
|
3042
3062
|
};
|
|
3043
3063
|
BindFilterQueryHelper.BuildOperatorSentence = (options, fieldOption) => ({
|
|
@@ -3053,14 +3073,14 @@ BindFilterQueryHelper.GetHasuraOperator = (options, fieldOption) => FilterOption
|
|
|
3053
3073
|
: options.operator === Where.LIKE && options.ignoreCase
|
|
3054
3074
|
? HasuraGraphQLWhere.ILIKE
|
|
3055
3075
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3056
|
-
Object.keys(Where).find((operator) => Where[operator] ===
|
|
3076
|
+
Object.keys(Where).find((operator) => Where[operator] === options?.operator))]
|
|
3057
3077
|
: HasuraGraphQLWhere.EQUALS;
|
|
3058
3078
|
BindFilterQueryHelper.GetHasuraJsonbOperator = (options) => options.operator === Where.IN
|
|
3059
3079
|
? HasuraGraphQLWhere.JSON_CONTAINS
|
|
3060
3080
|
: options.operator === Where.LIKE
|
|
3061
3081
|
? HasuraGraphQLWhere.JSON_HAS_KEYS_ANY
|
|
3062
3082
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3063
|
-
Object.keys(Where).find((operator) => Where[operator] ===
|
|
3083
|
+
Object.keys(Where).find((operator) => Where[operator] === options?.operator))];
|
|
3064
3084
|
|
|
3065
3085
|
class CacheKeyGeneratorHelper {
|
|
3066
3086
|
static generateCacheKeyFromIdentifiers(modelOrModelName, identifiers) {
|
|
@@ -3075,7 +3095,8 @@ class GraphQLFieldHelper {
|
|
|
3075
3095
|
}
|
|
3076
3096
|
GraphQLFieldHelper.CheckIsGraphQLParams = (params) => !isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
|
|
3077
3097
|
GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
3078
|
-
return fields
|
|
3098
|
+
return fields
|
|
3099
|
+
?.map((field) => {
|
|
3079
3100
|
if (isString(field))
|
|
3080
3101
|
return field.toString();
|
|
3081
3102
|
if (field === 'affected_rows')
|
|
@@ -3090,41 +3111,55 @@ GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
|
3090
3111
|
if (isNestedField)
|
|
3091
3112
|
return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
|
|
3092
3113
|
return fieldValue.columnName;
|
|
3093
|
-
})
|
|
3114
|
+
})
|
|
3115
|
+
.filter((field) => !!field);
|
|
3094
3116
|
};
|
|
3095
3117
|
GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
|
|
3096
3118
|
const { attributeName, fields: attributeFields, from, } = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields);
|
|
3097
3119
|
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
3098
3120
|
if (Array.isArray(data[columnName]))
|
|
3099
|
-
return
|
|
3121
|
+
return {
|
|
3122
|
+
...result,
|
|
3123
|
+
[attributeName]: from
|
|
3100
3124
|
? from(data[columnName], data)
|
|
3101
|
-
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields))
|
|
3125
|
+
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)),
|
|
3126
|
+
};
|
|
3102
3127
|
if (isObject(data[columnName]))
|
|
3103
|
-
return
|
|
3128
|
+
return {
|
|
3129
|
+
...result,
|
|
3130
|
+
[attributeName]: from
|
|
3104
3131
|
? from(data[columnName])
|
|
3105
|
-
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields)
|
|
3132
|
+
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields),
|
|
3133
|
+
};
|
|
3106
3134
|
}
|
|
3107
3135
|
if (from)
|
|
3108
|
-
return
|
|
3109
|
-
return
|
|
3136
|
+
return { ...result, [attributeName]: from(data[columnName], data) };
|
|
3137
|
+
return {
|
|
3138
|
+
...result,
|
|
3139
|
+
[attributeName]: isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName],
|
|
3140
|
+
};
|
|
3110
3141
|
}, {});
|
|
3111
3142
|
GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
3112
|
-
|
|
3113
|
-
const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
3143
|
+
const data = instance.toPlain?.() || instance;
|
|
3114
3144
|
return Object.keys(data).reduce((result, attributeName) => {
|
|
3115
3145
|
const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
|
|
3116
3146
|
if (bindPersistData)
|
|
3117
|
-
return
|
|
3147
|
+
return {
|
|
3148
|
+
...result,
|
|
3149
|
+
...bindPersistData(data[attributeName], instance),
|
|
3150
|
+
};
|
|
3118
3151
|
if (isNil(columnName))
|
|
3119
3152
|
return result;
|
|
3120
3153
|
if (!!foreignKeyColumn &&
|
|
3121
3154
|
!isEmpty(foreignKeyColumn) &&
|
|
3122
|
-
!Object.keys(foreignKeyColumn).filter((key) =>
|
|
3155
|
+
!Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
|
|
3123
3156
|
return Object.keys(foreignKeyColumn).reduce((object, current) => {
|
|
3124
|
-
var _a;
|
|
3125
3157
|
const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
|
|
3126
|
-
return
|
|
3127
|
-
|
|
3158
|
+
return {
|
|
3159
|
+
...object,
|
|
3160
|
+
[foreignColumnName]: data[attributeName]?.[current],
|
|
3161
|
+
};
|
|
3162
|
+
}, { ...result });
|
|
3128
3163
|
if (update &&
|
|
3129
3164
|
isObject(data[attributeName]) &&
|
|
3130
3165
|
!isNil(attributeFields) &&
|
|
@@ -3136,19 +3171,25 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
3136
3171
|
const converted = !isNil(columnName) && to
|
|
3137
3172
|
? to(instance[attributeName], instance)
|
|
3138
3173
|
: data[attributeName];
|
|
3139
|
-
return
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
:
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3174
|
+
return {
|
|
3175
|
+
...result,
|
|
3176
|
+
...(converted !== undefined
|
|
3177
|
+
? {
|
|
3178
|
+
[columnName]: {
|
|
3179
|
+
data: instance[attributeName] instanceof BaseModel
|
|
3180
|
+
? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
|
|
3181
|
+
: converted,
|
|
3182
|
+
},
|
|
3183
|
+
}
|
|
3184
|
+
: {}),
|
|
3185
|
+
};
|
|
3148
3186
|
}
|
|
3149
3187
|
if (to)
|
|
3150
|
-
return
|
|
3151
|
-
|
|
3188
|
+
return {
|
|
3189
|
+
...result,
|
|
3190
|
+
[columnName]: to(instance[attributeName], instance),
|
|
3191
|
+
};
|
|
3192
|
+
return { ...result, [columnName]: data[attributeName] };
|
|
3152
3193
|
}, {});
|
|
3153
3194
|
};
|
|
3154
3195
|
GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
|
|
@@ -3206,13 +3247,17 @@ class MD5GeneratorHelper {
|
|
|
3206
3247
|
|
|
3207
3248
|
class HasuraAuthHelper {
|
|
3208
3249
|
static buildHeaders(authOptions) {
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
? {}
|
|
3212
|
-
: {
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3250
|
+
return {
|
|
3251
|
+
'Content-Type': 'application/json',
|
|
3252
|
+
...(isNil(authOptions?.authToken) ? {} : { Authorization: authOptions?.authToken }),
|
|
3253
|
+
...(isNil(authOptions?.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': authOptions?.adminSecret }),
|
|
3254
|
+
...(isNil(authOptions?.authRole)
|
|
3255
|
+
? {}
|
|
3256
|
+
: {
|
|
3257
|
+
'X-Hasura-Role': authOptions.authRole.role,
|
|
3258
|
+
'X-Hasura-User-Id': authOptions?.authRole?.userId,
|
|
3259
|
+
}),
|
|
3260
|
+
};
|
|
3216
3261
|
}
|
|
3217
3262
|
}
|
|
3218
3263
|
|
|
@@ -3302,17 +3347,21 @@ class HasuraGraphQLOperationsHelper {
|
|
|
3302
3347
|
return this.executeFetch({ query: resultQuery, operationParams });
|
|
3303
3348
|
}
|
|
3304
3349
|
static async executeQuery(params) {
|
|
3305
|
-
var _a, _b, _c, _d;
|
|
3306
3350
|
const { operation, fields, variables, operationParams, buildHasuraQueryFields } = params;
|
|
3307
3351
|
const builded = buildHasuraQueryFields({ operation, fields, variables });
|
|
3308
|
-
const intercepted = (await
|
|
3352
|
+
const intercepted = (await operationParams.interceptors?.request?.(builded)) || builded;
|
|
3309
3353
|
const resultQuery = HasuraQueryBuilderHelper.buildQuery(intercepted);
|
|
3310
3354
|
const result = await this.executeFetch({ query: resultQuery, operationParams });
|
|
3311
|
-
return (await
|
|
3355
|
+
return (await operationParams.interceptors?.response?.(result, intercepted)) || result;
|
|
3312
3356
|
}
|
|
3313
3357
|
static async executeFetch(params) {
|
|
3314
3358
|
const { query, operationParams } = params;
|
|
3315
|
-
return HasuraRequestHelper.fetch(
|
|
3359
|
+
return HasuraRequestHelper.fetch({
|
|
3360
|
+
...query,
|
|
3361
|
+
endpoint: operationParams.endpoint,
|
|
3362
|
+
headers: HasuraAuthHelper.buildHeaders(operationParams.authOptions),
|
|
3363
|
+
logger: operationParams.logger,
|
|
3364
|
+
});
|
|
3316
3365
|
}
|
|
3317
3366
|
}
|
|
3318
3367
|
|
|
@@ -3326,12 +3375,10 @@ class HasuraColumnHelper {
|
|
|
3326
3375
|
const columnOptions = Object.values(field).shift();
|
|
3327
3376
|
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
3328
3377
|
columnOptions.foreignKeyColumn && [
|
|
3329
|
-
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) =>
|
|
3378
|
+
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => AttributeOptionHelper.FindByAttribute(foreignKeyName, fields)?.columnName),
|
|
3330
3379
|
{
|
|
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
|
-
}),
|
|
3380
|
+
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
|
|
3381
|
+
?.columnName || foreignKeyField),
|
|
3335
3382
|
},
|
|
3336
3383
|
]);
|
|
3337
3384
|
})
|
|
@@ -3356,7 +3403,7 @@ class HasuraCreateOperationsHelper {
|
|
|
3356
3403
|
const { model } = params;
|
|
3357
3404
|
params.repository.logger = DebugHelper.from(params.repository, 'create');
|
|
3358
3405
|
const instance = model.toInstance(data);
|
|
3359
|
-
const newData = await this.executeSave(
|
|
3406
|
+
const newData = await this.executeSave({ ...params, data: instance });
|
|
3360
3407
|
return model.toInstance(newData);
|
|
3361
3408
|
}
|
|
3362
3409
|
static async executeSave(params) {
|
|
@@ -3370,14 +3417,14 @@ class HasuraCreateOperationsHelper {
|
|
|
3370
3417
|
},
|
|
3371
3418
|
});
|
|
3372
3419
|
const convertedResult = repository.convertDataFromHasura(result[insertGraphQLOperation]);
|
|
3373
|
-
return
|
|
3420
|
+
return { ...data.toPlain(), ...convertedResult.toPlain() };
|
|
3374
3421
|
}
|
|
3375
3422
|
}
|
|
3376
3423
|
|
|
3377
3424
|
class HasuraCacheOperationsHelper {
|
|
3378
3425
|
static async removeCacheData(cache, params) {
|
|
3379
3426
|
const { model, identifiers, logger } = params;
|
|
3380
|
-
if (!
|
|
3427
|
+
if (!cache?.cacheAdapter)
|
|
3381
3428
|
return;
|
|
3382
3429
|
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3383
3430
|
await cache.cacheAdapter.remove(cacheKey);
|
|
@@ -3397,13 +3444,16 @@ class HasuraDeleteVariablesHelper {
|
|
|
3397
3444
|
if (isNil(instance.identifier[identifierBinded]))
|
|
3398
3445
|
return ids;
|
|
3399
3446
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
|
|
3400
|
-
const value =
|
|
3447
|
+
const value = columnOption?.to(identifiers[identifier], instance) ||
|
|
3401
3448
|
identifiers[identifier];
|
|
3402
|
-
return
|
|
3449
|
+
return {
|
|
3450
|
+
...ids,
|
|
3451
|
+
[columnOption.columnName]: {
|
|
3403
3452
|
type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3404
3453
|
value,
|
|
3405
3454
|
required: true,
|
|
3406
|
-
}
|
|
3455
|
+
},
|
|
3456
|
+
};
|
|
3407
3457
|
}, {});
|
|
3408
3458
|
}
|
|
3409
3459
|
}
|
|
@@ -3441,16 +3491,15 @@ class HasuraFindBindingHelper {
|
|
|
3441
3491
|
], []);
|
|
3442
3492
|
}
|
|
3443
3493
|
static bindAggregateAttributes(aggregates, fields) {
|
|
3444
|
-
var _a, _b;
|
|
3445
3494
|
return [
|
|
3446
|
-
...(
|
|
3495
|
+
...(aggregates?.minimal?.length
|
|
3447
3496
|
? [
|
|
3448
3497
|
{
|
|
3449
3498
|
min: this.bindAttributesToColumns(aggregates.minimal, fields),
|
|
3450
3499
|
},
|
|
3451
3500
|
]
|
|
3452
3501
|
: []),
|
|
3453
|
-
...(
|
|
3502
|
+
...(aggregates?.maximum?.length
|
|
3454
3503
|
? [
|
|
3455
3504
|
{
|
|
3456
3505
|
max: this.bindAttributesToColumns(aggregates.maximum, fields),
|
|
@@ -3477,7 +3526,7 @@ class HasuraFindBindingHelper {
|
|
|
3477
3526
|
});
|
|
3478
3527
|
if (typeof fieldOption === 'object' && fieldOption !== null) {
|
|
3479
3528
|
const columnOption = fieldOption[attributeName];
|
|
3480
|
-
return
|
|
3529
|
+
return columnOption?.columnName || attributeName;
|
|
3481
3530
|
}
|
|
3482
3531
|
return attributeName;
|
|
3483
3532
|
}
|
|
@@ -3490,27 +3539,27 @@ class HasuraFindCacheHelper {
|
|
|
3490
3539
|
}
|
|
3491
3540
|
static async getCachedResult(params) {
|
|
3492
3541
|
const { cache, model, findParams, cacheOptions, logger } = params;
|
|
3493
|
-
if (!
|
|
3542
|
+
if (!cache?.cacheAdapter || !cacheOptions?.enabled)
|
|
3494
3543
|
return null;
|
|
3495
3544
|
const cacheKey = this.generateCacheKey(model, findParams);
|
|
3496
3545
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
3497
3546
|
if (cachedData) {
|
|
3498
|
-
logger
|
|
3547
|
+
logger?.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
3499
3548
|
return deserialize(cachedData);
|
|
3500
3549
|
}
|
|
3501
3550
|
return null;
|
|
3502
3551
|
}
|
|
3503
3552
|
static async setCachedResult(params) {
|
|
3504
3553
|
const { cache, model, findParams, cacheOptions, result, logger } = params;
|
|
3505
|
-
if (!
|
|
3554
|
+
if (!cache?.cacheAdapter || !cacheOptions?.enabled)
|
|
3506
3555
|
return;
|
|
3507
3556
|
const cacheKey = this.generateCacheKey(model, findParams);
|
|
3508
3557
|
await cache.cacheAdapter.set({
|
|
3509
3558
|
key: cacheKey,
|
|
3510
3559
|
data: serialize(result),
|
|
3511
|
-
expirationInSeconds:
|
|
3560
|
+
expirationInSeconds: cacheOptions?.ttl || cache.ttlDefault,
|
|
3512
3561
|
});
|
|
3513
|
-
logger
|
|
3562
|
+
logger?.log(`Dados salvos no cache: ${cacheKey}`);
|
|
3514
3563
|
}
|
|
3515
3564
|
}
|
|
3516
3565
|
|
|
@@ -3518,27 +3567,40 @@ class HasuraFindResultHelper {
|
|
|
3518
3567
|
static processResult(params) {
|
|
3519
3568
|
const { result, tableName, enableCount, findOptions, tableFiltersNamed, fields, convertDataFromHasura, lastDistinct, } = params;
|
|
3520
3569
|
const data = result[tableName].map((row) => convertDataFromHasura(row));
|
|
3521
|
-
const findResult =
|
|
3570
|
+
const findResult = {
|
|
3571
|
+
data,
|
|
3572
|
+
count: enableCount ? result[`${tableName}_aggregate`].aggregate.count : Infinity,
|
|
3573
|
+
...this.processMinimalAggregates({ result, tableName, findOptions, fields }),
|
|
3574
|
+
...this.processMaximumAggregates({ result, tableName, findOptions, fields }),
|
|
3575
|
+
...this.processDistinctResults({ result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct }),
|
|
3576
|
+
};
|
|
3522
3577
|
return findResult;
|
|
3523
3578
|
}
|
|
3524
3579
|
static bindAggregateAttributes(params) {
|
|
3525
|
-
var _a, _b;
|
|
3526
3580
|
const { aggregates, fields } = params;
|
|
3527
3581
|
const convertFieldName = (fieldName) => {
|
|
3528
|
-
var _a, _b;
|
|
3529
3582
|
const finalFieldName = fieldName.toString().split('.').pop();
|
|
3530
|
-
const fieldOption =
|
|
3531
|
-
|
|
3583
|
+
const fieldOption = fields.find((fieldOption) => {
|
|
3584
|
+
if (typeof fieldOption === 'string')
|
|
3585
|
+
return fieldOption === finalFieldName;
|
|
3586
|
+
const key = Object.keys(fieldOption)[0];
|
|
3587
|
+
return key === finalFieldName;
|
|
3588
|
+
});
|
|
3589
|
+
if (fieldOption && typeof fieldOption !== 'string') {
|
|
3590
|
+
const fieldValue = Object.values(fieldOption)[0];
|
|
3591
|
+
return fieldValue?.columnName || finalFieldName;
|
|
3592
|
+
}
|
|
3593
|
+
return finalFieldName;
|
|
3532
3594
|
};
|
|
3533
3595
|
return [
|
|
3534
|
-
...(
|
|
3596
|
+
...(aggregates?.minimal?.length
|
|
3535
3597
|
? [
|
|
3536
3598
|
{
|
|
3537
3599
|
min: aggregates.minimal.map(convertFieldName),
|
|
3538
3600
|
},
|
|
3539
3601
|
]
|
|
3540
3602
|
: []),
|
|
3541
|
-
...(
|
|
3603
|
+
...(aggregates?.maximum?.length
|
|
3542
3604
|
? [
|
|
3543
3605
|
{
|
|
3544
3606
|
max: aggregates.maximum.map(convertFieldName),
|
|
@@ -3548,48 +3610,52 @@ class HasuraFindResultHelper {
|
|
|
3548
3610
|
];
|
|
3549
3611
|
}
|
|
3550
3612
|
static processMinimalAggregates(params) {
|
|
3551
|
-
var _a;
|
|
3552
3613
|
const { result, tableName, findOptions, fields } = params;
|
|
3553
|
-
return
|
|
3614
|
+
return findOptions?.minimal?.length
|
|
3554
3615
|
? {
|
|
3555
3616
|
minimal: findOptions.minimal.reduce((minimals, current) => {
|
|
3556
|
-
|
|
3557
|
-
return
|
|
3617
|
+
const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
|
|
3618
|
+
return {
|
|
3619
|
+
...minimals,
|
|
3620
|
+
...set(minimals, current, result[`${tableName}_aggregate`].aggregate.min[columnName]),
|
|
3621
|
+
};
|
|
3558
3622
|
}, {}),
|
|
3559
3623
|
}
|
|
3560
3624
|
: {};
|
|
3561
3625
|
}
|
|
3562
3626
|
static processMaximumAggregates(params) {
|
|
3563
|
-
var _a;
|
|
3564
3627
|
const { result, tableName, findOptions, fields } = params;
|
|
3565
|
-
return
|
|
3628
|
+
return findOptions?.maximum?.length
|
|
3566
3629
|
? {
|
|
3567
3630
|
maximum: findOptions.maximum.reduce((maximums, current) => {
|
|
3568
|
-
|
|
3569
|
-
return
|
|
3631
|
+
const columnName = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), fields)?.columnName || current;
|
|
3632
|
+
return {
|
|
3633
|
+
...maximums,
|
|
3634
|
+
...set(maximums, current, result[`${tableName}_aggregate`].aggregate.max[columnName]),
|
|
3635
|
+
};
|
|
3570
3636
|
}, {}),
|
|
3571
3637
|
}
|
|
3572
3638
|
: {};
|
|
3573
3639
|
}
|
|
3574
3640
|
static processDistinctResults(params) {
|
|
3575
|
-
var _a, _b;
|
|
3576
3641
|
const { result, tableName, findOptions, tableFiltersNamed, fields, lastDistinct } = params;
|
|
3577
|
-
return
|
|
3642
|
+
return findOptions?.distinct?.length
|
|
3578
3643
|
? {
|
|
3579
|
-
distinct:
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3644
|
+
distinct: lastDistinct[tableFiltersNamed] ??
|
|
3645
|
+
(lastDistinct[tableFiltersNamed] = findOptions?.distinct.reduce((distinct, current) => {
|
|
3646
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === current) ??
|
|
3647
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
|
|
3648
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || current;
|
|
3649
|
+
return {
|
|
3650
|
+
...distinct,
|
|
3651
|
+
[current.toString()]: result[`${tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]),
|
|
3652
|
+
};
|
|
3653
|
+
}, {})),
|
|
3585
3654
|
}
|
|
3586
3655
|
: {};
|
|
3587
3656
|
}
|
|
3588
3657
|
static bindAttributesToColumns(attributes, fields) {
|
|
3589
|
-
return attributes.map((attr) =>
|
|
3590
|
-
var _a;
|
|
3591
|
-
return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
|
|
3592
|
-
});
|
|
3658
|
+
return attributes.map((attr) => AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)?.columnName || attr);
|
|
3593
3659
|
}
|
|
3594
3660
|
}
|
|
3595
3661
|
|
|
@@ -3619,16 +3685,19 @@ class HasuraFindVariablesHelper {
|
|
|
3619
3685
|
};
|
|
3620
3686
|
}
|
|
3621
3687
|
static buildDistinctVariables(params) {
|
|
3622
|
-
var _a, _b;
|
|
3623
3688
|
const { distinct, tableName, fields, filtersVariables } = params;
|
|
3624
|
-
const distinctOption =
|
|
3625
|
-
|
|
3626
|
-
|
|
3689
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
|
|
3690
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
3691
|
+
const fieldName = Object.values(distinctOption).shift()?.columnName || distinct;
|
|
3692
|
+
return {
|
|
3693
|
+
...filtersVariables,
|
|
3694
|
+
[`${tableName}_${fieldName}_distinct`]: {
|
|
3627
3695
|
type: `${tableName}_select_column!`,
|
|
3628
3696
|
list: true,
|
|
3629
3697
|
value: fieldName,
|
|
3630
3698
|
name: 'distinct_on',
|
|
3631
|
-
}
|
|
3699
|
+
},
|
|
3700
|
+
};
|
|
3632
3701
|
}
|
|
3633
3702
|
static bindOrderByAttributes(orderBy, fields) {
|
|
3634
3703
|
return Object.keys(orderBy).reduce((acc, current) => [
|
|
@@ -3648,11 +3717,17 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3648
3717
|
const { tableName, fields, params, lastDistinct } = queryParams;
|
|
3649
3718
|
const { filters, limits, orderBy, options: findOptions } = params || {};
|
|
3650
3719
|
const filtersVariables = HasuraFindVariablesHelper.buildFiltersVariables({ filters, tableName, fields });
|
|
3651
|
-
const countVariables =
|
|
3652
|
-
|
|
3720
|
+
const countVariables = {
|
|
3721
|
+
...HasuraFindVariablesHelper.buildOrderByVariables({ orderBy, tableName, fields }),
|
|
3722
|
+
...filtersVariables,
|
|
3723
|
+
};
|
|
3724
|
+
const mainVariables = {
|
|
3725
|
+
...(isNil(limits) ? {} : limits),
|
|
3726
|
+
...countVariables,
|
|
3727
|
+
};
|
|
3653
3728
|
const queries = [
|
|
3654
3729
|
this.buildMainQuery({ tableName, fields, params, mainVariables }),
|
|
3655
|
-
...this.buildAggregateQuery({ tableName, findOptions, countVariables }),
|
|
3730
|
+
...this.buildAggregateQuery({ tableName, findOptions, countVariables, fields }),
|
|
3656
3731
|
...this.buildDistinctQueries({ tableName, fields, findOptions, filtersVariables, lastDistinct }),
|
|
3657
3732
|
];
|
|
3658
3733
|
return queries.filter(Boolean);
|
|
@@ -3661,26 +3736,23 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3661
3736
|
const { tableName, fields, params: findParams, mainVariables } = params;
|
|
3662
3737
|
return {
|
|
3663
3738
|
operation: tableName,
|
|
3664
|
-
fields:
|
|
3739
|
+
fields: findParams?.fields
|
|
3665
3740
|
? findParams.fields
|
|
3666
|
-
.map((fieldName) =>
|
|
3667
|
-
|
|
3668
|
-
return (_a = fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
|
|
3669
|
-
})
|
|
3741
|
+
.map((fieldName) => fields.find((fieldOption) => fieldOption === fieldName) ??
|
|
3742
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
|
|
3670
3743
|
.filter(Boolean)
|
|
3671
3744
|
: fields,
|
|
3672
3745
|
variables: mainVariables,
|
|
3673
3746
|
};
|
|
3674
3747
|
}
|
|
3675
3748
|
static buildAggregateQuery(params) {
|
|
3676
|
-
var _a;
|
|
3677
3749
|
const { tableName, findOptions, countVariables } = params;
|
|
3678
|
-
const enableCount =
|
|
3750
|
+
const enableCount = findOptions?.enableCount ?? true;
|
|
3679
3751
|
const aggregateFields = [
|
|
3680
3752
|
...(enableCount ? ['count'] : []),
|
|
3681
3753
|
...HasuraFindResultHelper.bindAggregateAttributes({
|
|
3682
|
-
aggregates: { minimal: findOptions
|
|
3683
|
-
fields:
|
|
3754
|
+
aggregates: { minimal: findOptions?.minimal, maximum: findOptions?.maximum },
|
|
3755
|
+
fields: params.fields,
|
|
3684
3756
|
}),
|
|
3685
3757
|
];
|
|
3686
3758
|
return aggregateFields.length > 0
|
|
@@ -3698,15 +3770,14 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3698
3770
|
: [];
|
|
3699
3771
|
}
|
|
3700
3772
|
static buildDistinctQueries(params) {
|
|
3701
|
-
var _a;
|
|
3702
3773
|
const { tableName, fields, findOptions, filtersVariables, lastDistinct } = params;
|
|
3703
3774
|
const tableFiltersNamed = `${tableName}:${JSON.stringify(filtersVariables)}`;
|
|
3704
|
-
if (!
|
|
3775
|
+
if (!findOptions?.distinct?.length || lastDistinct[tableFiltersNamed]) {
|
|
3705
3776
|
return [];
|
|
3706
3777
|
}
|
|
3707
3778
|
return findOptions.distinct.map((distinct) => {
|
|
3708
|
-
|
|
3709
|
-
|
|
3779
|
+
const distinctOption = fields.find((fieldOption) => fieldOption === distinct) ??
|
|
3780
|
+
fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
3710
3781
|
return {
|
|
3711
3782
|
operation: {
|
|
3712
3783
|
name: tableName,
|
|
@@ -3726,18 +3797,16 @@ class HasuraFindQueryBuilderHelper {
|
|
|
3726
3797
|
|
|
3727
3798
|
class HasuraFindOperationsHelper {
|
|
3728
3799
|
static async executeFindOperation(operationParams) {
|
|
3729
|
-
var _a;
|
|
3730
3800
|
const { params, cacheOptions, model, tableName, fields, cache, query, convertDataFromHasura, lastDistinct } = operationParams;
|
|
3731
3801
|
const logger = DebugHelper.from(operationParams, 'find');
|
|
3732
3802
|
const { filters, options: findOptions } = params || {};
|
|
3733
3803
|
const tableFiltersNamed = `${tableName}:${JSON.stringify(filters)}`;
|
|
3734
|
-
const enableCount =
|
|
3735
|
-
// Verifica cache primeiro
|
|
3804
|
+
const enableCount = findOptions?.enableCount ?? true;
|
|
3736
3805
|
const cachedResult = await HasuraFindCacheHelper.getCachedResult({
|
|
3737
3806
|
cache,
|
|
3738
3807
|
model,
|
|
3739
3808
|
findParams: params,
|
|
3740
|
-
cacheOptions: cacheOptions
|
|
3809
|
+
cacheOptions: cacheOptions?.cache,
|
|
3741
3810
|
logger,
|
|
3742
3811
|
});
|
|
3743
3812
|
if (cachedResult) {
|
|
@@ -3752,7 +3821,6 @@ class HasuraFindOperationsHelper {
|
|
|
3752
3821
|
lastDistinct,
|
|
3753
3822
|
});
|
|
3754
3823
|
}
|
|
3755
|
-
// Constrói e executa queries
|
|
3756
3824
|
const queries = HasuraFindQueryBuilderHelper.buildCompleteQuery({
|
|
3757
3825
|
tableName,
|
|
3758
3826
|
fields,
|
|
@@ -3760,16 +3828,14 @@ class HasuraFindOperationsHelper {
|
|
|
3760
3828
|
lastDistinct,
|
|
3761
3829
|
});
|
|
3762
3830
|
const result = await query(queries);
|
|
3763
|
-
// Salva no cache se habilitado
|
|
3764
3831
|
await HasuraFindCacheHelper.setCachedResult({
|
|
3765
3832
|
cache,
|
|
3766
3833
|
model,
|
|
3767
3834
|
findParams: params,
|
|
3768
|
-
cacheOptions: cacheOptions
|
|
3835
|
+
cacheOptions: cacheOptions?.cache,
|
|
3769
3836
|
result,
|
|
3770
3837
|
logger,
|
|
3771
3838
|
});
|
|
3772
|
-
// Processa e retorna resultado
|
|
3773
3839
|
return HasuraFindResultHelper.processResult({
|
|
3774
3840
|
result,
|
|
3775
3841
|
tableName,
|
|
@@ -3788,9 +3854,8 @@ class HasuraGetCacheHelper {
|
|
|
3788
3854
|
return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3789
3855
|
}
|
|
3790
3856
|
static async getCachedData(cache, params) {
|
|
3791
|
-
var _a;
|
|
3792
3857
|
const { identifiers, options, model, logger } = params;
|
|
3793
|
-
if (!
|
|
3858
|
+
if (!cache?.cacheAdapter || !options?.cache?.enabled)
|
|
3794
3859
|
return null;
|
|
3795
3860
|
const cacheKey = this.generateCacheKey(model, identifiers);
|
|
3796
3861
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -3800,15 +3865,14 @@ class HasuraGetCacheHelper {
|
|
|
3800
3865
|
return model.toInstance(deserialize(cachedData));
|
|
3801
3866
|
}
|
|
3802
3867
|
static async saveCacheData(cache, params) {
|
|
3803
|
-
var _a, _b;
|
|
3804
3868
|
const { identifiers, options, data, logger } = params;
|
|
3805
|
-
if (!
|
|
3869
|
+
if (!cache?.cacheAdapter || !options?.cache?.enabled)
|
|
3806
3870
|
return;
|
|
3807
3871
|
const cacheKey = this.generateCacheKey(params.data.constructor, identifiers);
|
|
3808
3872
|
await cache.cacheAdapter.set({
|
|
3809
3873
|
key: cacheKey,
|
|
3810
3874
|
data: serialize(data),
|
|
3811
|
-
expirationInSeconds:
|
|
3875
|
+
expirationInSeconds: options?.cache?.ttl || cache.ttlDefault,
|
|
3812
3876
|
});
|
|
3813
3877
|
logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
3814
3878
|
}
|
|
@@ -3819,18 +3883,20 @@ class HasuraGetVariablesHelper {
|
|
|
3819
3883
|
const { model, fields, repository } = params;
|
|
3820
3884
|
const instance = model.toInstance(identifiers);
|
|
3821
3885
|
return model.identifiersFields.reduce((ids, identifier) => {
|
|
3822
|
-
var _a;
|
|
3823
3886
|
const identifierBinded = identifier;
|
|
3824
3887
|
if (isNil(instance[identifierBinded]))
|
|
3825
3888
|
return ids;
|
|
3826
3889
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
|
|
3827
|
-
const value =
|
|
3890
|
+
const value = columnOption?.to?.(identifiers[identifier], instance) ||
|
|
3828
3891
|
identifiers[identifier];
|
|
3829
|
-
return
|
|
3892
|
+
return {
|
|
3893
|
+
...ids,
|
|
3894
|
+
[columnOption.columnName]: {
|
|
3830
3895
|
type: repository.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3831
3896
|
value,
|
|
3832
3897
|
required: true,
|
|
3833
|
-
}
|
|
3898
|
+
},
|
|
3899
|
+
};
|
|
3834
3900
|
}, {});
|
|
3835
3901
|
}
|
|
3836
3902
|
}
|
|
@@ -3887,7 +3953,7 @@ class HasuraUpdateDataHelper {
|
|
|
3887
3953
|
static getValueByAction(options) {
|
|
3888
3954
|
if (options instanceof BaseModel)
|
|
3889
3955
|
return options.toPlain();
|
|
3890
|
-
if (isNil(options
|
|
3956
|
+
if (isNil(options?.action))
|
|
3891
3957
|
return options;
|
|
3892
3958
|
if ([UpdateOptionActions.REMOVE_FIELD.toString(), UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
3893
3959
|
return null;
|
|
@@ -3896,9 +3962,12 @@ class HasuraUpdateDataHelper {
|
|
|
3896
3962
|
static paramsToPlain(params, model) {
|
|
3897
3963
|
if (model.isModel(params))
|
|
3898
3964
|
return params.toPlain();
|
|
3899
|
-
return Object.keys(params).reduce((data, currentKey) => (
|
|
3900
|
-
|
|
3901
|
-
|
|
3965
|
+
return Object.keys(params).reduce((data, currentKey) => ({
|
|
3966
|
+
...data,
|
|
3967
|
+
...(params[currentKey] !== undefined && {
|
|
3968
|
+
[currentKey]: this.getValueByAction(is(params[currentKey])),
|
|
3969
|
+
}),
|
|
3970
|
+
}), {});
|
|
3902
3971
|
}
|
|
3903
3972
|
static getIdentifiersFromData(data, model) {
|
|
3904
3973
|
const instance = model.toInstance(data);
|
|
@@ -3917,13 +3986,15 @@ class HasuraUpdateVariablesHelper {
|
|
|
3917
3986
|
static getUpdateModelKeys(data, model, fields) {
|
|
3918
3987
|
const instance = model.toInstance(data);
|
|
3919
3988
|
return model.identifiersFields.reduce((ids, identifier) => {
|
|
3920
|
-
var _a;
|
|
3921
3989
|
const identifierBinded = identifier;
|
|
3922
3990
|
if (isNil(instance.identifier[identifierBinded]))
|
|
3923
3991
|
return ids;
|
|
3924
3992
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifierBinded, fields);
|
|
3925
|
-
const value =
|
|
3926
|
-
return
|
|
3993
|
+
const value = columnOption?.to?.(data[identifierBinded], instance) || data[columnOption.attributeName];
|
|
3994
|
+
return {
|
|
3995
|
+
...ids,
|
|
3996
|
+
[columnOption.columnName]: value,
|
|
3997
|
+
};
|
|
3927
3998
|
}, {});
|
|
3928
3999
|
}
|
|
3929
4000
|
static getIdentifierFields(model, fields) {
|
|
@@ -3951,9 +4022,7 @@ class HasuraUpdateOperationsHelper {
|
|
|
3951
4022
|
const { data, updateGraphQLOperation, updateGraphQLObjectType, updateGraphQLPKType, model, fields, cache, mutation, convertDataToHasura, } = params;
|
|
3952
4023
|
const logger = DebugHelper.from(params, 'update');
|
|
3953
4024
|
const plainData = HasuraUpdateDataHelper.paramsToPlain(data, model);
|
|
3954
|
-
// Gerencia cache se disponível
|
|
3955
4025
|
await this.handleCacheRemoval({ plainData, model, cache, logger });
|
|
3956
|
-
// Executa mutation
|
|
3957
4026
|
const identifierFields = HasuraUpdateVariablesHelper.getIdentifierFields(model, fields);
|
|
3958
4027
|
const mutationVariables = HasuraUpdateVariablesHelper.buildMutationVariables({
|
|
3959
4028
|
plainData,
|
|
@@ -3968,13 +4037,13 @@ class HasuraUpdateOperationsHelper {
|
|
|
3968
4037
|
}
|
|
3969
4038
|
static async handleCacheRemoval(params) {
|
|
3970
4039
|
const { plainData, model, cache, logger } = params;
|
|
3971
|
-
if (!
|
|
4040
|
+
if (!cache?.cacheAdapter)
|
|
3972
4041
|
return;
|
|
3973
4042
|
const identifiers = HasuraUpdateDataHelper.getIdentifiersFromData(plainData, model);
|
|
3974
4043
|
if (Object.keys(identifiers).length > 0) {
|
|
3975
4044
|
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(model, identifiers);
|
|
3976
4045
|
await cache.cacheAdapter.remove(cacheKey);
|
|
3977
|
-
logger
|
|
4046
|
+
logger?.log(`Cache removido: ${cacheKey}`);
|
|
3978
4047
|
}
|
|
3979
4048
|
}
|
|
3980
4049
|
}
|
|
@@ -3996,9 +4065,8 @@ class FirestoreCacheKeyGeneratorHelper {
|
|
|
3996
4065
|
|
|
3997
4066
|
class FirestoreCacheHelper {
|
|
3998
4067
|
static async getCachedData(cache, params) {
|
|
3999
|
-
var _a;
|
|
4000
4068
|
const { model, identifiers, options, logger, req } = params;
|
|
4001
|
-
if (!
|
|
4069
|
+
if (!cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4002
4070
|
return null;
|
|
4003
4071
|
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(model, identifiers);
|
|
4004
4072
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -4009,9 +4077,8 @@ class FirestoreCacheHelper {
|
|
|
4009
4077
|
return null;
|
|
4010
4078
|
}
|
|
4011
4079
|
static async getCachedFindData(cache, params) {
|
|
4012
|
-
var _a;
|
|
4013
4080
|
const { model, find, options, logger } = params;
|
|
4014
|
-
if (!
|
|
4081
|
+
if (!cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4015
4082
|
return null;
|
|
4016
4083
|
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(model, find);
|
|
4017
4084
|
const cachedData = await cache.cacheAdapter.get(cacheKey);
|
|
@@ -4023,7 +4090,7 @@ class FirestoreCacheHelper {
|
|
|
4023
4090
|
}
|
|
4024
4091
|
static async saveCacheData(cache, params) {
|
|
4025
4092
|
const { cacheKey, data, expirationInSeconds, logger, req } = params;
|
|
4026
|
-
if (!
|
|
4093
|
+
if (!cache?.cacheAdapter)
|
|
4027
4094
|
return;
|
|
4028
4095
|
await cache.cacheAdapter.set({
|
|
4029
4096
|
key: cacheKey,
|
|
@@ -4035,7 +4102,7 @@ class FirestoreCacheHelper {
|
|
|
4035
4102
|
}
|
|
4036
4103
|
static async removeCacheData(cache, params) {
|
|
4037
4104
|
const { cacheKey, logger } = params;
|
|
4038
|
-
if (!
|
|
4105
|
+
if (!cache?.cacheAdapter)
|
|
4039
4106
|
return;
|
|
4040
4107
|
await cache.cacheAdapter.remove(cacheKey);
|
|
4041
4108
|
logger.log(`Cache removido: ${cacheKey}`);
|
|
@@ -4053,7 +4120,7 @@ class FirestoreOperationsHelper {
|
|
|
4053
4120
|
this.model = model;
|
|
4054
4121
|
}
|
|
4055
4122
|
buildInstanceFromIdentifiers(identifiers) {
|
|
4056
|
-
return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (
|
|
4123
|
+
return this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
|
|
4057
4124
|
}
|
|
4058
4125
|
async validateDocumentExists(docRef, collectionName, identifiers) {
|
|
4059
4126
|
const docSnapshot = await docRef.get();
|
|
@@ -4075,7 +4142,7 @@ class FirestoreOperationsHelper {
|
|
|
4075
4142
|
calculateCount(data, limits) {
|
|
4076
4143
|
if (data.length <= 0)
|
|
4077
4144
|
return 0;
|
|
4078
|
-
if (data.length
|
|
4145
|
+
if (data.length)
|
|
4079
4146
|
return data.length;
|
|
4080
4147
|
return Infinity;
|
|
4081
4148
|
}
|
|
@@ -4088,8 +4155,8 @@ class FirestoreOperationsHelper {
|
|
|
4088
4155
|
const { isSubCollection, collectionName, parentRepository, parentIdField, identifiers } = params;
|
|
4089
4156
|
if (!isSubCollection)
|
|
4090
4157
|
return collectionName;
|
|
4091
|
-
const parentId = identifiers
|
|
4092
|
-
return `${parentRepository
|
|
4158
|
+
const parentId = identifiers?.[parentIdField];
|
|
4159
|
+
return `${parentRepository?.collectionName}/${parentId}/${collectionName}`;
|
|
4093
4160
|
}
|
|
4094
4161
|
getKeyField() {
|
|
4095
4162
|
const model = new this.model();
|
|
@@ -4140,27 +4207,25 @@ const createGetFirestoreClass = (MixinBase) => {
|
|
|
4140
4207
|
}
|
|
4141
4208
|
}
|
|
4142
4209
|
async executeGet(params) {
|
|
4143
|
-
var _a, _b, _c, _d;
|
|
4144
4210
|
const { instance, collectionName, identifiers, logger, req } = params;
|
|
4145
|
-
const intercepted = await
|
|
4146
|
-
const builded =
|
|
4211
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4212
|
+
const builded = intercepted?.instance || instance;
|
|
4147
4213
|
const docRef = await this.operationsHelper.getDocumentSnapshot(this.collection(collectionName), builded);
|
|
4148
4214
|
const data = docRef.data();
|
|
4149
4215
|
this.operationsHelper.validateDocumentData(data, collectionName, identifiers);
|
|
4150
|
-
const result = (await
|
|
4216
|
+
const result = (await this.interceptors?.response?.(data, intercepted)) || data;
|
|
4151
4217
|
logger.log({ req, res: result });
|
|
4152
4218
|
return result;
|
|
4153
4219
|
}
|
|
4154
4220
|
async saveCacheData(params) {
|
|
4155
|
-
var _a, _b, _c;
|
|
4156
4221
|
const { identifiers, options, result, logger, req } = params;
|
|
4157
|
-
if (!
|
|
4222
|
+
if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4158
4223
|
return;
|
|
4159
4224
|
const cacheKey = FirestoreCacheHelper.generateGetCacheKey(this.model, identifiers);
|
|
4160
4225
|
await FirestoreCacheHelper.saveCacheData(this.cache, {
|
|
4161
4226
|
cacheKey,
|
|
4162
4227
|
data: result,
|
|
4163
|
-
expirationInSeconds:
|
|
4228
|
+
expirationInSeconds: options?.cache?.ttl,
|
|
4164
4229
|
logger,
|
|
4165
4230
|
req,
|
|
4166
4231
|
});
|
|
@@ -4191,14 +4256,13 @@ class FirestoreQueryBuilderHelper {
|
|
|
4191
4256
|
this.config = config;
|
|
4192
4257
|
}
|
|
4193
4258
|
buildWhereSentence(fieldName, options) {
|
|
4194
|
-
|
|
4195
|
-
if (((_b = (_a = this.config).isSubCollection) === null || _b === void 0 ? void 0 : _b.call(_a, this)) && fieldName === this.config.parentIdField)
|
|
4259
|
+
if (this.config.isSubCollection?.(this) && fieldName === this.config.parentIdField)
|
|
4196
4260
|
return [];
|
|
4197
4261
|
const firestoreFieldName = this.getFirestoreFieldName(fieldName, options);
|
|
4198
4262
|
return this.buildWhereConditions(firestoreFieldName, options, fieldName);
|
|
4199
4263
|
}
|
|
4200
4264
|
getFirestoreFieldName(fieldName, options) {
|
|
4201
|
-
const value =
|
|
4265
|
+
const value = options?.value || options;
|
|
4202
4266
|
const object = {};
|
|
4203
4267
|
set(object, fieldName.toString(), value);
|
|
4204
4268
|
const plainInstance = new this.config.model(object).toPlain();
|
|
@@ -4207,19 +4271,19 @@ class FirestoreQueryBuilderHelper {
|
|
|
4207
4271
|
: Object.keys(plainInstance).find((key) => plainInstance[key]);
|
|
4208
4272
|
}
|
|
4209
4273
|
buildWhereConditions(firestoreFieldName, options, fieldName) {
|
|
4210
|
-
if (
|
|
4274
|
+
if (options?.operator === Where.LIKE) {
|
|
4211
4275
|
return this.buildLikeConditions(firestoreFieldName, options);
|
|
4212
4276
|
}
|
|
4213
|
-
if (
|
|
4277
|
+
if (options?.operator === Where.IN && Array.isArray(options?.value)) {
|
|
4214
4278
|
return this.buildInConditions(firestoreFieldName, options);
|
|
4215
4279
|
}
|
|
4216
4280
|
if (this.isNestedObjectFilter(options)) {
|
|
4217
4281
|
return this.buildNestedObjectConditions(fieldName, options);
|
|
4218
4282
|
}
|
|
4219
|
-
return [[firestoreFieldName, (
|
|
4283
|
+
return [[firestoreFieldName, (options?.operator || '=='), options?.value || options]];
|
|
4220
4284
|
}
|
|
4221
4285
|
buildLikeConditions(firestoreFieldName, options) {
|
|
4222
|
-
if (this.isArrayField(firestoreFieldName) && Array.isArray(options
|
|
4286
|
+
if (this.isArrayField(firestoreFieldName) && Array.isArray(options?.value)) {
|
|
4223
4287
|
return [[firestoreFieldName, 'array-contains-any', options.value]];
|
|
4224
4288
|
}
|
|
4225
4289
|
return [
|
|
@@ -4236,17 +4300,16 @@ class FirestoreQueryBuilderHelper {
|
|
|
4236
4300
|
buildNestedObjectConditions(fieldName, options) {
|
|
4237
4301
|
return Object.keys(options).reduce((queries, key) => [
|
|
4238
4302
|
...queries,
|
|
4239
|
-
...this.buildWhereSentence(`${fieldName.toString()}.${key}`, is(options)[key]),
|
|
4303
|
+
...this.buildWhereSentence(Array.isArray(options) ? fieldName : `${fieldName.toString()}.${key}`, is(options)[key]),
|
|
4240
4304
|
], []);
|
|
4241
4305
|
}
|
|
4242
4306
|
isArrayField(firestoreFieldName) {
|
|
4243
|
-
|
|
4244
|
-
return (((_a = this.config.fields) === null || _a === void 0 ? void 0 : _a[firestoreFieldName]) ===
|
|
4307
|
+
return (this.config.fields?.[firestoreFieldName] ===
|
|
4245
4308
|
FirestoreFieldType.Array ||
|
|
4246
|
-
!
|
|
4309
|
+
!this.config.fields?.[firestoreFieldName]);
|
|
4247
4310
|
}
|
|
4248
4311
|
isNestedObjectFilter(options) {
|
|
4249
|
-
return isObject(options) && isNil(options
|
|
4312
|
+
return isObject(options) && isNil(options?.operator) && isNil(options?.value);
|
|
4250
4313
|
}
|
|
4251
4314
|
buildOrderBy(filters, fieldsToOrderBy) {
|
|
4252
4315
|
const orderByKeys = Object.keys(fieldsToOrderBy || {});
|
|
@@ -4262,8 +4325,8 @@ class FirestoreQueryBuilderHelper {
|
|
|
4262
4325
|
filtersKeysWithUnordered.forEach((filterKey) => {
|
|
4263
4326
|
const filterValue = filters[filterKey];
|
|
4264
4327
|
const filterOptions = is(filterValue);
|
|
4265
|
-
if (
|
|
4266
|
-
updatedOrderBy =
|
|
4328
|
+
if (filterOptions?.operator && ![Where.EQUALS].includes(filterOptions.operator)) {
|
|
4329
|
+
updatedOrderBy = { [filterKey]: 'asc', ...updatedOrderBy };
|
|
4267
4330
|
}
|
|
4268
4331
|
});
|
|
4269
4332
|
return updatedOrderBy;
|
|
@@ -4277,21 +4340,21 @@ class FirestoreQueryBuilderHelper {
|
|
|
4277
4340
|
async buildLimits(params) {
|
|
4278
4341
|
const { filters, limits, collection, buildCollectionPath } = params;
|
|
4279
4342
|
const queries = [];
|
|
4280
|
-
if (limits
|
|
4343
|
+
if (limits?.offset) {
|
|
4281
4344
|
await this.addOffsetQuery({ queries, limits, filters, collection, buildCollectionPath });
|
|
4282
4345
|
}
|
|
4283
|
-
if (limits
|
|
4346
|
+
if (limits?.limit) {
|
|
4284
4347
|
queries.push(['limit', limits.limit]);
|
|
4285
4348
|
}
|
|
4286
4349
|
return queries;
|
|
4287
4350
|
}
|
|
4288
4351
|
async addOffsetQuery(params) {
|
|
4289
|
-
var _a;
|
|
4290
4352
|
const { queries, limits, filters, collection, buildCollectionPath } = params;
|
|
4291
4353
|
if (this.config.model.isModel(limits.offset)) {
|
|
4292
4354
|
const docSnapshot = await collection(buildCollectionPath(filters))
|
|
4293
|
-
.getDoc(
|
|
4294
|
-
.shift()
|
|
4355
|
+
.getDoc(Object.values(limits.offset.identifier)
|
|
4356
|
+
.shift()
|
|
4357
|
+
?.toString())
|
|
4295
4358
|
.get();
|
|
4296
4359
|
queries.push(['fromStartAfter', docSnapshot]);
|
|
4297
4360
|
}
|
|
@@ -4306,7 +4369,7 @@ class FirestoreQueryBuilderHelper {
|
|
|
4306
4369
|
}
|
|
4307
4370
|
|
|
4308
4371
|
const createFilterHelpers = () => {
|
|
4309
|
-
const checkIfIsFilterOption = (filter) => !isNil(filter
|
|
4372
|
+
const checkIfIsFilterOption = (filter) => !isNil(filter?.operator);
|
|
4310
4373
|
const getValueFromFilter = (filter) => {
|
|
4311
4374
|
return checkIfIsFilterOption(filter) ? filter.value : filter;
|
|
4312
4375
|
};
|
|
@@ -4364,20 +4427,19 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4364
4427
|
}
|
|
4365
4428
|
}
|
|
4366
4429
|
async executeFind(params) {
|
|
4367
|
-
var _a, _b, _c, _d, _e, _f;
|
|
4368
4430
|
const { find, collectionName, logger, req } = params;
|
|
4369
4431
|
const collection = this.collection(collectionName);
|
|
4370
|
-
const enableCount =
|
|
4371
|
-
const intercepted = await
|
|
4372
|
-
const { filters, limits, orderBy } =
|
|
4432
|
+
const enableCount = find?.options?.enableCount ?? true;
|
|
4433
|
+
const intercepted = await this.interceptors?.request?.({ find });
|
|
4434
|
+
const { filters, limits, orderBy } = intercepted?.find || find;
|
|
4373
4435
|
const queryData = await this.buildQueryData(filters, orderBy, limits);
|
|
4374
4436
|
const docs = await this.executeQuery(collection, queryData);
|
|
4375
4437
|
const data = docs.docs.map((doc) => doc.data());
|
|
4376
4438
|
const result = {
|
|
4377
|
-
data: (await
|
|
4439
|
+
data: (await this.interceptors?.response?.(data, intercepted)) || data,
|
|
4378
4440
|
count: enableCount ? this.operationsHelper.calculateCount(data, limits) : Infinity,
|
|
4379
4441
|
};
|
|
4380
|
-
logger.log(
|
|
4442
|
+
logger.log({ req, ...queryData, res: result });
|
|
4381
4443
|
return result;
|
|
4382
4444
|
}
|
|
4383
4445
|
async buildQueryData(filters, orderBy, limits) {
|
|
@@ -4393,19 +4455,21 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4393
4455
|
}
|
|
4394
4456
|
async executeQuery(collection, queryData) {
|
|
4395
4457
|
return this.queryBuilder
|
|
4396
|
-
.buildQuery(
|
|
4458
|
+
.buildQuery({
|
|
4459
|
+
collection,
|
|
4460
|
+
...queryData,
|
|
4461
|
+
})
|
|
4397
4462
|
.getDocs();
|
|
4398
4463
|
}
|
|
4399
4464
|
async saveCacheData(params) {
|
|
4400
|
-
var _a, _b, _c;
|
|
4401
4465
|
const { find, options, result, logger } = params;
|
|
4402
|
-
if (!
|
|
4466
|
+
if (!this.cache?.cacheAdapter || options?.cache?.enabled === false)
|
|
4403
4467
|
return;
|
|
4404
4468
|
const cacheKey = this.generateCacheKey(find);
|
|
4405
4469
|
await FirestoreCacheHelper.saveCacheData(this.cache, {
|
|
4406
4470
|
cacheKey,
|
|
4407
4471
|
data: result,
|
|
4408
|
-
expirationInSeconds:
|
|
4472
|
+
expirationInSeconds: options?.cache?.ttl,
|
|
4409
4473
|
logger,
|
|
4410
4474
|
});
|
|
4411
4475
|
}
|
|
@@ -4413,7 +4477,7 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4413
4477
|
if (!this.isSubCollection(this))
|
|
4414
4478
|
return this.collectionName;
|
|
4415
4479
|
const parentIdField = this.parentIdField;
|
|
4416
|
-
const parentId = getValueFromFilter(filters
|
|
4480
|
+
const parentId = getValueFromFilter(filters?.[parentIdField]);
|
|
4417
4481
|
return `${this.parentRepository.collectionName}/${parentId}/${this.collectionName}`;
|
|
4418
4482
|
}
|
|
4419
4483
|
};
|
|
@@ -4422,16 +4486,15 @@ const withFindFirestore = (MixinBase) => {
|
|
|
4422
4486
|
const withCreateFirestore = (MixinBase) => {
|
|
4423
4487
|
return class CreateFirestore extends MixinBase {
|
|
4424
4488
|
async create(data) {
|
|
4425
|
-
var _a, _b, _c, _d;
|
|
4426
4489
|
const logger = this.logger.with('create');
|
|
4427
4490
|
const instance = this.model.toInstance(data);
|
|
4428
|
-
const intercepted = await
|
|
4429
|
-
const builded =
|
|
4491
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4492
|
+
const builded = intercepted?.instance || instance;
|
|
4430
4493
|
const req = { collection: this.buildCollectionPathForAdd(builded), data };
|
|
4431
4494
|
try {
|
|
4432
4495
|
const docRef = await this.save(builded);
|
|
4433
4496
|
const doc = (await docRef.get()).data();
|
|
4434
|
-
const docBuilded = (await
|
|
4497
|
+
const docBuilded = (await this.interceptors?.response?.(doc, intercepted)) || doc;
|
|
4435
4498
|
logger.log({ req, res: docBuilded });
|
|
4436
4499
|
return docBuilded;
|
|
4437
4500
|
}
|
|
@@ -4442,10 +4505,9 @@ const withCreateFirestore = (MixinBase) => {
|
|
|
4442
4505
|
}
|
|
4443
4506
|
}
|
|
4444
4507
|
async save(data) {
|
|
4445
|
-
var _a, _b;
|
|
4446
4508
|
const collectionPath = this.buildCollectionPathForAdd(data);
|
|
4447
4509
|
const collection = this.collection(collectionPath);
|
|
4448
|
-
return collection.add(data,
|
|
4510
|
+
return collection.add(data, Object.values(data.identifier).shift()?.toString?.());
|
|
4449
4511
|
}
|
|
4450
4512
|
buildCollectionPathForAdd(identifiers) {
|
|
4451
4513
|
return this.isSubCollection(this)
|
|
@@ -4456,26 +4518,23 @@ const withCreateFirestore = (MixinBase) => {
|
|
|
4456
4518
|
};
|
|
4457
4519
|
|
|
4458
4520
|
const createUpdateHelpers = () => {
|
|
4459
|
-
const getValueFromParams = (params, field) =>
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
? is(params[field])
|
|
4463
|
-
: is(params[field]).value) || null;
|
|
4464
|
-
};
|
|
4521
|
+
const getValueFromParams = (params, field) => (isNil(is(params[field])?.value)
|
|
4522
|
+
? is(params[field])
|
|
4523
|
+
: is(params[field]).value) || null;
|
|
4465
4524
|
const getValueByAction = (options) => {
|
|
4466
|
-
if (isNil(options
|
|
4525
|
+
if (isNil(options?.action))
|
|
4467
4526
|
return options;
|
|
4468
|
-
if (
|
|
4527
|
+
if (options?.action === UpdateOptionActions.REMOVE_FIELD)
|
|
4469
4528
|
return deleteField();
|
|
4470
|
-
if (
|
|
4529
|
+
if (options?.action === UpdateOptionActions.NULL)
|
|
4471
4530
|
return null;
|
|
4472
|
-
if (Array.isArray(options
|
|
4473
|
-
if (
|
|
4531
|
+
if (Array.isArray(options?.value)) {
|
|
4532
|
+
if (options?.action === UpdateOptionActions.MERGE)
|
|
4474
4533
|
return arrayUnion(...options.value);
|
|
4475
|
-
if (
|
|
4534
|
+
if (options?.action === UpdateOptionActions.REMOVE)
|
|
4476
4535
|
return arrayRemove(...options.value);
|
|
4477
4536
|
}
|
|
4478
|
-
return options
|
|
4537
|
+
return options?.value;
|
|
4479
4538
|
};
|
|
4480
4539
|
return { getValueFromParams, getValueByAction };
|
|
4481
4540
|
};
|
|
@@ -4526,14 +4585,13 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
|
|
|
4526
4585
|
await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
|
|
4527
4586
|
}
|
|
4528
4587
|
async executeUpdate(params) {
|
|
4529
|
-
var _a, _b, _c, _d;
|
|
4530
4588
|
const { data, docRef, logger, req, identifiers } = params;
|
|
4531
4589
|
const plainFromData = this.model.toInstance(this.paramsToPlain(data));
|
|
4532
|
-
const intercepted = await
|
|
4533
|
-
const builded =
|
|
4590
|
+
const intercepted = await this.interceptors?.request?.({ instance: plainFromData });
|
|
4591
|
+
const builded = intercepted?.instance || plainFromData;
|
|
4534
4592
|
await docRef.save(builded.toPlain());
|
|
4535
4593
|
const docData = await docRef.get();
|
|
4536
|
-
const result =
|
|
4594
|
+
const result = this.interceptors?.response?.(docData.data(), intercepted) || docData.data();
|
|
4537
4595
|
logger.log({ req, res: result, identifiers });
|
|
4538
4596
|
return result;
|
|
4539
4597
|
}
|
|
@@ -4549,7 +4607,10 @@ const createUpdateFirestoreClass = (MixinBase, helpers) => {
|
|
|
4549
4607
|
return this.convertParamsToPlainObject(params);
|
|
4550
4608
|
}
|
|
4551
4609
|
convertParamsToPlainObject(params) {
|
|
4552
|
-
return Object.keys(params).reduce((data, currentKey) => (
|
|
4610
|
+
return Object.keys(params).reduce((data, currentKey) => ({
|
|
4611
|
+
...data,
|
|
4612
|
+
...this.processParamValue(currentKey, params[currentKey]),
|
|
4613
|
+
}), {});
|
|
4553
4614
|
}
|
|
4554
4615
|
processParamValue(key, value) {
|
|
4555
4616
|
const processedValue = getValueByAction(value);
|
|
@@ -4590,12 +4651,11 @@ const createDeleteFirestoreClass = (MixinBase) => {
|
|
|
4590
4651
|
await FirestoreCacheHelper.removeCacheData(this.cache, { cacheKey, logger });
|
|
4591
4652
|
}
|
|
4592
4653
|
async executeDeleteOperation(params) {
|
|
4593
|
-
var _a, _b, _c, _d;
|
|
4594
4654
|
const { instance, collectionName, logger, req } = params;
|
|
4595
|
-
const intercepted = await
|
|
4596
|
-
const builded =
|
|
4655
|
+
const intercepted = await this.interceptors?.request?.({ instance });
|
|
4656
|
+
const builded = intercepted?.instance || instance;
|
|
4597
4657
|
await this.operationsHelper.executeDelete(this.collection(collectionName), builded);
|
|
4598
|
-
await
|
|
4658
|
+
await this.interceptors?.response?.(instance, intercepted);
|
|
4599
4659
|
logger.log({ req, res: undefined });
|
|
4600
4660
|
}
|
|
4601
4661
|
buildCollectionPathForRemove(identifiers) {
|
|
@@ -4675,15 +4735,15 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
4675
4735
|
const products = [];
|
|
4676
4736
|
const wheres = [];
|
|
4677
4737
|
for (const productIds of chunks) {
|
|
4678
|
-
if (
|
|
4738
|
+
if (options?.limit && products.length >= options?.limit)
|
|
4679
4739
|
break;
|
|
4680
4740
|
wheres.push(['published', '==', true], ['id', 'in', productIds]);
|
|
4681
|
-
if (options
|
|
4741
|
+
if (options?.hasStock)
|
|
4682
4742
|
wheres.push(['stock.quantity', '>', 0]);
|
|
4683
|
-
if (options
|
|
4684
|
-
wheres.push(['tags', 'array-contains', options
|
|
4743
|
+
if (options?.gender)
|
|
4744
|
+
wheres.push(['tags', 'array-contains', options?.gender]);
|
|
4685
4745
|
const productSnap = await wheres
|
|
4686
|
-
.reduce((collection, where) => collection.where(...where),
|
|
4746
|
+
.reduce((collection, where) => collection.where(...where), options?.limit
|
|
4687
4747
|
? this.collection('productsErpVitrine').limit(options.limit)
|
|
4688
4748
|
: this.collection('productsErpVitrine'))
|
|
4689
4749
|
.getDocs();
|
|
@@ -4748,19 +4808,17 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
4748
4808
|
throw new Error('Method not implemented.');
|
|
4749
4809
|
}
|
|
4750
4810
|
async getBySlug(slug) {
|
|
4751
|
-
var _a;
|
|
4752
4811
|
const result = await this.find({
|
|
4753
4812
|
filters: {
|
|
4754
4813
|
slug: { operator: Where.EQUALS, value: slug },
|
|
4755
4814
|
},
|
|
4756
4815
|
});
|
|
4757
|
-
return
|
|
4816
|
+
return result?.data?.shift();
|
|
4758
4817
|
}
|
|
4759
4818
|
async fetchReviews(status) {
|
|
4760
4819
|
const { data: products } = await this.find();
|
|
4761
4820
|
products.forEach((product) => {
|
|
4762
|
-
|
|
4763
|
-
if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
|
|
4821
|
+
if ([undefined, 0].includes(product.reviews?.length))
|
|
4764
4822
|
return;
|
|
4765
4823
|
const productInfo = {
|
|
4766
4824
|
productId: product.id,
|
|
@@ -4772,11 +4830,11 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
4772
4830
|
this.reviews.rejected = [];
|
|
4773
4831
|
product.reviews.forEach((review) => {
|
|
4774
4832
|
if ([null, undefined].includes(review.status))
|
|
4775
|
-
return this.reviews.pending.push(
|
|
4833
|
+
return this.reviews.pending.push({ ...review, ...productInfo });
|
|
4776
4834
|
if (review.status === false)
|
|
4777
|
-
return this.reviews.rejected.push(
|
|
4835
|
+
return this.reviews.rejected.push({ ...review, ...productInfo });
|
|
4778
4836
|
if (review.status)
|
|
4779
|
-
return this.reviews.approved.push(
|
|
4837
|
+
return this.reviews.approved.push({ ...review, ...productInfo });
|
|
4780
4838
|
return review;
|
|
4781
4839
|
});
|
|
4782
4840
|
});
|
|
@@ -4863,22 +4921,18 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
4863
4921
|
interceptors,
|
|
4864
4922
|
cache,
|
|
4865
4923
|
});
|
|
4866
|
-
this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
|
|
4879
|
-
products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
|
|
4880
|
-
});
|
|
4881
|
-
};
|
|
4924
|
+
this.homeCategoryGroupToPlain = (homeCategoryGroup) => ({
|
|
4925
|
+
category: homeCategoryGroup?.category?.toPlain
|
|
4926
|
+
? homeCategoryGroup?.category?.toPlain()
|
|
4927
|
+
: homeCategoryGroup?.category,
|
|
4928
|
+
products: homeCategoryGroup?.products
|
|
4929
|
+
?.map((product) => (product?.toPlain ? product?.toPlain() : product))
|
|
4930
|
+
.filter(Boolean) || [],
|
|
4931
|
+
});
|
|
4932
|
+
this.plainToHomeCategoryGroup = (homeCategoryGroup) => ({
|
|
4933
|
+
category: Category.toInstance(homeCategoryGroup?.category),
|
|
4934
|
+
products: homeCategoryGroup.products?.map((product) => Product.toInstance(product)),
|
|
4935
|
+
});
|
|
4882
4936
|
}
|
|
4883
4937
|
buildModelInstance() {
|
|
4884
4938
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
@@ -4894,17 +4948,15 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
4894
4948
|
};
|
|
4895
4949
|
}
|
|
4896
4950
|
homeToFirestore(home) {
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
home.data.data.
|
|
4900
|
-
home.data.data.
|
|
4901
|
-
home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
|
|
4951
|
+
if (home.data?.data) {
|
|
4952
|
+
home.data.data.discoverProducts = home.data.data.discoverProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4953
|
+
home.data.data.featuredProducts = home.data.data.featuredProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4954
|
+
home.data.data.verticalProducts = home.data.data.verticalProducts?.map(this.homeCategoryGroupToPlain) || [];
|
|
4902
4955
|
}
|
|
4903
4956
|
return home;
|
|
4904
4957
|
}
|
|
4905
4958
|
homeFromFirestore(home) {
|
|
4906
|
-
|
|
4907
|
-
if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
|
|
4959
|
+
if (home.data?.data) {
|
|
4908
4960
|
home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
|
|
4909
4961
|
home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
|
|
4910
4962
|
home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
|
|
@@ -5043,8 +5095,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
5043
5095
|
},
|
|
5044
5096
|
});
|
|
5045
5097
|
this.orderFromFirestore = (order) => {
|
|
5046
|
-
|
|
5047
|
-
if ((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length) {
|
|
5098
|
+
if (order?.lineItems?.length) {
|
|
5048
5099
|
order.lineItems = order.lineItems.map((lineItem) => {
|
|
5049
5100
|
const prices = !!lineItem.price;
|
|
5050
5101
|
const shopPrice = prices[order.shop];
|
|
@@ -5059,7 +5110,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
5059
5110
|
buildModelInstance() {
|
|
5060
5111
|
const { fromFirestore, toFirestore } = super.buildModelInstance();
|
|
5061
5112
|
return {
|
|
5062
|
-
toFirestore: (data) => toFirestore(
|
|
5113
|
+
toFirestore: (data) => toFirestore(data?.toPlain ? data.toPlain() : data),
|
|
5063
5114
|
fromFirestore: (snap) => {
|
|
5064
5115
|
const instance = fromFirestore(snap);
|
|
5065
5116
|
return this.orderFromFirestore(instance);
|
|
@@ -5090,18 +5141,20 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
|
|
|
5090
5141
|
});
|
|
5091
5142
|
}
|
|
5092
5143
|
async createBlockedOrderOrPayment(params) {
|
|
5093
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5094
5144
|
const { checkout, blockType, type, limiteRange, card = null } = params;
|
|
5095
5145
|
return this.create(OrderBlocked.toInstance({
|
|
5096
5146
|
customer: {
|
|
5097
|
-
name:
|
|
5098
|
-
cpf:
|
|
5099
|
-
id:
|
|
5100
|
-
email:
|
|
5101
|
-
phoneNumber: '+55' +
|
|
5102
|
-
isSubscriber:
|
|
5103
|
-
subscriptionPlan:
|
|
5104
|
-
shippingAddress:
|
|
5147
|
+
name: checkout.user?.displayName || '',
|
|
5148
|
+
cpf: checkout.user?.cpf || '',
|
|
5149
|
+
id: checkout.user?.id,
|
|
5150
|
+
email: checkout.user?.email || '',
|
|
5151
|
+
phoneNumber: '+55' + checkout.user?.phone,
|
|
5152
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
5153
|
+
subscriptionPlan: checkout.user?.subscriptionPlan || '',
|
|
5154
|
+
shippingAddress: {
|
|
5155
|
+
...checkout.shippingAddress,
|
|
5156
|
+
zip: this.formatZip(checkout.shippingAddress?.zip),
|
|
5157
|
+
},
|
|
5105
5158
|
},
|
|
5106
5159
|
blockType,
|
|
5107
5160
|
limiteRange,
|
|
@@ -5349,7 +5402,7 @@ class ConnectDocumentService {
|
|
|
5349
5402
|
this.reference = doc(this.firestore, this.path).withConverter({
|
|
5350
5403
|
toFirestore: (data) => data,
|
|
5351
5404
|
fromFirestore: (snapshot) => {
|
|
5352
|
-
return
|
|
5405
|
+
return { id: snapshot.id, ...snapshot.data() };
|
|
5353
5406
|
},
|
|
5354
5407
|
});
|
|
5355
5408
|
}
|
|
@@ -5387,7 +5440,7 @@ class ConnectCollectionService {
|
|
|
5387
5440
|
this.reference = collection(firestore, path).withConverter({
|
|
5388
5441
|
toFirestore: (data) => data,
|
|
5389
5442
|
fromFirestore: (snapshot) => {
|
|
5390
|
-
return
|
|
5443
|
+
return { id: snapshot.id, ...snapshot.data() };
|
|
5391
5444
|
},
|
|
5392
5445
|
});
|
|
5393
5446
|
}
|
|
@@ -5482,10 +5535,10 @@ class FirebaseFileUploaderService {
|
|
|
5482
5535
|
function createCreateHasuraGraphQLClass(MixinBase) {
|
|
5483
5536
|
return class CreateHasuraGraphQLMixin extends MixinBase {
|
|
5484
5537
|
constructor(...params) {
|
|
5485
|
-
const options = params
|
|
5538
|
+
const options = params?.[0];
|
|
5486
5539
|
super(...params);
|
|
5487
|
-
this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options
|
|
5488
|
-
this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options
|
|
5540
|
+
this.insertGraphQLOperation = HasuraCreateOperationsHelper.buildInsertOperationName(this.tableName, options?.insertGraphQLOperation);
|
|
5541
|
+
this.insertGraphQLObjectType = HasuraCreateOperationsHelper.buildInsertObjectType(this.tableName, options?.insertGraphQLObjectType);
|
|
5489
5542
|
}
|
|
5490
5543
|
async create(data) {
|
|
5491
5544
|
return HasuraCreateOperationsHelper.executeCreate(data, {
|
|
@@ -5512,9 +5565,9 @@ function createCreateHasuraGraphQLClass(MixinBase) {
|
|
|
5512
5565
|
function createDeleteHasuraGraphQLClass(MixinBase) {
|
|
5513
5566
|
return class DeleteHasuraGraphQLMixin extends MixinBase {
|
|
5514
5567
|
constructor(...params) {
|
|
5515
|
-
const options = params
|
|
5568
|
+
const options = params?.[0];
|
|
5516
5569
|
super(...params);
|
|
5517
|
-
this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options
|
|
5570
|
+
this.deleteGraphQLOperation = HasuraDeleteOperationsHelper.buildDeleteOperationName(this.tableName, options?.deleteGraphQLOperation);
|
|
5518
5571
|
}
|
|
5519
5572
|
async delete(identifiers) {
|
|
5520
5573
|
await HasuraDeleteOperationsHelper.executeDelete({
|
|
@@ -5560,9 +5613,9 @@ function createFindHasuraGraphQLClass(MixinBase) {
|
|
|
5560
5613
|
function createGetHasuraGraphQLClass(MixinBase) {
|
|
5561
5614
|
return class GetHasuraGraphQLMixin extends MixinBase {
|
|
5562
5615
|
constructor(...params) {
|
|
5563
|
-
const options = params
|
|
5616
|
+
const options = params?.[0];
|
|
5564
5617
|
super(...params);
|
|
5565
|
-
this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options
|
|
5618
|
+
this.getGraphQLOperation = HasuraGetOperationsHelper.buildGetOperationName(this.tableName, options?.getGraphQLOperation);
|
|
5566
5619
|
}
|
|
5567
5620
|
generateCacheKey(identifiers) {
|
|
5568
5621
|
return HasuraGetCacheHelper.generateCacheKey(this.model, identifiers);
|
|
@@ -5638,11 +5691,11 @@ function createHasuraGraphQLClass(MixinBase) {
|
|
|
5638
5691
|
function createUpdateHasuraGraphQLClass(MixinBase) {
|
|
5639
5692
|
return class UpdateHasuraGraphQLMixin extends MixinBase {
|
|
5640
5693
|
constructor(...params) {
|
|
5641
|
-
const options = params
|
|
5694
|
+
const options = params?.[0];
|
|
5642
5695
|
super(...params);
|
|
5643
|
-
this.updateGraphQLOperation =
|
|
5644
|
-
this.updateGraphQLObjectType =
|
|
5645
|
-
this.updateGraphQLPKType =
|
|
5696
|
+
this.updateGraphQLOperation = options?.updateGraphQLOperation || `update_${this.tableName}_by_pk`;
|
|
5697
|
+
this.updateGraphQLObjectType = options?.updateGraphQLObjectType || `${this.tableName}_set_input`;
|
|
5698
|
+
this.updateGraphQLPKType = options?.updateGraphQLPKType || `${this.tableName}_pk_columns_input`;
|
|
5646
5699
|
}
|
|
5647
5700
|
getIdentifiersFromData(data) {
|
|
5648
5701
|
return HasuraUpdateDataHelper.getIdentifiersFromData(data, this.model);
|
|
@@ -5832,7 +5885,7 @@ const fieldsConfiguration$5 = [
|
|
|
5832
5885
|
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
5833
5886
|
}),
|
|
5834
5887
|
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
5835
|
-
from: (categories) =>
|
|
5888
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
5836
5889
|
},
|
|
5837
5890
|
},
|
|
5838
5891
|
],
|
|
@@ -5913,8 +5966,7 @@ class CategoryCacheOperationsHelper {
|
|
|
5913
5966
|
logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5914
5967
|
}
|
|
5915
5968
|
static shouldUseCache(cacheAdapter, optionsCache) {
|
|
5916
|
-
|
|
5917
|
-
return !!(cacheAdapter && ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.enabled));
|
|
5969
|
+
return !!(cacheAdapter && optionsCache?.cache?.enabled);
|
|
5918
5970
|
}
|
|
5919
5971
|
}
|
|
5920
5972
|
|
|
@@ -6082,19 +6134,25 @@ class CategoryProductOperationsHelper {
|
|
|
6082
6134
|
}
|
|
6083
6135
|
static buildProductQuery(params) {
|
|
6084
6136
|
const { productIds, fields, hasStock, limit } = params;
|
|
6085
|
-
return
|
|
6137
|
+
return {
|
|
6138
|
+
filters: this.buildProductFilters(productIds, hasStock),
|
|
6139
|
+
...(limit ? { limits: { limit } } : {}),
|
|
6140
|
+
fields,
|
|
6141
|
+
options: { enableCount: false },
|
|
6142
|
+
orderBy: {
|
|
6086
6143
|
stock: 'desc',
|
|
6087
6144
|
shoppingCount: 'desc',
|
|
6088
6145
|
rate: 'desc',
|
|
6089
6146
|
name: 'asc',
|
|
6090
|
-
}
|
|
6147
|
+
},
|
|
6148
|
+
};
|
|
6091
6149
|
}
|
|
6092
6150
|
static getGenderParam(shop) {
|
|
6093
6151
|
return shop === Shops.MENSMARKET ? 'male' : 'female';
|
|
6094
6152
|
}
|
|
6095
6153
|
static async fetchMostRelevantProducts(params) {
|
|
6096
6154
|
const { productRepository, mostRelevantsIds, fields, shop, hasStock, optionsCache } = params;
|
|
6097
|
-
if (!
|
|
6155
|
+
if (!mostRelevantsIds?.length)
|
|
6098
6156
|
return [];
|
|
6099
6157
|
const query = this.buildProductQuery({ productIds: mostRelevantsIds, fields, hasStock });
|
|
6100
6158
|
const { data } = await productRepository.findCatalog(query, this.getGenderParam(shop), optionsCache);
|
|
@@ -6123,9 +6181,8 @@ class CategoryProductOperationsHelper {
|
|
|
6123
6181
|
|
|
6124
6182
|
class CategoryMountOperationsHelper {
|
|
6125
6183
|
static async executeMount(params, dependencies) {
|
|
6126
|
-
var _a;
|
|
6127
6184
|
const { category, shop, options = {}, optionsCache } = params;
|
|
6128
|
-
if (!
|
|
6185
|
+
if (!category?.products?.length)
|
|
6129
6186
|
return [];
|
|
6130
6187
|
const cachedResult = await this.tryGetFromCache({
|
|
6131
6188
|
category,
|
|
@@ -6146,7 +6203,7 @@ class CategoryMountOperationsHelper {
|
|
|
6146
6203
|
optionsCache,
|
|
6147
6204
|
dependencies,
|
|
6148
6205
|
});
|
|
6149
|
-
if (mostRelevantProducts.length >= mostRelevantsIds.length) {
|
|
6206
|
+
if (mostRelevantsIds.length && mostRelevantProducts.length >= mostRelevantsIds.length) {
|
|
6150
6207
|
return this.finalizeMountWithMostRelevants({
|
|
6151
6208
|
mostRelevantProducts,
|
|
6152
6209
|
mostRelevantsIds,
|
|
@@ -6223,7 +6280,6 @@ class CategoryMountOperationsHelper {
|
|
|
6223
6280
|
return result;
|
|
6224
6281
|
}
|
|
6225
6282
|
static async saveToCacheIfNeeded(params) {
|
|
6226
|
-
var _a;
|
|
6227
6283
|
const { category, shop, options, optionsCache, result, dependencies } = params;
|
|
6228
6284
|
const shouldUseCache = CategoryCacheOperationsHelper.shouldUseCache(dependencies.cacheAdapter, optionsCache);
|
|
6229
6285
|
if (!shouldUseCache)
|
|
@@ -6233,7 +6289,7 @@ class CategoryMountOperationsHelper {
|
|
|
6233
6289
|
cacheAdapter: dependencies.cacheAdapter,
|
|
6234
6290
|
cacheKey,
|
|
6235
6291
|
products: result,
|
|
6236
|
-
ttl:
|
|
6292
|
+
ttl: optionsCache?.cache?.ttl || dependencies.defaultCacheTtl,
|
|
6237
6293
|
logger: dependencies.logger,
|
|
6238
6294
|
});
|
|
6239
6295
|
}
|
|
@@ -6259,7 +6315,12 @@ class ProductFetchReviewsHelper {
|
|
|
6259
6315
|
...reviews,
|
|
6260
6316
|
...product.reviews
|
|
6261
6317
|
.filter((review) => this.matchesStatus(review, status))
|
|
6262
|
-
.map((review) => (
|
|
6318
|
+
.map((review) => ({
|
|
6319
|
+
...bindReviewToModel(review),
|
|
6320
|
+
productId: product.id,
|
|
6321
|
+
productName: product.name,
|
|
6322
|
+
productSku: product.sku,
|
|
6323
|
+
})),
|
|
6263
6324
|
], []);
|
|
6264
6325
|
}
|
|
6265
6326
|
static matchesStatus(review, status) {
|
|
@@ -6306,8 +6367,7 @@ class ProductReviewCacheHelper {
|
|
|
6306
6367
|
dependencies.logger.log(`Dados salvos no cache: ${key}`);
|
|
6307
6368
|
}
|
|
6308
6369
|
static shouldUseCache(cacheAdapter, options) {
|
|
6309
|
-
|
|
6310
|
-
return !!(cacheAdapter && ((_a = options === null || options === void 0 ? void 0 : options.cache) === null || _a === void 0 ? void 0 : _a.enabled));
|
|
6370
|
+
return !!(cacheAdapter && options?.cache?.enabled);
|
|
6311
6371
|
}
|
|
6312
6372
|
}
|
|
6313
6373
|
|
|
@@ -6318,9 +6378,12 @@ class ProductReviewOperationsHelper {
|
|
|
6318
6378
|
let count = 0;
|
|
6319
6379
|
let offset = 0;
|
|
6320
6380
|
do {
|
|
6321
|
-
const result = await repository.find(
|
|
6322
|
-
|
|
6323
|
-
|
|
6381
|
+
const result = await repository.find({
|
|
6382
|
+
fields: ['id', 'name', 'sku', 'reviews'],
|
|
6383
|
+
...(limit && {
|
|
6384
|
+
limits: { offset, limit },
|
|
6385
|
+
}),
|
|
6386
|
+
});
|
|
6324
6387
|
data = data.concat(result.data);
|
|
6325
6388
|
count = result.data.length;
|
|
6326
6389
|
offset += limit;
|
|
@@ -6331,7 +6394,13 @@ class ProductReviewOperationsHelper {
|
|
|
6331
6394
|
const { data, getReviewStatus } = params;
|
|
6332
6395
|
return data.reduce((reviews, product) => [
|
|
6333
6396
|
...reviews,
|
|
6334
|
-
...product.reviews.map((review) => (
|
|
6397
|
+
...product.reviews.map((review) => ({
|
|
6398
|
+
...review,
|
|
6399
|
+
reviewStatus: getReviewStatus(review),
|
|
6400
|
+
productId: product.id,
|
|
6401
|
+
productName: product.name,
|
|
6402
|
+
productSku: product.sku,
|
|
6403
|
+
})),
|
|
6335
6404
|
], []);
|
|
6336
6405
|
}
|
|
6337
6406
|
static applyReviewFilters(params) {
|
|
@@ -6375,7 +6444,7 @@ class ProductReviewUpdateHelper {
|
|
|
6375
6444
|
const { productId, reviews, dependencies } = params;
|
|
6376
6445
|
const reviewIds = await Promise.all(reviews.value.map(async (reviewData) => {
|
|
6377
6446
|
const review = await dependencies.findReview(reviewData, productId);
|
|
6378
|
-
return review
|
|
6447
|
+
return review?.id;
|
|
6379
6448
|
}));
|
|
6380
6449
|
await dependencies.mutation('delete_product_review', ['affected_rows'], {
|
|
6381
6450
|
where: {
|
|
@@ -6414,7 +6483,7 @@ class ProductReviewUpdateHelper {
|
|
|
6414
6483
|
static async insertNewReview(reviewData, productId, dependencies) {
|
|
6415
6484
|
const result = await dependencies.mutation('insert_product_review_one', dependencies.reviewsFields, {
|
|
6416
6485
|
object: {
|
|
6417
|
-
value: omit(
|
|
6486
|
+
value: omit({ ...dependencies.bindReviewToHasura(reviewData), product_id: productId.toString() }, ['id']),
|
|
6418
6487
|
type: 'product_review_insert_input',
|
|
6419
6488
|
required: true,
|
|
6420
6489
|
},
|
|
@@ -6507,11 +6576,14 @@ const fieldsConfiguration$4 = [
|
|
|
6507
6576
|
bindPersistData: (value) => {
|
|
6508
6577
|
return {
|
|
6509
6578
|
brand_condition: value.brand,
|
|
6510
|
-
tag_condition:
|
|
6579
|
+
tag_condition: value?.tags || [],
|
|
6511
6580
|
};
|
|
6512
6581
|
},
|
|
6513
6582
|
bindFindFilter: (sentence) => {
|
|
6514
|
-
return
|
|
6583
|
+
return {
|
|
6584
|
+
...(sentence.brand ? { brand_condition: sentence.brand } : {}),
|
|
6585
|
+
...(sentence.tags ? { tag_condition: sentence.tags } : {}),
|
|
6586
|
+
};
|
|
6515
6587
|
},
|
|
6516
6588
|
},
|
|
6517
6589
|
},
|
|
@@ -6523,7 +6595,7 @@ const fieldsConfiguration$4 = [
|
|
|
6523
6595
|
bindPersistData: (value) => ({
|
|
6524
6596
|
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
6525
6597
|
}),
|
|
6526
|
-
from: (filters) =>
|
|
6598
|
+
from: (filters) => filters?.map((filter) => filter?.filter).filter((filter) => filter.enabled) || [],
|
|
6527
6599
|
},
|
|
6528
6600
|
},
|
|
6529
6601
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -6588,11 +6660,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6588
6660
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
6589
6661
|
}
|
|
6590
6662
|
async create(params) {
|
|
6591
|
-
const { images, mostRelevants, metadatas
|
|
6592
|
-
return super.create(
|
|
6663
|
+
const { images, mostRelevants, metadatas, ...data } = params;
|
|
6664
|
+
return super.create({
|
|
6665
|
+
...data,
|
|
6666
|
+
isWishlist: false,
|
|
6667
|
+
metadatas: metadatas || [{ shop: null, description: null, title: null }],
|
|
6668
|
+
mostRelevants: mostRelevants || {
|
|
6593
6669
|
[Shops.GLAMSHOP]: null,
|
|
6594
6670
|
[Shops.MENSMARKET]: null,
|
|
6595
|
-
},
|
|
6671
|
+
},
|
|
6672
|
+
images: images || {
|
|
6596
6673
|
[Shops.GLAMSHOP]: {
|
|
6597
6674
|
brandBanner: null,
|
|
6598
6675
|
brandBannerMobile: null,
|
|
@@ -6603,17 +6680,18 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6603
6680
|
brandBannerMobile: null,
|
|
6604
6681
|
image: null,
|
|
6605
6682
|
},
|
|
6606
|
-
}
|
|
6683
|
+
},
|
|
6684
|
+
});
|
|
6607
6685
|
}
|
|
6608
6686
|
async get(identifiers, optionsCache) {
|
|
6609
6687
|
const id = await this.getId(identifiers.id);
|
|
6610
6688
|
return super.get({ id }, optionsCache);
|
|
6611
6689
|
}
|
|
6612
6690
|
async update(params) {
|
|
6613
|
-
const { id, products, metadatas, filters
|
|
6691
|
+
const { id, products, metadatas, filters, ...data } = params;
|
|
6614
6692
|
const categoryId = +(await this.getId(id));
|
|
6615
6693
|
const [category] = await Promise.all([
|
|
6616
|
-
super.update(
|
|
6694
|
+
super.update({ id: categoryId?.toString(), ...data }),
|
|
6617
6695
|
...(products ? [this.updateProducts(categoryId, { products })] : []),
|
|
6618
6696
|
...(metadatas ? [this.updateMetadata(categoryId, { metadatas })] : []),
|
|
6619
6697
|
...(filters ? [this.updateFilters(categoryId, { filters })] : []),
|
|
@@ -6653,7 +6731,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6653
6731
|
}
|
|
6654
6732
|
async getCategoriesForHome(params) {
|
|
6655
6733
|
const { categoryIds, shop, limit = 4, optionsCache } = params;
|
|
6656
|
-
if (!
|
|
6734
|
+
if (!categoryIds?.length)
|
|
6657
6735
|
return [];
|
|
6658
6736
|
const { firestore, hasura } = CategoryHomeOperationsHelper.separateCategoryIds(categoryIds);
|
|
6659
6737
|
const categories = [];
|
|
@@ -6674,11 +6752,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6674
6752
|
});
|
|
6675
6753
|
}
|
|
6676
6754
|
async mountCategory(params) {
|
|
6677
|
-
var _a, _b;
|
|
6678
6755
|
return CategoryMountOperationsHelper.executeMount(params, {
|
|
6679
6756
|
productRepository: this.productRepository,
|
|
6680
|
-
cacheAdapter:
|
|
6681
|
-
defaultCacheTtl:
|
|
6757
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
6758
|
+
defaultCacheTtl: this.cache?.ttlDefault,
|
|
6682
6759
|
logger: this.logger,
|
|
6683
6760
|
});
|
|
6684
6761
|
}
|
|
@@ -6697,12 +6774,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6697
6774
|
return categoryTree.some((c) => c.id == id.toString());
|
|
6698
6775
|
}
|
|
6699
6776
|
async getId(id) {
|
|
6700
|
-
var _a, _b;
|
|
6701
6777
|
if (!Number.isNaN(+id))
|
|
6702
6778
|
return id;
|
|
6703
6779
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
6704
|
-
if (
|
|
6705
|
-
return
|
|
6780
|
+
if (data?.[0]?.id)
|
|
6781
|
+
return data?.[0]?.id;
|
|
6706
6782
|
throw new NotFoundError(`Category with id ${id} not found`);
|
|
6707
6783
|
}
|
|
6708
6784
|
async updateProducts(categoryId, { products }) {
|
|
@@ -6756,7 +6832,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6756
6832
|
objects: {
|
|
6757
6833
|
type: '[category_metadata_insert_input!]',
|
|
6758
6834
|
required: true,
|
|
6759
|
-
value: metadatas.map((m) => (
|
|
6835
|
+
value: metadatas.map((m) => ({ category_id: categoryId, ...m })),
|
|
6760
6836
|
},
|
|
6761
6837
|
});
|
|
6762
6838
|
return metadatas;
|
|
@@ -6922,7 +6998,7 @@ const fieldsConfiguration$3 = [
|
|
|
6922
6998
|
bindPersistData: (value) => ({
|
|
6923
6999
|
categories: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
6924
7000
|
}),
|
|
6925
|
-
from: (categories) =>
|
|
7001
|
+
from: (categories) => categories?.map((category) => category?.category) || [],
|
|
6926
7002
|
},
|
|
6927
7003
|
},
|
|
6928
7004
|
];
|
|
@@ -6941,7 +7017,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6941
7017
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
6942
7018
|
}
|
|
6943
7019
|
async update(params) {
|
|
6944
|
-
const { options
|
|
7020
|
+
const { options, ...data } = params;
|
|
6945
7021
|
const filter = await super.update(data);
|
|
6946
7022
|
filter.options = await this.updateOptions(+data.id, { options });
|
|
6947
7023
|
return filter;
|
|
@@ -6963,8 +7039,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6963
7039
|
if (hasFilter)
|
|
6964
7040
|
filterOptions.push(hasFilter);
|
|
6965
7041
|
}
|
|
6966
|
-
catch
|
|
6967
|
-
const newOption = await this.filterOptionRepository.create(
|
|
7042
|
+
catch {
|
|
7043
|
+
const newOption = await this.filterOptionRepository.create({ ...options.value[i], filterId });
|
|
6968
7044
|
filterOptions.push(newOption);
|
|
6969
7045
|
}
|
|
6970
7046
|
}
|
|
@@ -6978,8 +7054,8 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
6978
7054
|
if (hasFilter)
|
|
6979
7055
|
filterOptions.push(hasFilter);
|
|
6980
7056
|
}
|
|
6981
|
-
catch
|
|
6982
|
-
const newOption = await this.filterOptionRepository.create(
|
|
7057
|
+
catch {
|
|
7058
|
+
const newOption = await this.filterOptionRepository.create({ ...options[i], filterId });
|
|
6983
7059
|
filterOptions.push(newOption);
|
|
6984
7060
|
}
|
|
6985
7061
|
}
|
|
@@ -7100,13 +7176,13 @@ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
|
|
|
7100
7176
|
filters: {
|
|
7101
7177
|
id: {
|
|
7102
7178
|
operator: Where.IN,
|
|
7103
|
-
value: Array.from(new Set(variantsWithNoData.map((item) =>
|
|
7179
|
+
value: Array.from(new Set(variantsWithNoData.map((item) => item.product.productId?.toString()))),
|
|
7104
7180
|
},
|
|
7105
7181
|
},
|
|
7106
7182
|
});
|
|
7107
7183
|
products.forEach((product) => {
|
|
7108
7184
|
result.data
|
|
7109
|
-
.filter((variant) =>
|
|
7185
|
+
.filter((variant) => variant.product.productId?.toString() === product.id.toString())
|
|
7110
7186
|
.forEach((variant) => {
|
|
7111
7187
|
variant.product.name = product.name;
|
|
7112
7188
|
variant.product.group = product.group;
|
|
@@ -7139,21 +7215,37 @@ const commonFields = [
|
|
|
7139
7215
|
purpose: data.purpose,
|
|
7140
7216
|
}),
|
|
7141
7217
|
bindFindFilter: (filters) => {
|
|
7142
|
-
return
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7218
|
+
return {
|
|
7219
|
+
...(filters?.description && { description: filters.description }),
|
|
7220
|
+
...(filters.differentials && { differentials: filters.differentials }),
|
|
7221
|
+
...(filters.whoMustUse && {
|
|
7222
|
+
who_must_use: filters.whoMustUse,
|
|
7223
|
+
}),
|
|
7224
|
+
...(filters.howToUse && {
|
|
7225
|
+
how_to_use: filters.howToUse,
|
|
7226
|
+
}),
|
|
7227
|
+
...(filters.brand && {
|
|
7228
|
+
brand_description: filters.brand,
|
|
7229
|
+
}),
|
|
7230
|
+
...(filters.ingredients && {
|
|
7231
|
+
ingredients: filters.ingredients,
|
|
7232
|
+
}),
|
|
7233
|
+
...(filters.purpose && {
|
|
7234
|
+
purpose: filters.purpose,
|
|
7235
|
+
}),
|
|
7236
|
+
};
|
|
7153
7237
|
},
|
|
7154
|
-
bindPersistData: (descriptionData) => (
|
|
7155
|
-
|
|
7156
|
-
|
|
7238
|
+
bindPersistData: (descriptionData) => ({
|
|
7239
|
+
...(descriptionData?.description && { description: descriptionData.description }),
|
|
7240
|
+
...(descriptionData.differentials && { differentials: descriptionData.differentials }),
|
|
7241
|
+
...(descriptionData.whoMustUse && {
|
|
7242
|
+
who_must_use: descriptionData.whoMustUse,
|
|
7243
|
+
}),
|
|
7244
|
+
...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
|
|
7245
|
+
...(descriptionData.brand && { brand_description: descriptionData.brand }),
|
|
7246
|
+
...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
|
|
7247
|
+
...(descriptionData.purpose && { purpose: descriptionData.purpose }),
|
|
7248
|
+
}),
|
|
7157
7249
|
},
|
|
7158
7250
|
},
|
|
7159
7251
|
{ differentials: { columnName: 'differentials' } },
|
|
@@ -7166,13 +7258,13 @@ const commonFields = [
|
|
|
7166
7258
|
{
|
|
7167
7259
|
images: {
|
|
7168
7260
|
columnName: 'images',
|
|
7169
|
-
to: (value) =>
|
|
7261
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7170
7262
|
},
|
|
7171
7263
|
},
|
|
7172
7264
|
{
|
|
7173
7265
|
miniatures: {
|
|
7174
7266
|
columnName: 'miniatures',
|
|
7175
|
-
to: (value) =>
|
|
7267
|
+
to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
|
|
7176
7268
|
},
|
|
7177
7269
|
},
|
|
7178
7270
|
'name',
|
|
@@ -7187,19 +7279,31 @@ const commonFields = [
|
|
|
7187
7279
|
subscriberPrice: data.subscriber_price,
|
|
7188
7280
|
}),
|
|
7189
7281
|
bindFindFilter: (filters) => {
|
|
7190
|
-
return
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7282
|
+
return {
|
|
7283
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7284
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7285
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7286
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7287
|
+
}),
|
|
7288
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7289
|
+
subscriber_price: filters.subscriberPrice,
|
|
7290
|
+
}),
|
|
7291
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7292
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7293
|
+
}),
|
|
7294
|
+
};
|
|
7197
7295
|
},
|
|
7198
|
-
bindPersistData: (priceData) => (
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7296
|
+
bindPersistData: (priceData) => ({
|
|
7297
|
+
...(priceData?.price >= 0 && { price: priceData.price }),
|
|
7298
|
+
...(priceData.fullPrice >= 0 && { full_price: priceData.fullPrice }),
|
|
7299
|
+
...(priceData.subscriberDiscountPercentage >= 0 && {
|
|
7300
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
7301
|
+
}),
|
|
7302
|
+
...(priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
7303
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
7304
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
7305
|
+
}),
|
|
7306
|
+
}),
|
|
7203
7307
|
},
|
|
7204
7308
|
},
|
|
7205
7309
|
{ fullPrice: { columnName: 'full_price' } },
|
|
@@ -7214,7 +7318,7 @@ const commonFields = [
|
|
|
7214
7318
|
stock: {
|
|
7215
7319
|
columnName: 'stock',
|
|
7216
7320
|
from: (quantity) => ({ quantity }),
|
|
7217
|
-
to: (value) => (isNil(value
|
|
7321
|
+
to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
|
|
7218
7322
|
},
|
|
7219
7323
|
},
|
|
7220
7324
|
{ hasStock: { columnName: 'has_stock' } },
|
|
@@ -7253,7 +7357,7 @@ const fieldsConfiguration$2 = [
|
|
|
7253
7357
|
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
7254
7358
|
}),
|
|
7255
7359
|
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
7256
|
-
from: (categories) =>
|
|
7360
|
+
from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
|
|
7257
7361
|
},
|
|
7258
7362
|
},
|
|
7259
7363
|
{
|
|
@@ -7329,12 +7433,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7329
7433
|
fields: fieldsConfiguration$2,
|
|
7330
7434
|
cache,
|
|
7331
7435
|
});
|
|
7332
|
-
this.bindReviewToModel = (plain) => ProductReview.toInstance(
|
|
7333
|
-
|
|
7436
|
+
this.bindReviewToModel = (plain) => ProductReview.toInstance({
|
|
7437
|
+
...is(omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])),
|
|
7438
|
+
createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at,
|
|
7439
|
+
updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at,
|
|
7440
|
+
personId: plain.person_id,
|
|
7441
|
+
orderId: plain.order_id,
|
|
7442
|
+
});
|
|
7443
|
+
this.bindReviewToHasura = (review) => ({
|
|
7444
|
+
...is(omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])),
|
|
7445
|
+
person_id: review.personId,
|
|
7446
|
+
order_id: review.orderId,
|
|
7447
|
+
});
|
|
7334
7448
|
}
|
|
7335
7449
|
async create(params) {
|
|
7336
|
-
const { metadata
|
|
7337
|
-
const product = await super.create(omit(
|
|
7450
|
+
const { metadata, ...data } = params;
|
|
7451
|
+
const product = await super.create(omit({ ...data, metadata: metadata || { description: null, title: null } }, ['reviews']));
|
|
7338
7452
|
try {
|
|
7339
7453
|
product.reviews = data.reviews && (await this.updateReviews(+product.id, data));
|
|
7340
7454
|
}
|
|
@@ -7345,10 +7459,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7345
7459
|
return product;
|
|
7346
7460
|
}
|
|
7347
7461
|
async get(identifiers, options) {
|
|
7348
|
-
var _a;
|
|
7349
7462
|
const product = Number.isNaN(+identifiers.id)
|
|
7350
|
-
? (
|
|
7351
|
-
.data
|
|
7463
|
+
? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
|
|
7464
|
+
.data?.[0]
|
|
7352
7465
|
: await super.get(identifiers, options);
|
|
7353
7466
|
if (product.productId)
|
|
7354
7467
|
throw new NotFoundError('Product not found, it is a variant');
|
|
@@ -7356,19 +7469,21 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7356
7469
|
return product;
|
|
7357
7470
|
}
|
|
7358
7471
|
async find(params, optionsParams) {
|
|
7359
|
-
|
|
7360
|
-
const _o = params || {}, { filters, fields } = _o, options = __rest(_o, ["filters", "fields"]);
|
|
7472
|
+
const { filters, fields, ...options } = params || {};
|
|
7361
7473
|
const bindFields = fields ||
|
|
7362
7474
|
this.fields
|
|
7363
7475
|
.map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
|
|
7364
7476
|
.filter((field) => field !== 'reviews' && field !== 'categories');
|
|
7365
|
-
if (
|
|
7366
|
-
|
|
7367
|
-
if (
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
return super.find(
|
|
7477
|
+
if (options.options?.minimal?.includes('price'))
|
|
7478
|
+
options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7479
|
+
if (options.options?.maximum?.includes('price'))
|
|
7480
|
+
options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
|
|
7481
|
+
options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
|
|
7482
|
+
options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
|
|
7483
|
+
return super.find({
|
|
7484
|
+
...options,
|
|
7485
|
+
filters: { ...filters, productId: { operator: Where.ISNULL } },
|
|
7486
|
+
fields: [
|
|
7372
7487
|
...bindFields,
|
|
7373
7488
|
...(bindFields.includes('price')
|
|
7374
7489
|
? [
|
|
@@ -7377,11 +7492,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7377
7492
|
'fullPrice',
|
|
7378
7493
|
]
|
|
7379
7494
|
: []),
|
|
7380
|
-
]
|
|
7495
|
+
],
|
|
7496
|
+
}, optionsParams);
|
|
7381
7497
|
}
|
|
7382
7498
|
async getBySlug(slug, options) {
|
|
7383
|
-
|
|
7384
|
-
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)) {
|
|
7499
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7385
7500
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
7386
7501
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7387
7502
|
if (cachedData) {
|
|
@@ -7400,70 +7515,68 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7400
7515
|
});
|
|
7401
7516
|
if (!result.data.length)
|
|
7402
7517
|
return null;
|
|
7403
|
-
const product =
|
|
7518
|
+
const product = result?.data?.shift();
|
|
7404
7519
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
7405
|
-
if (
|
|
7520
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7406
7521
|
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
7407
7522
|
await this.cache.cacheAdapter.set({
|
|
7408
7523
|
key: cacheKey,
|
|
7409
7524
|
data: serialize(product),
|
|
7410
|
-
expirationInSeconds:
|
|
7525
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7411
7526
|
});
|
|
7412
7527
|
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7413
7528
|
}
|
|
7414
7529
|
return product;
|
|
7415
7530
|
}
|
|
7416
7531
|
async update(params) {
|
|
7417
|
-
const
|
|
7532
|
+
const { kitProducts, reviews, id: checkId, metadata, ...data } = omit(params, ['categories', 'rate']);
|
|
7418
7533
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
7419
7534
|
const id = await this.getId(plainData.id);
|
|
7420
|
-
const product = await super.update(
|
|
7535
|
+
const product = await super.update({ id, ...data });
|
|
7421
7536
|
product.kitProducts = kitProducts && (await this.updateKitProducts(+id, { kitProducts }));
|
|
7422
7537
|
product.reviews = reviews && (await this.updateReviews(+id, { reviews }));
|
|
7423
7538
|
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
7424
7539
|
return product;
|
|
7425
7540
|
}
|
|
7426
7541
|
async fetchProductReviews(filters, options) {
|
|
7427
|
-
var _a, _b, _c, _d, _e;
|
|
7428
7542
|
const cacheKey = ProductReviewCacheHelper.generateProductReviewsCacheKey(filters, this.model.name);
|
|
7429
7543
|
const dependencies = {
|
|
7430
|
-
cacheAdapter:
|
|
7544
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
7431
7545
|
logger: this.logger,
|
|
7432
7546
|
modelName: this.model.name,
|
|
7433
|
-
defaultTtl:
|
|
7547
|
+
defaultTtl: this.cache?.ttlDefault,
|
|
7434
7548
|
};
|
|
7435
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7549
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7436
7550
|
const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
|
|
7437
7551
|
if (cachedData)
|
|
7438
7552
|
return cachedData;
|
|
7439
7553
|
}
|
|
7440
|
-
const limit =
|
|
7554
|
+
const limit = filters?.limit || 500;
|
|
7441
7555
|
const data = await ProductReviewOperationsHelper.fetchAllProductsWithReviews({ repository: this, limit });
|
|
7442
7556
|
const reviews = ProductReviewOperationsHelper.processProductsToReviews({
|
|
7443
7557
|
data,
|
|
7444
7558
|
getReviewStatus: this.getReviewStatus.bind(this),
|
|
7445
7559
|
});
|
|
7446
7560
|
const filteredReviews = ProductReviewOperationsHelper.applyReviewFilters({ reviews, filters });
|
|
7447
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7561
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7448
7562
|
await ProductReviewCacheHelper.saveToCache({
|
|
7449
7563
|
key: cacheKey,
|
|
7450
7564
|
data: filteredReviews,
|
|
7451
|
-
ttl:
|
|
7565
|
+
ttl: options?.cache?.ttl,
|
|
7452
7566
|
dependencies,
|
|
7453
7567
|
});
|
|
7454
7568
|
}
|
|
7455
7569
|
return filteredReviews;
|
|
7456
7570
|
}
|
|
7457
7571
|
async fetchReviews(status, options) {
|
|
7458
|
-
var _a, _b, _c, _d, _e;
|
|
7459
7572
|
const cacheKey = ProductReviewCacheHelper.generateReviewsStatusCacheKey(status, this.model.name);
|
|
7460
7573
|
const dependencies = {
|
|
7461
|
-
cacheAdapter:
|
|
7574
|
+
cacheAdapter: this.cache?.cacheAdapter,
|
|
7462
7575
|
logger: this.logger,
|
|
7463
7576
|
modelName: this.model.name,
|
|
7464
|
-
defaultTtl:
|
|
7577
|
+
defaultTtl: this.cache?.ttlDefault,
|
|
7465
7578
|
};
|
|
7466
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7579
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7467
7580
|
const cachedData = await ProductReviewCacheHelper.tryGetFromCache({ key: cacheKey, dependencies });
|
|
7468
7581
|
if (cachedData)
|
|
7469
7582
|
return cachedData;
|
|
@@ -7474,18 +7587,26 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7474
7587
|
reviewsFields: this.reviewsFields,
|
|
7475
7588
|
};
|
|
7476
7589
|
const reviews = await ProductFetchReviewsHelper.executeQuery(status, fetchDependencies);
|
|
7477
|
-
if (ProductReviewCacheHelper.shouldUseCache(
|
|
7590
|
+
if (ProductReviewCacheHelper.shouldUseCache(this.cache?.cacheAdapter, options)) {
|
|
7478
7591
|
await ProductReviewCacheHelper.saveToCache({
|
|
7479
7592
|
key: cacheKey,
|
|
7480
7593
|
data: reviews,
|
|
7481
|
-
ttl:
|
|
7594
|
+
ttl: options?.cache?.ttl,
|
|
7482
7595
|
dependencies,
|
|
7483
7596
|
});
|
|
7484
7597
|
}
|
|
7485
7598
|
return reviews;
|
|
7486
7599
|
}
|
|
7487
7600
|
async findCatalog(params, mainGender, options) {
|
|
7488
|
-
const result = await this.find(
|
|
7601
|
+
const result = await this.find({
|
|
7602
|
+
...params,
|
|
7603
|
+
filters: { ...params.filters, published: true },
|
|
7604
|
+
orderBy: {
|
|
7605
|
+
hasStock: 'desc',
|
|
7606
|
+
...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
|
|
7607
|
+
...omit(params.orderBy, ['hasStock', 'intGender']),
|
|
7608
|
+
},
|
|
7609
|
+
}, options);
|
|
7489
7610
|
return result;
|
|
7490
7611
|
}
|
|
7491
7612
|
async cleanShoppingCountFromIds(ids) {
|
|
@@ -7556,17 +7677,15 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7556
7677
|
return plainData.metadata;
|
|
7557
7678
|
}
|
|
7558
7679
|
async getId(id) {
|
|
7559
|
-
var _a, _b;
|
|
7560
7680
|
if (!Number.isNaN(+id))
|
|
7561
7681
|
return id;
|
|
7562
7682
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
7563
|
-
if (
|
|
7564
|
-
return
|
|
7683
|
+
if (data?.[0]?.id)
|
|
7684
|
+
return data?.[0]?.id;
|
|
7565
7685
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7566
7686
|
}
|
|
7567
7687
|
async findReviewsByProduct(productId, options) {
|
|
7568
|
-
|
|
7569
|
-
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)) {
|
|
7688
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7570
7689
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7571
7690
|
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7572
7691
|
if (cachedData) {
|
|
@@ -7583,13 +7702,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7583
7702
|
required: true,
|
|
7584
7703
|
},
|
|
7585
7704
|
});
|
|
7586
|
-
const reviews = data
|
|
7587
|
-
if (
|
|
7705
|
+
const reviews = data?.map((review) => this.bindReviewToModel(review));
|
|
7706
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && reviews) {
|
|
7588
7707
|
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
7589
7708
|
await this.cache.cacheAdapter.set({
|
|
7590
7709
|
key: cacheKey,
|
|
7591
7710
|
data: serialize(reviews),
|
|
7592
|
-
expirationInSeconds:
|
|
7711
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7593
7712
|
});
|
|
7594
7713
|
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7595
7714
|
}
|
|
@@ -7613,23 +7732,32 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7613
7732
|
async getReviewByPersonId(personId, productId, orderId) {
|
|
7614
7733
|
const { product_review: data } = await this.query('product_review', this.reviewsFields, {
|
|
7615
7734
|
where: {
|
|
7616
|
-
value:
|
|
7735
|
+
value: {
|
|
7736
|
+
product_id: { _eq: productId },
|
|
7737
|
+
person_id: { _eq: personId },
|
|
7738
|
+
...(orderId && { order_id: { _eq: orderId } }),
|
|
7739
|
+
},
|
|
7617
7740
|
type: 'product_review_bool_exp',
|
|
7618
7741
|
required: true,
|
|
7619
7742
|
},
|
|
7620
7743
|
});
|
|
7621
|
-
return
|
|
7744
|
+
return data?.[0] && this.bindReviewToModel(data[0]);
|
|
7622
7745
|
}
|
|
7623
7746
|
async getReviewByAuthorAndEmail(params) {
|
|
7624
7747
|
const { author, email, productId, orderId } = params;
|
|
7625
7748
|
const { product_review: data } = await this.query('product_review', this.reviewsFields, {
|
|
7626
7749
|
where: {
|
|
7627
|
-
value:
|
|
7750
|
+
value: {
|
|
7751
|
+
product_id: { _eq: productId },
|
|
7752
|
+
author: { _eq: author },
|
|
7753
|
+
email: { _eq: email },
|
|
7754
|
+
...(orderId && { order_id: { _eq: orderId } }),
|
|
7755
|
+
},
|
|
7628
7756
|
type: 'product_review_bool_exp',
|
|
7629
7757
|
required: true,
|
|
7630
7758
|
},
|
|
7631
7759
|
});
|
|
7632
|
-
return
|
|
7760
|
+
return data?.[0] && this.bindReviewToModel(data[0]);
|
|
7633
7761
|
}
|
|
7634
7762
|
async productVariantFullReport() {
|
|
7635
7763
|
const dependencies = {
|
|
@@ -7778,7 +7906,16 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
|
|
|
7778
7906
|
});
|
|
7779
7907
|
}
|
|
7780
7908
|
async getNotificationsReport(params, orderBy, pagination) {
|
|
7781
|
-
const query =
|
|
7909
|
+
const query = {
|
|
7910
|
+
...(params.productId && { product_id: { _eq: params.productId } }),
|
|
7911
|
+
...(params.ean && { ean: { _eq: params.ean } }),
|
|
7912
|
+
...(params.sku && { sku: { _eq: params.sku } }),
|
|
7913
|
+
...(params.name && { name: { _iregex: params.name } }),
|
|
7914
|
+
...(params.categoryId && { category_id: { _eq: params.categoryId } }),
|
|
7915
|
+
...(params.category && { category: { _iregex: params.category } }),
|
|
7916
|
+
...(params.reference && { category_reference: { _eq: params.reference } }),
|
|
7917
|
+
...(params.emailsCount && { emails_registered: { _eq: params.emailsCount } }),
|
|
7918
|
+
};
|
|
7782
7919
|
const orderByField = {
|
|
7783
7920
|
[orderBy.field]: orderBy.direction,
|
|
7784
7921
|
};
|
|
@@ -7794,8 +7931,8 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
|
|
|
7794
7931
|
required: true,
|
|
7795
7932
|
},
|
|
7796
7933
|
});
|
|
7797
|
-
const data =
|
|
7798
|
-
? reportStockNotification.slice(pagination
|
|
7934
|
+
const data = pagination?.limit
|
|
7935
|
+
? reportStockNotification.slice(pagination?.offset, pagination?.offset + pagination?.limit)
|
|
7799
7936
|
: reportStockNotification;
|
|
7800
7937
|
return {
|
|
7801
7938
|
data,
|
|
@@ -7811,7 +7948,7 @@ const fieldsConfiguration$1 = [
|
|
|
7811
7948
|
productId: {
|
|
7812
7949
|
columnName: 'main_product_id',
|
|
7813
7950
|
to: (value) => +value,
|
|
7814
|
-
from: (value) => value
|
|
7951
|
+
from: (value) => value?.toString(),
|
|
7815
7952
|
},
|
|
7816
7953
|
},
|
|
7817
7954
|
{ EAN: { columnName: 'ean' } },
|
|
@@ -7828,19 +7965,31 @@ const fieldsConfiguration$1 = [
|
|
|
7828
7965
|
}),
|
|
7829
7966
|
bindFindFilter: (sentence) => {
|
|
7830
7967
|
const filters = Object.values(sentence).shift();
|
|
7831
|
-
return
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7968
|
+
return {
|
|
7969
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7970
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7971
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7972
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7973
|
+
}),
|
|
7974
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7975
|
+
subscriber_price: filters.subscriberPrice,
|
|
7976
|
+
}),
|
|
7977
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7978
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7979
|
+
}),
|
|
7980
|
+
};
|
|
7838
7981
|
},
|
|
7839
|
-
bindPersistData: (priceData) => (
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7982
|
+
bindPersistData: (priceData) => ({
|
|
7983
|
+
...((priceData?.price || 0) >= 0 && { price: priceData.price }),
|
|
7984
|
+
...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
|
|
7985
|
+
...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
|
|
7986
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
7987
|
+
}),
|
|
7988
|
+
...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
7989
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
7990
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
7991
|
+
}),
|
|
7992
|
+
}),
|
|
7844
7993
|
},
|
|
7845
7994
|
},
|
|
7846
7995
|
{ fullPrice: { columnName: 'full_price' } },
|
|
@@ -7852,7 +8001,7 @@ const fieldsConfiguration$1 = [
|
|
|
7852
8001
|
stock: {
|
|
7853
8002
|
columnName: 'stock',
|
|
7854
8003
|
from: (quantity) => ({ quantity }),
|
|
7855
|
-
to: (value) => (isNil(value
|
|
8004
|
+
to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
|
|
7856
8005
|
},
|
|
7857
8006
|
},
|
|
7858
8007
|
{ hasStock: { columnName: 'has_stock' } },
|
|
@@ -7885,41 +8034,39 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7885
8034
|
});
|
|
7886
8035
|
}
|
|
7887
8036
|
async get(identifiers) {
|
|
7888
|
-
var _a;
|
|
7889
8037
|
if (!identifiers.id) {
|
|
7890
8038
|
throw new NotFoundError('Variant ID is required');
|
|
7891
8039
|
}
|
|
7892
8040
|
const variant = Number.isNaN(+identifiers.id)
|
|
7893
|
-
? (
|
|
8041
|
+
? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
|
|
7894
8042
|
: await super.get(identifiers);
|
|
7895
8043
|
if (!variant.productId)
|
|
7896
8044
|
throw new NotFoundError('Variant not found, it is a product');
|
|
7897
8045
|
return variant;
|
|
7898
8046
|
}
|
|
7899
8047
|
async find(params) {
|
|
7900
|
-
const
|
|
7901
|
-
return super.find(
|
|
8048
|
+
const { filters, ...options } = params || {};
|
|
8049
|
+
return super.find({ ...options, filters: { productId: { operator: Where.ISNOTNULL }, ...filters } });
|
|
7902
8050
|
}
|
|
7903
8051
|
async update(params) {
|
|
7904
|
-
const { productId, id: checkId
|
|
8052
|
+
const { productId, id: checkId, ...data } = params;
|
|
7905
8053
|
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
7906
8054
|
if (!dataWithProductId.id) {
|
|
7907
8055
|
throw new NotFoundError('Variant ID is required for update');
|
|
7908
8056
|
}
|
|
7909
8057
|
const id = await this.getId(dataWithProductId.id);
|
|
7910
|
-
const product = await super.update(
|
|
8058
|
+
const product = await super.update({ id, ...data });
|
|
7911
8059
|
if (dataWithProductId.productId) {
|
|
7912
8060
|
product.productId = dataWithProductId.productId;
|
|
7913
8061
|
}
|
|
7914
8062
|
return product;
|
|
7915
8063
|
}
|
|
7916
8064
|
async getId(id) {
|
|
7917
|
-
var _a, _b;
|
|
7918
8065
|
if (!Number.isNaN(+id))
|
|
7919
8066
|
return id;
|
|
7920
8067
|
const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
|
|
7921
|
-
if (
|
|
7922
|
-
return
|
|
8068
|
+
if (data?.[0]?.id)
|
|
8069
|
+
return data?.[0]?.id;
|
|
7923
8070
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
7924
8071
|
}
|
|
7925
8072
|
}
|
|
@@ -7950,11 +8097,14 @@ const fieldsConfiguration = [
|
|
|
7950
8097
|
bindPersistData: (value) => {
|
|
7951
8098
|
return {
|
|
7952
8099
|
brand_condition: value.brand,
|
|
7953
|
-
tag_condition:
|
|
8100
|
+
tag_condition: value?.tags || [],
|
|
7954
8101
|
};
|
|
7955
8102
|
},
|
|
7956
8103
|
bindFindFilter: (sentence) => {
|
|
7957
|
-
return
|
|
8104
|
+
return {
|
|
8105
|
+
...(sentence.brand ? { brand_condition: sentence.brand } : {}),
|
|
8106
|
+
...(sentence.tags ? { tag_condition: sentence.tags } : {}),
|
|
8107
|
+
};
|
|
7958
8108
|
},
|
|
7959
8109
|
},
|
|
7960
8110
|
},
|
|
@@ -7966,7 +8116,7 @@ const fieldsConfiguration = [
|
|
|
7966
8116
|
bindPersistData: (value) => ({
|
|
7967
8117
|
filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
|
|
7968
8118
|
}),
|
|
7969
|
-
from: (filters) =>
|
|
8119
|
+
from: (filters) => filters?.map((filter) => filter?.filter) || [],
|
|
7970
8120
|
},
|
|
7971
8121
|
},
|
|
7972
8122
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -8034,12 +8184,18 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8034
8184
|
this.categoryProductRepository = categoryProductRepository;
|
|
8035
8185
|
}
|
|
8036
8186
|
async create(params) {
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8187
|
+
const { images, mostRelevants, metadatas, ...data } = params;
|
|
8188
|
+
return super.create({
|
|
8189
|
+
...data,
|
|
8190
|
+
isWishlist: true,
|
|
8191
|
+
isCollection: true,
|
|
8192
|
+
brandCategory: false,
|
|
8193
|
+
metadatas: metadatas || [{ shop: data.shop ?? null, description: data.description, title: data.name }],
|
|
8194
|
+
mostRelevants: mostRelevants || {
|
|
8040
8195
|
[Shops.GLAMSHOP]: null,
|
|
8041
8196
|
[Shops.MENSMARKET]: null,
|
|
8042
|
-
},
|
|
8197
|
+
},
|
|
8198
|
+
images: images || {
|
|
8043
8199
|
[Shops.GLAMSHOP]: {
|
|
8044
8200
|
brandBanner: null,
|
|
8045
8201
|
brandBannerMobile: null,
|
|
@@ -8050,7 +8206,8 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8050
8206
|
brandBannerMobile: null,
|
|
8051
8207
|
image: null,
|
|
8052
8208
|
},
|
|
8053
|
-
}
|
|
8209
|
+
},
|
|
8210
|
+
});
|
|
8054
8211
|
}
|
|
8055
8212
|
async get(identifiers) {
|
|
8056
8213
|
const data = await super.get(identifiers);
|
|
@@ -8059,14 +8216,20 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8059
8216
|
return data;
|
|
8060
8217
|
}
|
|
8061
8218
|
async find(params) {
|
|
8062
|
-
const { filters
|
|
8063
|
-
return await super.find(
|
|
8219
|
+
const { filters, ...rest } = params;
|
|
8220
|
+
return await super.find({
|
|
8221
|
+
...rest,
|
|
8222
|
+
filters: {
|
|
8223
|
+
...filters,
|
|
8224
|
+
isWishlist: { operator: Where.EQUALS, value: true },
|
|
8225
|
+
},
|
|
8226
|
+
});
|
|
8064
8227
|
}
|
|
8065
8228
|
async update(params) {
|
|
8066
|
-
const
|
|
8229
|
+
const { id: checkId, metadatas, ...data } = omit(params, ['products', 'filters']);
|
|
8067
8230
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
8068
8231
|
const id = plainData.id;
|
|
8069
|
-
const category = await super.update(
|
|
8232
|
+
const category = await super.update({ id, ...data, isWishlist: true, isCollection: true, brandCategory: false });
|
|
8070
8233
|
category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
|
|
8071
8234
|
return category;
|
|
8072
8235
|
}
|
|
@@ -8129,11 +8292,22 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8129
8292
|
return data;
|
|
8130
8293
|
}
|
|
8131
8294
|
async findBfluOrGlamgirlWishlists(params, shops) {
|
|
8132
|
-
|
|
8133
|
-
|
|
8295
|
+
return this.find({
|
|
8296
|
+
...params,
|
|
8297
|
+
filters: {
|
|
8298
|
+
...params.filters,
|
|
8299
|
+
published: true,
|
|
8300
|
+
shops: { operator: Where.LIKE, value: shops },
|
|
8301
|
+
personType: params.filters?.personType ?? {
|
|
8134
8302
|
operator: Where.IN,
|
|
8135
8303
|
value: [PersonTypes.BFLU, PersonTypes.GLAMGIRL],
|
|
8136
|
-
}
|
|
8304
|
+
},
|
|
8305
|
+
},
|
|
8306
|
+
orderBy: {
|
|
8307
|
+
personHasPhoto: 'desc',
|
|
8308
|
+
...omit(params.orderBy, ['personHasPhoto']),
|
|
8309
|
+
},
|
|
8310
|
+
});
|
|
8137
8311
|
}
|
|
8138
8312
|
getCategoriesForHome() {
|
|
8139
8313
|
return;
|
|
@@ -8341,7 +8515,7 @@ class PagarmePaymentFactoryHelper {
|
|
|
8341
8515
|
checkoutId: checkout.id,
|
|
8342
8516
|
totalPrice: checkout.totalPrice,
|
|
8343
8517
|
paymentProvider: PaymentProviders.PAGARME,
|
|
8344
|
-
transaction:
|
|
8518
|
+
transaction: { ...resultData, paidAt: new Date() },
|
|
8345
8519
|
});
|
|
8346
8520
|
return payment;
|
|
8347
8521
|
}
|
|
@@ -8368,7 +8542,6 @@ class PagarmeCardAxiosAdapter {
|
|
|
8368
8542
|
this.orderBlockedRepository = orderBlockedRepository;
|
|
8369
8543
|
}
|
|
8370
8544
|
async pay(checkout, card) {
|
|
8371
|
-
var _a;
|
|
8372
8545
|
try {
|
|
8373
8546
|
const result = await PagarmePaymentOperationsHelper.executePaymentRequest({
|
|
8374
8547
|
checkout,
|
|
@@ -8394,7 +8567,7 @@ class PagarmeCardAxiosAdapter {
|
|
|
8394
8567
|
if (error instanceof PaymentError) {
|
|
8395
8568
|
throw error;
|
|
8396
8569
|
}
|
|
8397
|
-
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout,
|
|
8570
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
8398
8571
|
}
|
|
8399
8572
|
}
|
|
8400
8573
|
async addCard(card) {
|
|
@@ -8461,7 +8634,10 @@ class PagarmeCardAxiosAdapter {
|
|
|
8461
8634
|
const { data } = await axios({
|
|
8462
8635
|
method: 'POST',
|
|
8463
8636
|
url: `${this.credentials.URL}/transactions`,
|
|
8464
|
-
data:
|
|
8637
|
+
data: {
|
|
8638
|
+
...info,
|
|
8639
|
+
api_key: this.credentials.API_KEY,
|
|
8640
|
+
},
|
|
8465
8641
|
});
|
|
8466
8642
|
return data;
|
|
8467
8643
|
}
|
|
@@ -8472,7 +8648,6 @@ class PagarmeCardAxiosAdapter {
|
|
|
8472
8648
|
}
|
|
8473
8649
|
}
|
|
8474
8650
|
createCardPayment(checkout, card) {
|
|
8475
|
-
var _a, _b, _c, _d, _e, _f;
|
|
8476
8651
|
return {
|
|
8477
8652
|
api_key: this.credentials.API_KEY,
|
|
8478
8653
|
amount: Math.floor(checkout.totalPrice * 100),
|
|
@@ -8499,14 +8674,14 @@ class PagarmeCardAxiosAdapter {
|
|
|
8499
8674
|
name: checkout.user.displayName,
|
|
8500
8675
|
address: {
|
|
8501
8676
|
country: 'br',
|
|
8502
|
-
state: checkout.billingAddress ? checkout.billingAddress.state :
|
|
8503
|
-
city: checkout.billingAddress ? checkout.billingAddress.city :
|
|
8504
|
-
neighborhood: checkout.billingAddress ? checkout.billingAddress.district :
|
|
8505
|
-
street: checkout.billingAddress ? checkout.billingAddress.street :
|
|
8506
|
-
street_number: checkout.billingAddress ? checkout.billingAddress.number :
|
|
8677
|
+
state: checkout.billingAddress ? checkout.billingAddress.state : checkout.shippingAddress?.state,
|
|
8678
|
+
city: checkout.billingAddress ? checkout.billingAddress.city : checkout.shippingAddress?.city,
|
|
8679
|
+
neighborhood: checkout.billingAddress ? checkout.billingAddress.district : checkout.shippingAddress?.district,
|
|
8680
|
+
street: checkout.billingAddress ? checkout.billingAddress.street : checkout.shippingAddress?.street,
|
|
8681
|
+
street_number: checkout.billingAddress ? checkout.billingAddress.number : checkout.shippingAddress?.number,
|
|
8507
8682
|
zipcode: checkout.billingAddress
|
|
8508
8683
|
? checkout.billingAddress.zip.replace('-', '')
|
|
8509
|
-
:
|
|
8684
|
+
: checkout.shippingAddress?.zip.replace('-', ''),
|
|
8510
8685
|
},
|
|
8511
8686
|
},
|
|
8512
8687
|
items: checkout.lineItems.map((item) => {
|
|
@@ -8528,7 +8703,6 @@ class PagarmePixAxiosAdapter {
|
|
|
8528
8703
|
this.paymentRepository = paymentRepository;
|
|
8529
8704
|
}
|
|
8530
8705
|
async pay(checkout) {
|
|
8531
|
-
var _a;
|
|
8532
8706
|
try {
|
|
8533
8707
|
const payload = this.createPixPayment(checkout);
|
|
8534
8708
|
const result = await axios({
|
|
@@ -8552,7 +8726,7 @@ class PagarmePixAxiosAdapter {
|
|
|
8552
8726
|
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
8553
8727
|
checkoutId: checkout.id,
|
|
8554
8728
|
userEmail: checkout.user.email,
|
|
8555
|
-
info:
|
|
8729
|
+
info: error.response?.data,
|
|
8556
8730
|
});
|
|
8557
8731
|
}
|
|
8558
8732
|
}
|