@infrab4a/connect 3.5.0-beta.1 → 3.5.0-beta.2

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 (27) hide show
  1. package/bundles/infrab4a-connect.umd.js +161 -78
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/generic/repository/find.repository.d.ts +3 -0
  4. package/domain/shopping/models/enums/order-status.enum.d.ts +2 -2
  5. package/esm2015/domain/generic/repository/find.repository.js +1 -1
  6. package/esm2015/domain/shopping/models/campaign-hashtag.js +1 -1
  7. package/esm2015/domain/shopping/models/enums/order-status.enum.js +3 -3
  8. package/esm2015/infra/firebase/firestore/enums/firestore-field-type.enum.js +10 -0
  9. package/esm2015/infra/firebase/firestore/enums/index.js +2 -0
  10. package/esm2015/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +11 -5
  11. package/esm2015/infra/firebase/firestore/mixins/with-firestore.mixin.js +34 -7
  12. package/esm2015/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.js +2 -2
  13. package/esm2015/infra/firebase/firestore/repositories/shopping/order-firestore.repository.js +7 -2
  14. package/esm2015/infra/firebase/firestore/types/firestore.repository.type.js +1 -1
  15. package/esm2015/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.js +17 -12
  16. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +28 -17
  17. package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +7 -4
  18. package/esm2015/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.js +2 -2
  19. package/fesm2015/infrab4a-connect.js +108 -43
  20. package/fesm2015/infrab4a-connect.js.map +1 -1
  21. package/infra/firebase/firestore/enums/firestore-field-type.enum.d.ts +8 -0
  22. package/infra/firebase/firestore/enums/index.d.ts +1 -0
  23. package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +2 -2
  24. package/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +2 -2
  25. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +3 -1
  26. package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +4 -9
  27. package/package.json +2 -2
@@ -1465,8 +1465,8 @@
1465
1465
  OrderStatus["EM_PREPARO"] = "Preparando pedido";
1466
1466
  OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
1467
1467
  OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
1468
- OrderStatus["ENVIADO"] = "Pedido Enviado";
1469
- OrderStatus["ENTREGUE"] = "Pedido entregue";
1468
+ OrderStatus["ENVIADO"] = "Enviado";
1469
+ OrderStatus["ENTREGUE"] = "Entregue";
1470
1470
  OrderStatus["CANCELADO"] = "Cancelado";
1471
1471
  OrderStatus["CREDIT_CARD"] = "credit_card";
1472
1472
  })(exports.OrderStatus || (exports.OrderStatus = {}));
@@ -1895,6 +1895,30 @@
1895
1895
  }());
1896
1896
 
1897
1897
  var withFirestore = function (MixinBase) {
1898
+ var isObjectsAndNoDate = function (data) { return data &&
1899
+ !Array.isArray(data) &&
1900
+ typeof data === 'object' &&
1901
+ (data === null || data === void 0 ? void 0 : data.constructor.name) !== 'Timestamp' &&
1902
+ !('seconds' in data); };
1903
+ var bindDate = function (data, keyName) {
1904
+ if ((data === null || data === void 0 ? void 0 : data.constructor.name) === 'Timestamp')
1905
+ return data.toDate();
1906
+ if (data && typeof data === 'object' && 'seconds' in data)
1907
+ return new Date(data.seconds * 1000);
1908
+ if (typeof data === 'number' && ['createdAt', 'updatedAt'].includes(keyName))
1909
+ return new Date(data);
1910
+ return data;
1911
+ };
1912
+ var bindAllDateFromObject = function (data) {
1913
+ return Object.keys(data).reduce(function (object, key) {
1914
+ var _a;
1915
+ return (Object.assign(Object.assign({}, object), (_a = {}, _a[key] = isObjectsAndNoDate(data[key])
1916
+ ? bindAllDateFromObject(data[key])
1917
+ : Array.isArray(data[key])
1918
+ ? data[key].map(function (element) { return (isObjectsAndNoDate(element) ? bindAllDateFromObject(element) : element); })
1919
+ : bindDate(data[key], key), _a)));
1920
+ }, {});
1921
+ };
1898
1922
  return /** @class */ (function (_super) {
1899
1923
  __extends(class_1, _super);
1900
1924
  function class_1() {
@@ -1909,12 +1933,18 @@
1909
1933
  toFirestore: function (data) { return ((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data); },
1910
1934
  fromFirestore: function (snap) {
1911
1935
  var data = snap.data();
1912
- Object.keys(data).forEach(function (key) {
1913
- if (data[key] && typeof data[key] === 'object' && '_seconds' in data[key]) {
1914
- data[key] = data[key].toDate();
1915
- }
1916
- });
1917
- return _this.model.toInstance(Object.assign(Object.assign({}, data), { id: snap.id }));
1936
+ var bindedData;
1937
+ try {
1938
+ var ids = { id: snap.id };
1939
+ bindedData = bindAllDateFromObject(data);
1940
+ return _this.model.toInstance(Object.assign(Object.assign({}, bindedData), ids));
1941
+ }
1942
+ catch (error) {
1943
+ console.info('id', snap.id);
1944
+ console.info('data', JSON.stringify(bindedData));
1945
+ console.error(error);
1946
+ throw error;
1947
+ }
1918
1948
  },
1919
1949
  };
1920
1950
  };
@@ -1976,6 +2006,16 @@
1976
2006
  }(MixinBase));
1977
2007
  };
