@infrab4a/connect 3.4.3-beta.0 → 3.5.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/bundles/infrab4a-connect.umd.js +157 -362
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/generic/repository/find.repository.d.ts +0 -3
  4. package/domain/shopping/models/enums/order-status.enum.d.ts +2 -2
  5. package/domain/shopping/models/index.d.ts +4 -5
  6. package/domain/shopping/repositories/index.d.ts +2 -4
  7. package/esm2015/domain/generic/repository/find.repository.js +1 -1
  8. package/esm2015/domain/shopping/models/enums/order-status.enum.js +3 -3
  9. package/esm2015/domain/shopping/models/index.js +5 -6
  10. package/esm2015/domain/shopping/repositories/index.js +3 -5
  11. package/esm2015/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +5 -11
  12. package/esm2015/infra/firebase/firestore/mixins/with-firestore.mixin.js +7 -34
  13. package/esm2015/infra/firebase/firestore/repositories/shopping/index.js +4 -6
  14. package/esm2015/infra/firebase/firestore/repositories/shopping/order-firestore.repository.js +2 -7
  15. package/esm2015/infra/firebase/firestore/types/firestore.repository.type.js +1 -1
  16. package/esm2015/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.js +12 -17
  17. package/esm2015/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.js +5 -5
  18. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +17 -28
  19. package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +4 -7
  20. package/esm2015/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.js +2 -2
  21. package/fesm2015/infrab4a-connect.js +91 -185
  22. package/fesm2015/infrab4a-connect.js.map +1 -1
  23. package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +2 -2
  24. package/infra/firebase/firestore/repositories/shopping/index.d.ts +3 -5
  25. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +1 -3
  26. package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +9 -4
  27. package/package.json +2 -2
  28. package/domain/shopping/models/campaign-dashboard.d.ts +0 -15
  29. package/domain/shopping/models/campaign-hashtag.d.ts +0 -18
  30. package/domain/shopping/repositories/campaign-dashboard.repository.d.ts +0 -4
  31. package/domain/shopping/repositories/campaign-hashtag.repository.d.ts +0 -4
  32. package/esm2015/domain/shopping/models/campaign-dashboard.js +0 -7
  33. package/esm2015/domain/shopping/models/campaign-hashtag.js +0 -7
  34. package/esm2015/domain/shopping/repositories/campaign-dashboard.repository.js +0 -2
  35. package/esm2015/domain/shopping/repositories/campaign-hashtag.repository.js +0 -2
  36. package/esm2015/infra/firebase/firestore/enums/firestore-field-type.enum.js +0 -10
  37. package/esm2015/infra/firebase/firestore/enums/index.js +0 -2
  38. package/esm2015/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.js +0 -12
  39. package/esm2015/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.js +0 -12
  40. package/infra/firebase/firestore/enums/firestore-field-type.enum.d.ts +0 -8
  41. package/infra/firebase/firestore/enums/index.d.ts +0 -1
  42. package/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +0 -9
  43. package/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +0 -9
@@ -9,6 +9,7 @@ import { CustomError } from 'ts-custom-error';
9
9
  import axios from 'axios';
10
10
  import firebase from 'firebase';
11
11
  import { mutation, query } from 'gql-query-builder';
12
+ import fetch from 'node-fetch';
12
13
 