1978
2008
 
2009
+ var FirestoreFieldType;
2010
+ (function (FirestoreFieldType) {
2011
+ FirestoreFieldType["String"] = "string";
2012
+ FirestoreFieldType["Number"] = "number";
2013
+ FirestoreFieldType["Boolean"] = "boolean";
2014
+ FirestoreFieldType["Timestamp"] = "timestamp";
2015
+ FirestoreFieldType["Array"] = "array";
2016
+ FirestoreFieldType["Map"] = "map";
2017
+ })(FirestoreFieldType || (FirestoreFieldType = {}));
2018
+
1979
2019
  var withFindFirestore = function (MixinBase) {
1980
2020
  var checkIfIsFilterOption = function (filter) { return !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator); };
1981
2021
  var getValueFromFilter = function (filter) {
@@ -2000,13 +2040,16 @@
2000
2040
  ? fieldName.toString()
2001
2041
  : Object.keys(plainInstance).find(function (key) { return plainInstance[key]; });
2002
2042
  if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.LIKE) {
2003
- if (Array.isArray(options === null || options === void 0 ? void 0 : options.value))
2043
+ if (Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
2044
+ (_this.fields[firestoreFieldName] === FirestoreFieldType.Array || !_this.fields[firestoreFieldName]))
2004
2045
  return queryReference.where(firestoreFieldName, 'array-contains-any', options.value);
2005
2046
  queryReference = queryReference.where(firestoreFieldName, '>=', options.value);
2006
2047
  queryReference = queryReference.where(firestoreFieldName, '<=', options.value + "~");
2007
2048
  return queryReference;
2008
2049
  }
2009
- if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.IN && Array.isArray(options === null || options === void 0 ? void 0 : options.value))
2050
+ if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.IN &&
2051
+ Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
2052
+ (_this.fields[firestoreFieldName] === FirestoreFieldType.Array || !_this.fields[firestoreFieldName]))
2010
2053
  return queryReference.where(firestoreFieldName, 'array-contains', options.value);
2011
2054
  if (lodash.isObject(options) && lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) && lodash.isNil(options === null || options === void 0 ? void 0 : options.value)) {
2012
2055
  return Object.keys(options).reduce(function (queryReferenceWithWhere, key) { return _this.buildWhereSentence(queryReferenceWithWhere, fieldName.toString() + "." + key, options[key]); }, queryReference);
@@ -2015,35 +2058,37 @@
2015
2058
  };
2016
2059
  return _this;
2017
2060
  }
2018
- FindFirestore.prototype.find = function (_a) {
2019
- var _b = _a === void 0 ? {} : _a, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
2061
+ FindFirestore.prototype.find = function (_b) {
2062
+ var _c = _b === void 0 ? {} : _b, filters = _c.filters, limits = _c.limits, orderBy = _c.orderBy, options = _c.options;
2063
+ var _a;
2020
2064
  return __awaiter(this, void 0, void 0, function () {
2021
- var orderByKeys, query, filtersKeysWithUnordered, docs, data;
2022
- return __generator(this, function (_a) {
2023
- switch (_a.label) {
2065
+ var orderByKeys, enableCount, query, filtersKeysWithUnordered, docs, data;
2066
+ return __generator(this, function (_b) {
2067
+ switch (_b.label) {
2024
2068
  case 0:
2025
2069
  orderByKeys = Object.keys(orderBy || {});
2070
+ enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
2026
2071
  query = this.collection(this.buildCollectionPathForFind(filters || {}));
2027
2072
  query = this.makeFirestoreWhere(query, filters || {});
2028
2073
  if (orderByKeys.length) {
2029
2074
  filtersKeysWithUnordered = Object.keys(filters || {}).filter(function (filterKey) { return !orderByKeys.includes(filterKey); });
2030
2075
  if (filtersKeysWithUnordered.length)
2031
2076
  filtersKeysWithUnordered.forEach(function (filterKey) {
2032
- var _a;
2033
- return (orderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(filters[filterKey].operator) ? (_a = {}, _a[filterKey] = 'asc', _a) : {})), orderBy));
2077
+ var _b;
2078
+ return (orderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(filters[filterKey].operator) ? (_b = {}, _b[filterKey] = 'asc', _b) : {})), orderBy));
2034
2079
  });
2035
2080
  Object.keys(orderBy).forEach(function (fieldName) { return (query = query.orderBy(fieldName, orderBy[fieldName])); });
2036
2081
  }
2037
2082
  return [4 /*yield*/, this.defineLimits(query, filters, limits)];
2038
2083
  case 1:
2039
- query = _a.sent();
2084
+ query = _b.sent();
2040
2085
  return [4 /*yield*/, query.get()];
2041
2086
  case 2:
2042
- docs = _a.sent();
2087
+ docs = _b.sent();
2043
2088
  data = docs.docs.map(function (doc) { return doc.data(); });
2044
2089
  return [2 /*return*/, {
2045
2090
  data: data,
2046
- count: this.calculateCount(data, limits),
2091
+ count: enableCount ? this.calculateCount(data, limits) : Infinity,
2047
2092
  }];
2048
2093
  }
2049
2094
  });
@@ -2058,23 +2103,23 @@
2058
2103
  };