13
14
  class BaseModel {
14
15
  get identifier() {
@@ -810,27 +811,17 @@ class Variant extends BaseModel {
810
811
  }
811
812
  }
812
813
 
813
- class Buy2Win extends BaseModel {
814
- static get identifiersFields() {
815
- return ['id'];
816
- }
817
- }
818
- __decorate([
819
- Type(() => Category),
820
- __metadata("design:type", Array)
821
- ], Buy2Win.prototype, "categories", void 0);
822
-
823
- class CampaignDashboard extends BaseModel {
824
- static get identifiersFields() {
825
- return ['id'];
826
- }
827
- }
828
-
829
- class CampaignHashtag extends BaseModel {
830
- static get identifiersFields() {
831
- return ['id'];
832
- }
833
- }
814
+ var OrderStatus;
815
+ (function (OrderStatus) {
816
+ OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
817
+ OrderStatus["EM_PREPARO"] = "Preparando pedido";
818
+ OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
819
+ OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
820
+ OrderStatus["ENVIADO"] = "Pedido Enviado";
821
+ OrderStatus["ENTREGUE"] = "Pedido entregue";
822
+ OrderStatus["CANCELADO"] = "Cancelado";
823
+ OrderStatus["CREDIT_CARD"] = "credit_card";
824
+ })(OrderStatus || (OrderStatus = {}));
834
825
 
835
826
  class LineItem extends Product {
836
827
  }
@@ -871,18 +862,6 @@ __decorate([
871
862
  __metadata("design:type", Coupon)
872
863
  ], Checkout.prototype, "coupon", void 0);
873
864
 
874
- var OrderStatus;
875
- (function (OrderStatus) {
876
- OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
877
- OrderStatus["EM_PREPARO"] = "Preparando pedido";
878
- OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
879
- OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
880
- OrderStatus["ENVIADO"] = "Enviado";
881
- OrderStatus["ENTREGUE"] = "Entregue";
882
- OrderStatus["CANCELADO"] = "Cancelado";
883
- OrderStatus["CREDIT_CARD"] = "credit_card";
884
- })(OrderStatus || (OrderStatus = {}));
885
-
886
865
  class Order extends Checkout {
887
866
  }
888
867
  __decorate([
@@ -912,6 +891,16 @@ __decorate([
912
891
  __metadata("design:type", Coupon)
913
892
  ], CheckoutSubscription.prototype, "coupon", void 0);
914
893
 
894
+ class Buy2Win extends BaseModel {
895
+ static get identifiersFields() {
896
+ return ['id'];
897
+ }
898
+ }
899
+ __decorate([
900
+ Type(() => Category),
901
+ __metadata("design:type", Array)
902
+ ], Buy2Win.prototype, "categories", void 0);
903
+
915
904
  var FilterType;
916
905
  (function (FilterType) {
917
906
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -1185,27 +1174,6 @@ class ProductsIndex {
1185
1174
  }
1186
1175
 
1187
1176
  const withFirestore = (MixinBase) => {
1188
- const isObjectsAndNoDate = (data) => data &&
1189
- !Array.isArray(data) &&
1190
- typeof data === 'object' &&
1191
- (data === null || data === void 0 ? void 0 : data.constructor.name) !== 'Timestamp' &&
1192
- !('seconds' in data);
1193
- const bindDate = (data, keyName) => {
1194
- if ((data === null || data === void 0 ? void 0 : data.constructor.name) === 'Timestamp')
1195
- return data.toDate();
1196
- if (data && typeof data === 'object' && 'seconds' in data)
1197
- return new Date(data.seconds * 1000);
1198
- if (typeof data === 'number' && ['createdAt', 'updatedAt'].includes(keyName))
1199
- return new Date(data);
1200
- return data;
1201
- };
1202
- const bindAllDateFromObject = (data) => {
1203
- return Object.keys(data).reduce((object, key) => (Object.assign(Object.assign({}, object), { [key]: isObjectsAndNoDate(data[key])
1204
- ? bindAllDateFromObject(data[key])
1205
- : Array.isArray(data[key])
1206
- ? data[key].map((element) => (isObjectsAndNoDate(element) ? bindAllDateFromObject(element) : element))
1207
- : bindDate(data[key], key) })), {});
1208
- };
1209
1177
  return class extends MixinBase {
1210
1178
  collection(path) {
1211
1179
  return this.firestore.collection(path || this.collectionName).withConverter(this.buildModelInstance());
@@ -1215,18 +1183,12 @@ const withFirestore = (MixinBase) => {
1215
1183
  toFirestore: (data) => ((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data),
1216
1184
  fromFirestore: (snap) => {
1217
1185
  const data = snap.data();
1218
- let bindedData;
1219
- try {
1220
- const ids = { id: snap.id };
1221
- bindedData = bindAllDateFromObject(data);
1222
- return this.model.toInstance(Object.assign(Object.assign({}, bindedData), ids));
1223
- }
1224
- catch (error) {
1225
- console.info('id', snap.id);
1226
- console.info('data', JSON.stringify(bindedData));
1227
- console.error(error);
1228
- throw error;
1229
- }
1186
+ Object.keys(data).forEach((key) => {
1187
+ if (data[key] && typeof data[key] === 'object' && '_seconds' in data[key]) {
1188
+ data[key] = data[key].toDate();
1189
+ }
1190
+ });
1191
+ return this.model.toInstance(Object.assign(Object.assign({}, data), { id: snap.id }));
1230
1192
  },
1231
1193
  };
1232
1194
  }
@@ -1270,16 +1232,6 @@ const withGetFirestore = (MixinBase) => {
1270
1232
  };
1271
1233
  };
1272
1234
 
1273
- var FirestoreFieldType;
1274
- (function (FirestoreFieldType) {
1275
- FirestoreFieldType["String"] = "string";
1276
- FirestoreFieldType["Number"] = "number";
1277
- FirestoreFieldType["Boolean"] = "boolean";
1278
- FirestoreFieldType["Timestamp"] = "timestamp";
1279
- FirestoreFieldType["Array"] = "array";
1280
- FirestoreFieldType["Map"] = "map";
1281
- })(FirestoreFieldType || (FirestoreFieldType = {}));
1282
-
1283
1235
  const withFindFirestore = (MixinBase) => {
1284
1236
  const checkIfIsFilterOption = (filter) => !isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
1285
1237
  const getValueFromFilter = (filter) => {
@@ -1303,16 +1255,13 @@ const withFindFirestore = (MixinBase) => {
1303
1255
  ? fieldName.toString()
1304
1256
  : Object.keys(plainInstance).find((key) => plainInstance[key]);
1305
1257
  if ((options === null || options === void 0 ? void 0 : options.operator) === Where.LIKE) {
1306
- if (Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
1307
- (this.fields[firestoreFieldName] === FirestoreFieldType.Array || !this.fields[firestoreFieldName]))
1258
+ if (Array.isArray(options === null || options === void 0 ? void 0 : options.value))
1308
1259
  return queryReference.where(firestoreFieldName, 'array-contains-any', options.value);
1309
1260
  queryReference = queryReference.where(firestoreFieldName, '>=', options.value);
1310
1261
  queryReference = queryReference.where(firestoreFieldName, '<=', `${options.value}~`);
1311
1262
  return queryReference;
1312
1263
  }
1313
- if ((options === null || options === void 0 ? void 0 : options.operator) === Where.IN &&
1314
- Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
1315
- (this.fields[firestoreFieldName] === FirestoreFieldType.Array || !this.fields[firestoreFieldName]))
1264
+ if ((options === null || options === void 0 ? void 0 : options.operator) === Where.IN && Array.isArray(options === null || options === void 0 ? void 0 : options.value))
1316
1265
  return queryReference.where(firestoreFieldName, 'array-contains', options.value);
1317
1266
  if (isObject(options) && isNil(options === null || options === void 0 ? void 0 : options.operator) && isNil(options === null || options === void 0 ? void 0 : options.value)) {
1318
1267
  return Object.keys(options).reduce((queryReferenceWithWhere, key) => this.buildWhereSentence(queryReferenceWithWhere, `${fieldName.toString()}.${key}`, options[key]), queryReference);
@@ -1320,11 +1269,9 @@ const withFindFirestore = (MixinBase) => {
1320
1269
  return queryReference.where(firestoreFieldName, (options === null || options === void 0 ? void 0 : options.operator) || '==', (options === null || options === void 0 ? void 0 : options.value) || options);
1321
1270
  };
1322
1271
  }
1323
- find({ filters, limits, orderBy, options } = {}) {
1324
- var _a;
1272
+ find({ filters, limits, orderBy, } = {}) {
1325
1273
  return __awaiter(this, void 0, void 0, function* () {
1326
1274
  const orderByKeys = Object.keys(orderBy || {});
1327
- const enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
1328
1275
  let query = this.collection(this.buildCollectionPathForFind(filters || {}));
1329
1276
  query = this.makeFirestoreWhere(query, filters || {});
1330
1277
  if (orderByKeys.length) {
@@ -1338,7 +1285,7 @@ const withFindFirestore = (MixinBase) => {
1338
1285
  const data = docs.docs.map((doc) => doc.data());
1339
1286
  return {
1340
1287
  data,
1341
- count: enableCount ? this.calculateCount(data, limits) : Infinity,
1288
+ count: this.calculateCount(data, limits),
1342
1289
  };
1343
1290
  });
1344
1291
  }
@@ -1748,33 +1695,6 @@ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpe
1748
1695
  }
1749
1696
  }
1750
1697
 
1751
- class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1752
- constructor(firestore) {
1753
- super();
1754
- this.firestore = firestore;
1755
- this.collectionName = 'buy2win';
1756
- this.model = Buy2Win;
1757
- }
1758
- }
1759
-
1760
- class CampaignDashboardFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1761
- constructor(firestore) {
1762
- super();
1763
- this.firestore = firestore;
1764
- this.collectionName = 'dashboardCampaignsAuto';
1765
- this.model = CampaignDashboard;
1766
- }
1767
- }
1768
-
1769
- class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1770
- constructor(firestore) {
1771
- super();
1772
- this.firestore = firestore;
1773
- this.collectionName = 'hashtagCampaignsAuto';
1774
- this.model = CampaignHashtag;
1775
- }
1776
- }
1777
-
1778
1698
  class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1779
1699
  constructor(firestore) {
1780
1700
  super();
@@ -1784,15 +1704,6 @@ class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1784
1704
  }
1785
1705
  }
1786
1706
 
1787
- class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1788
- constructor(firestore) {
1789
- super();
1790
- this.firestore = firestore;
1791
- this.collectionName = 'checkoutsSubscription';
1792
- this.model = CheckoutSubscription;
1793
- }
1794
- }
1795
-
1796
1707
  class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1797
1708
  constructor(firestore) {
1798
1709
  super();
@@ -1827,8 +1738,7 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
1827
1738
  var _a;
1828
1739
  if (!!((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length)) {
1829
1740
  order.lineItems = order.lineItems.map((lineItem) => {
1830
- var _a;
1831
- if (!!((_a = lineItem.price) === null || _a === void 0 ? void 0 : _a[order.shop])) {
1741
+ if (!!lineItem.price[order.shop]) {
1832
1742
  const shopPrice = lineItem['price'][order.shop];
1833
1743
  lineItem['price'] = shopPrice;
1834
1744
  }
@@ -1839,9 +1749,6 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
1839
1749
  };
1840
1750
  this.collectionName = 'orders';
1841
1751
  this.model = Order;
1842
- this.fields = {
1843
- status: FirestoreFieldType.String,
1844
- };
1845
1752
  }
1846
1753
  buildModelInstance() {
1847
1754
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1855,20 +1762,21 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
1855
1762
  }
1856
1763
  }
1857
1764
 
1858
- class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
1765
+ class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1859
1766
  constructor(firestore) {
1860
- super(firestore);
1767
+ super();
1861
1768
  this.firestore = firestore;
1862
- this.collectionName = 'legacyOrders';
1769
+ this.collectionName = 'payments';
1770
+ this.model = Payment;
1863
1771
  }
1864
1772
  }
1865
1773
 
1866
- class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1774
+ class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1867
1775
  constructor(firestore) {
1868
1776
  super();
1869
1777
  this.firestore = firestore;
1870
- this.collectionName = 'payments';
1871
- this.model = Payment;
1778
+ this.collectionName = 'checkoutsSubscription';
1779
+ this.model = CheckoutSubscription;
1872
1780
  }
1873
1781
  }
1874
1782
 
@@ -1881,6 +1789,23 @@ class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(
1881
1789
  }
1882
1790
  }
1883
1791
 
1792
+ class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1793
+ constructor(firestore) {
1794
+ super();
1795
+ this.firestore = firestore;
1796
+ this.collectionName = 'buy2win';
1797
+ this.model = Buy2Win;
1798
+ }
1799
+ }
1800
+
1801
+ class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
1802
+ constructor(firestore) {
1803
+ super(firestore);
1804
+ this.firestore = firestore;
1805
+ this.collectionName = 'legacyOrders';
1806
+ }
1807
+ }
1808
+
1884
1809
  class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1885
1810
  constructor(firestore) {
1886
1811
  super();
@@ -2338,12 +2263,12 @@ const withHasuraGraphQL = (MixinBase) => {
2338
2263
  fetch(params) {
2339
2264
  return __awaiter(this, void 0, void 0, function* () {
2340
2265
  const headers = this.headers;
2341
- const { data: result } = yield axios({
2342
- url: `${this.endpoint}`,
2266
+ const response = yield fetch(`${this.endpoint}`, {
2343
2267
  method: 'POST',
2344
- data: params,
2268
+ body: JSON.stringify(params),
2345
2269
  headers,
2346
2270
  });
2271
+ const result = yield response.json();
2347
2272
  if (!isNil(result.errors))
2348
2273
  throw new Error(JSON.stringify(result.errors));
2349
2274
  return result.data;
@@ -2467,11 +2392,9 @@ const withGetHasuraGraphQL = (MixinBase) => {
2467
2392
 
2468
2393
  const withFindHasuraGraphQL = (MixinBase) => {
2469
2394
  return class FindHasuraGraphQLMixin extends MixinBase {
2470
- find(params) {
2471
- var _a;
2395
+ find(options) {
2472
2396
  return __awaiter(this, void 0, void 0, function* () {
2473
- const { filters, limits, orderBy, options } = params || {};
2474
- const enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
2397
+ const { filters, limits, orderBy } = options || {};
2475
2398
  const variablesCount = Object.assign(Object.assign({}, (isNil(orderBy) ? {} : { order_by: { type: `${this.tableName}_order_by!`, list: true, value: orderBy } })), (isNil(filters)
2476
2399
  ? {}
2477
2400
  : {
@@ -2485,8 +2408,8 @@ const withFindHasuraGraphQL = (MixinBase) => {
2485
2408
  const result = yield this.query([
2486
2409
  {
2487
2410
  operation: this.tableName,
2488
- fields: params.fields
2489
- ? params.fields
2411
+ fields: options.fields
2412
+ ? options.fields
2490
2413
  .map((fieldName) => {
2491
2414
  var _a;
2492
2415
  return (_a = this.fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
@@ -2495,18 +2418,15 @@ const withFindHasuraGraphQL = (MixinBase) => {
2495
2418
  : this.fields,
2496
2419
  variables,
2497
2420
  },
2498
- ...(enableCount
2499
- ? [
2500
- {
2501
- operation: `${this.tableName}_aggregate`,
2502
- fields: [{ aggregate: ['count'] }],
2503
- variables: variablesCount,
2504
- },
2505
- ]
2506
- : []),
2421
+ {
2422
+ operation: `${this.tableName}_aggregate`,
2423
+ fields: [{ aggregate: ['count'] }],
2424
+ variables: variablesCount,
2425
+ },
2507
2426
  ]);
2508
2427
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
2509
- return { data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity };
2428
+ const count = result[`${this.tableName}_aggregate`].aggregate.count;
2429
+ return { count, data };
2510
2430
  });
2511
2431
  }
2512
2432
  };
@@ -2625,7 +2545,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2625
2545
  var _a;
2626
2546
  return __awaiter(this, void 0, void 0, function* () {
2627
2547
  return Number.isNaN(+identifiers.id)
2628
- ? (_a = (yield this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data) === null || _a === void 0 ? void 0 : _a[0]
2548
+ ? (_a = (yield this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
2629
2549
  : _super.get.call(this, identifiers);
2630
2550
  });
2631
2551
  }
@@ -2647,31 +2567,21 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2647
2567
  return __awaiter(this, void 0, void 0, function* () {
2648
2568
  if (!slug)
2649
2569
  return;
2650
- const { data } = yield this.find({ filters: { slug, shop, published: true }, options: { enableCount: false } });
2651
- if (!data.length)
2652
- throw new NotFoundError(`Category with slug ${slug} not found`);
2653
- if (data.length > 1)
2570
+ const { data, count } = yield this.find({ filters: { slug, shop, published: true } });
2571
+ if (count > 1)
2654
2572
  throw new DuplicatedResultsError('Query returned duplicated values');
2573
+ if (!count)
2574
+ throw new NotFoundError(`Category with slug ${slug} not found`);
2655
2575
  return data.shift();
2656
2576
  });
2657
2577
  }
2658
2578
  getCategoriesForHome(categoryIds, limit = 4) {
2659
2579
  return __awaiter(this, void 0, void 0, function* () {
2660
- if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
2661
- return [];
2662
- const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
2663
- const categoriesHasura = categoryIds.filter((categoryId) => +categoryId > 0);
2664
- const categories = [];
2665
- if (categoriesFirestore.length)
2666
- categories.push(...(yield this.find({
2667
- filters: { firestoreId: { operator: Where.IN, value: categoriesFirestore.filter(Boolean) }, published: true },
2668
- }).then(({ data }) => data)));
2669
- if (categoriesHasura.length)
2670
- categories.push(...(yield this.find({
2671
- filters: { id: { operator: Where.IN, value: categoriesHasura.filter(Boolean) }, published: true },
2672
- }).then(({ data }) => data)));
2673
- if (!categories.length)
2674
- return [];
2580
+ const { data: categories, count } = yield this.find({
2581
+ filters: { firestoreId: { operator: Where.IN, value: categoryIds.filter(Boolean) }, published: true },
2582
+ });
2583
+ if (!count)
2584
+ throw new NotFoundError('Categories not found');
2675
2585
  const homeSections = yield Promise.all(categories.map((category) => __awaiter(this, void 0, void 0, function* () {
2676
2586
  return ({
2677
2587
  category,
@@ -2682,12 +2592,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2682
2592
  });
2683
2593
  }
2684
2594
  mountCategory(category, options) {
2685
- var _a;
2686
2595
  return __awaiter(this, void 0, void 0, function* () {
2687
- if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
2688
- return [];
2596
+ if (!category.products)
2597
+ throw new RequiredArgumentError(['Category products is empty']);
2689
2598
  const products = [];
2690
- const { data: productsData } = yield this.productRepository.find(Object.assign(Object.assign({ filters: Object.assign({ id: { operator: Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})), fields: [
2599
+ const { data: productsData } = yield this.productRepository.find(Object.assign({ filters: Object.assign({ id: { operator: Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})), fields: [
2691
2600
  'id',
2692
2601
  'name',
2693
2602
  'slug',
@@ -2711,7 +2620,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2711
2620
  'tags',
2712
2621
  'type',
2713
2622
  'shoppingCount',
2714
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }));
2623
+ ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})));
2715
2624
  products.push(...productsData);
2716
2625
  return products;
2717
2626
  });
@@ -2721,7 +2630,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2721
2630
  return __awaiter(this, void 0, void 0, function* () {
2722
2631
  if (!Number.isNaN(+id))
2723
2632
  return id;
2724
- const { data } = yield this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
2633
+ const { data } = yield this.find({ filters: { firestoreId: id } });
2725
2634
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
2726
2635
  return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
2727
2636
  throw new NotFoundError(`Category with id ${id} not found`);
@@ -2985,7 +2894,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2985
2894
  var _a;
2986
2895
  return __awaiter(this, void 0, void 0, function* () {
2987
2896
  const product = Number.isNaN(+identifiers.id)
2988
- ? (_a = (yield this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data) === null || _a === void 0 ? void 0 : _a[0]
2897
+ ? (_a = (yield this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
2989
2898
  : yield _super.get.call(this, identifiers);
2990
2899
  if (product.productId)
2991
2900
  throw new NotFoundError('Product not found, it is a variant');
@@ -3013,12 +2922,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3013
2922
  filters: {
3014
2923
  slug,
3015
2924
  },
3016
- fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
3017
- options: {
3018
- enableCount: false,
3019
- },
3020
2925
  });
3021
2926
  const product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
2927
+ product.reviews = yield this.findReviewsByProduct(+product.id);
3022
2928
  return product;
3023
2929
  });
3024
2930
  }
@@ -3181,7 +3087,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3181
3087
  return __awaiter(this, void 0, void 0, function* () {
3182
3088
  if (!Number.isNaN(+id))
3183
3089
  return id;
3184
- const { data } = yield this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
3090
+ const { data } = yield this.find({ filters: { firestoreId: id } });
3185
3091
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
3186
3092
  return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
3187
3093
  throw new NotFoundError(`Product with id ${id} not found`);
@@ -3340,7 +3246,7 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3340
3246
  return __awaiter(this, void 0, void 0, function* () {
3341
3247
  if (!Number.isNaN(+id))
3342
3248
  return id;
3343
- const { data } = yield this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
3249
+ const { data } = yield this.find({ filters: { firestoreId: id } });
3344
3250
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
3345
3251
  return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
3346
3252
  throw new NotFoundError(`Product with id ${id} not found`);
@@ -3352,5 +3258,5 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3352
3258
  * Generated bundle index. Do not edit.
3353
3259
  */
3354
3260
 
3355
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
3261
+ export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
3356
3262
  //# sourceMappingURL=infrab4a-connect.js.map