2059
2104
  FindFirestore.prototype.defineLimits = function (query, filters, limits) {
2060
2105
  return __awaiter(this, void 0, void 0, function () {
2061
- var _a, _b;
2062
- return __generator(this, function (_c) {
2063
- switch (_c.label) {
2106
+ var _b, _c;
2107
+ return __generator(this, function (_d) {
2108
+ switch (_d.label) {
2064
2109
  case 0:
2065
2110
  if (!(limits === null || limits === void 0 ? void 0 : limits.offset)) return [3 /*break*/, 3];
2066
2111
  if (!this.model.isModel(limits.offset)) return [3 /*break*/, 2];
2067
- _b = (_a = query).startAfter;
2112
+ _c = (_b = query).startAfter;
2068
2113
  return [4 /*yield*/, this.collection(this.buildCollectionPathForFind(filters))
2069
2114
  .doc(limits.offset[limits.offset.identifiersFields.shift()])
2070
2115
  .get()];
2071
2116
  case 1:
2072
- query = _b.apply(_a, [_c.sent()]);
2117
+ query = _c.apply(_b, [_d.sent()]);
2073
2118
  return [3 /*break*/, 3];
2074
2119
  case 2:
2075
2120
  if (lodash.isNumber(limits.offset) || lodash.isString(limits.offset))
2076
2121
  query = query.startAt(limits.offset);
2077
- _c.label = 3;
2122
+ _d.label = 3;
2078
2123
  case 3:
2079
2124
  if (limits === null || limits === void 0 ? void 0 : limits.limit)
2080
2125
  query = query.limit(limits.limit);
@@ -2766,7 +2811,8 @@
2766
2811
  var _a;
2767
2812
  if (!!((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length)) {
2768
2813
  order.lineItems = order.lineItems.map(function (lineItem) {
2769
- if (!!lineItem.price[order.shop]) {
2814
+ var _a;
2815
+ if (!!((_a = lineItem.price) === null || _a === void 0 ? void 0 : _a[order.shop])) {
2770
2816
  var shopPrice = lineItem['price'][order.shop];
2771
2817
  lineItem['price'] = shopPrice;
2772
2818
  }
@@ -2777,6 +2823,9 @@
2777
2823
  };
2778
2824
  _this.collectionName = 'orders';
2779
2825
  _this.model = Order;
2826
+ _this.fields = {
2827
+ status: FirestoreFieldType.String,
2828
+ };
2780
2829
  return _this;
2781
2830
  }
2782
2831
  OrderFirestoreRepository.prototype.buildModelInstance = function () {
@@ -3600,14 +3649,16 @@
3600
3649
  function FindHasuraGraphQLMixin() {
3601
3650
  return _super !== null && _super.apply(this, arguments) || this;
3602
3651
  }
3603
- FindHasuraGraphQLMixin.prototype.find = function (options) {
3652
+ FindHasuraGraphQLMixin.prototype.find = function (params) {
3653
+ var _a;
3604
3654
  return __awaiter(this, void 0, void 0, function () {
3605
- var _b, filters, limits, orderBy, variablesCount, variables, result, data, count;
3655
+ var _b, filters, limits, orderBy, options, enableCount, variablesCount, variables, result, data;
3606
3656
  var _this = this;
3607
3657
  return __generator(this, function (_c) {
3608
3658
  switch (_c.label) {
3609
3659
  case 0:
3610
- _b = options || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
3660
+ _b = params || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy, options = _b.options;
3661
+ enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
3611
3662
  variablesCount = Object.assign(Object.assign({}, (lodash.isNil(orderBy) ? {} : { order_by: { type: this.tableName + "_order_by!", list: true, value: orderBy } })), (lodash.isNil(filters)
3612
3663
  ? {}
3613
3664
  : {
@@ -3618,11 +3669,11 @@
3618
3669
  },
3619
3670
  }));
3620
3671
  variables = Object.assign(Object.assign({}, (lodash.isNil(limits) ? {} : limits)), variablesCount);
3621
- return [4 /*yield*/, this.query([
3672
+ return [4 /*yield*/, this.query(__spreadArray([
3622
3673
  {
3623
3674
  operation: this.tableName,
3624
- fields: options.fields
3625
- ? options.fields
3675
+ fields: params.fields
3676
+ ? params.fields
3626
3677
  .map(function (fieldName) {
3627
3678
  var _a;
3628
3679
  return (_a = _this.fields.find(function (fieldOption) { return fieldOption === fieldName; })) !== null && _a !== void 0 ? _a : _this.fields.find(function (fieldOption) { return Object.keys(fieldOption).shift() === fieldName; });
@@ -3630,18 +3681,20 @@
3630
3681
  .filter(Boolean)
3631
3682
  : this.fields,
3632
3683
  variables: variables,
3633
- },
3634
- {
3635
- operation: this.tableName + "_aggregate",
3636
- fields: [{ aggregate: ['count'] }],
3637
- variables: variablesCount,
3638
- },
3639
- ])];
3684
+ }
3685
+ ], __read((enableCount
3686
+ ? [
3687
+ {
3688
+ operation: this.tableName + "_aggregate",
3689
+ fields: [{ aggregate: ['count'] }],
3690
+ variables: variablesCount,
3691
+ },
3692
+ ]
3693
+ : []))))];
3640
3694
  case 1:
3641
3695
  result = _c.sent();
3642
3696
  data = result[this.tableName].map(function (row) { return _this.convertDataFromHasura(row); });
3643
- count = result[this.tableName + "_aggregate"].aggregate.count;
3644
- return [2 /*return*/, { count: count, data: data }];
3697
+ return [2 /*return*/, { data: data, count: enableCount ? result[this.tableName + "_aggregate"].aggregate.count : Infinity }];
3645
3698
  }
3646
3699
  });
3647
3700
  });
@@ -3795,7 +3848,7 @@
3795
3848
  switch (_d.label) {
3796
3849
  case 0:
3797
3850
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3798
- return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3851
+ return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })];
3799
3852
  case 1:
3800
3853
  _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3801
3854
  return [3 /*break*/, 3];
@@ -3849,19 +3902,19 @@
3849
3902
  };
3850
3903
  CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
3851
3904
  return __awaiter(this, void 0, void 0, function () {
3852
- var _c, data, count;
3853
- return __generator(this, function (_d) {
3854
- switch (_d.label) {
3905
+ var data;
3906
+ return __generator(this, function (_c) {
3907
+ switch (_c.label) {
3855
3908
  case 0:
3856
3909
  if (!slug)
3857
3910
  return [2 /*return*/];
3858
- return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
3911
+ return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true }, options: { enableCount: false } })];
3859
3912
  case 1:
3860
- _c = _d.sent(), data = _c.data, count = _c.count;
3861
- if (count > 1)
3862
- throw new DuplicatedResultsError('Query returned duplicated values');
3863
- if (!count)
3913
+ data = (_c.sent()).data;
3914
+ if (!data.length)
3864
3915
  throw new NotFoundError("Category with slug " + slug + " not found");
3916
+ if (data.length > 1)
3917
+ throw new DuplicatedResultsError('Query returned duplicated values');
3865
3918
  return [2 /*return*/, data.shift()];
3866
3919
  }
3867
3920
  });
@@ -3870,17 +3923,46 @@
3870
3923
  CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
3871
3924
  if (limit === void 0) { limit = 4; }
3872
3925
  return __awaiter(this, void 0, void 0, function () {
3873
- var _c, categories, count, homeSections;
3926
+ var categoriesFirestore, categoriesHasura, categories, _c, _d, _e, _f, _g, _h, _j, _k, homeSections;
3874
3927
  var _this = this;
3875
- return __generator(this, function (_d) {
3876
- switch (_d.label) {
3877
- case 0: return [4 /*yield*/, this.find({
3878
- filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
3879
- })];
3928
+ return __generator(this, function (_l) {
3929
+ switch (_l.label) {
3930
+ case 0:
3931
+ if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
3932
+ return [2 /*return*/, []];
3933
+ categoriesFirestore = categoryIds.filter(function (categoryId) { return Number.isNaN(+categoryId); });
3934
+ categoriesHasura = categoryIds.filter(function (categoryId) { return +categoryId > 0; });
3935
+ categories = [];
3936
+ if (!categoriesFirestore.length) return [3 /*break*/, 2];
3937
+ _d = (_c = categories.push).apply;
3938
+ _e = [categories];
3939
+ _f = [[]];
3940
+ return [4 /*yield*/, this.find({
3941
+ filters: { firestoreId: { operator: exports.Where.IN, value: categoriesFirestore.filter(Boolean) }, published: true },
3942
+ }).then(function (_c) {
3943
+ var data = _c.data;
3944
+ return data;
3945
+ })];
3880
3946
  case 1:
3881
- _c = _d.sent(), categories = _c.data, count = _c.count;
3882
- if (!count)
3883
- throw new NotFoundError('Categories not found');
3947
+ _d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_l.sent())])]))]));
3948
+ _l.label = 2;
3949
+ case 2:
3950
+ if (!categoriesHasura.length) return [3 /*break*/, 4];
3951
+ _h = (_g = categories.push).apply;
3952
+ _j = [categories];
3953
+ _k = [[]];
3954
+ return [4 /*yield*/, this.find({
3955
+ filters: { id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) }, published: true },
3956
+ }).then(function (_c) {
3957
+ var data = _c.data;
3958
+ return data;
3959
+ })];
3960
+ case 3:
3961
+ _h.apply(_g, _j.concat([__spreadArray.apply(void 0, _k.concat([__read.apply(void 0, [(_l.sent())])]))]));
3962
+ _l.label = 4;
3963
+ case 4:
3964
+ if (!categories.length)
3965
+ return [2 /*return*/, []];
3884
3966
  return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
3885
3967
  var _c;
3886
3968
  return __generator(this, function (_d) {
@@ -3895,23 +3977,24 @@
3895
3977
  }
3896
3978
  });
3897
3979
  }); }))];
3898
- case 2:
3899
- homeSections = _d.sent();
3980
+ case 5:
3981
+ homeSections = _l.sent();
3900
3982
  return [2 /*return*/, homeSections];
3901
3983
  }
3902
3984
  });
3903
3985
  });
3904
3986
  };
3905
3987
  CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
3988
+ var _a;
3906
3989
  return __awaiter(this, void 0, void 0, function () {
3907
3990
  var products, productsData;
3908
3991
  return __generator(this, function (_c) {
3909
3992
  switch (_c.label) {
3910
3993
  case 0:
3911
- if (!category.products)
3912
- throw new RequiredArgumentError(['Category products is empty']);
3994
+ if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
3995
+ return [2 /*return*/, []];
3913
3996
  products = [];
3914
- return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign({ id: { operator: exports.Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3997
+ return [4 /*yield*/, this.productRepository.find(Object.assign(Object.assign({ filters: Object.assign({ id: { operator: exports.Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3915
3998
  'id',
3916
3999
  'name',
3917
4000
  'slug',
@@ -3935,7 +4018,7 @@
3935
4018
  'tags',
3936
4019
  'type',
3937
4020
  'shoppingCount',
3938
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
4021
+ ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }))];
3939
4022
  case 1:
3940
4023
  productsData = (_c.sent()).data;
3941
4024
  products.push.apply(products, __spreadArray([], __read(productsData)));
@@ -3953,7 +4036,7 @@
3953
4036
  case 0:
3954
4037
  if (!Number.isNaN(+id))
3955
4038
  return [2 /*return*/, id];
3956
- return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4039
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id }, options: { enableCount: false } })];
3957
4040
  case 1:
3958
4041
  data = (_c.sent()).data;
3959
4042
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
@@ -4273,7 +4356,7 @@
4273
4356
  switch (_f.label) {
4274
4357
  case 0:
4275
4358
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
4276
- return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
4359
+ return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })];
4277
4360
  case 1:
4278
4361
  _c = (_a = (_f.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
4279
4362
  return [3 /*break*/, 4];
@@ -4318,21 +4401,21 @@
4318
4401
  ProductHasuraGraphQLRepository.prototype.getBySlug = function (slug) {
4319
4402
  var _a;
4320
4403
  return __awaiter(this, void 0, void 0, function () {
4321
- var result, product, _c;
4322
- return __generator(this, function (_d) {
4323
- switch (_d.label) {
4404
+ var result, product;
4405
+ return __generator(this, function (_c) {
4406
+ switch (_c.label) {
4324
4407
  case 0: return [4 /*yield*/, this.find({
4325
4408
  filters: {
4326
4409
  slug: slug,
4327
4410
  },
4411
+ fields: this.fields.map(function (field) { return typeof field === 'string' ? field : Object.keys(field).shift(); }),
4412
+ options: {
4413
+ enableCount: false,
4414
+ },
4328
4415
  })];
4329
4416
  case 1:
4330
- result = _d.sent();
4417
+ result = _c.sent();
4331
4418
  product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
4332
- _c = product;
4333
- return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
4334
- case 2:
4335
- _c.reviews = _d.sent();
4336
4419
  return [2 /*return*/, product];
4337
4420
  }
4338
4421
  });
@@ -4613,7 +4696,7 @@
4613
4696
  case 0:
4614
4697
  if (!Number.isNaN(+id))
4615
4698
  return [2 /*return*/, id];
4616
- return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4699
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id }, options: { enableCount: false } })];
4617
4700
  case 1:
4618
4701
  data = (_c.sent()).data;
4619
4702
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
@@ -4843,7 +4926,7 @@
4843
4926
  case 0:
4844
4927
  if (!Number.isNaN(+id))
4845
4928
  return [2 /*return*/, id];
4846
- return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4929
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id }, options: { enableCount: false } })];
4847
4930
  case 1:
4848
4931
  data = (_c.sent()).data;
4849
4932
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)