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

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 +94 -241
  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/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/domain/shopping/repositories/campaign-dashboard.repository.js +1 -1
  9. package/esm2015/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +5 -11
  10. package/esm2015/infra/firebase/firestore/mixins/with-firestore.mixin.js +7 -34
  11. package/esm2015/infra/firebase/firestore/repositories/shopping/order-firestore.repository.js +2 -7
  12. package/esm2015/infra/firebase/firestore/types/firestore.repository.type.js +1 -1
  13. package/esm2015/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.js +12 -17
  14. package/esm2015/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.js +5 -5
  15. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +17 -28
  16. package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +4 -7
  17. package/esm2015/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.js +2 -2
  18. package/fesm2015/infrab4a-connect.js +47 -111
  19. package/fesm2015/infrab4a-connect.js.map +1 -1
  20. package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +2 -2
  21. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +1 -3
  22. package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +9 -4
  23. package/package.json +2 -2
  24. package/esm2015/infra/firebase/firestore/enums/firestore-field-type.enum.js +0 -10
  25. package/esm2015/infra/firebase/firestore/enums/index.js +0 -2
  26. package/infra/firebase/firestore/enums/firestore-field-type.enum.d.ts +0 -8
  27. package/infra/firebase/firestore/enums/index.d.ts +0 -1
@@ -1,13 +1,14 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('ts-custom-error'), require('axios'), require('firebase'), require('gql-query-builder')) :
3
- typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'ts-custom-error', 'axios', 'firebase', 'gql-query-builder'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global["ts-custom-error"], global.axios, global.firebase, global["gql-query-builder"]));
5
- })(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, tsCustomError, axios, firebase, gqlQueryBuilder) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('ts-custom-error'), require('axios'), require('firebase'), require('gql-query-builder'), require('node-fetch')) :
3
+ typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'ts-custom-error', 'axios', 'firebase', 'gql-query-builder', 'node-fetch'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global["ts-custom-error"], global.axios, global.firebase, global["gql-query-builder"], global["node-fetch"]));
5
+ })(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, tsCustomError, axios, firebase, gqlQueryBuilder, fetch) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
10
10
  var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
11
+ var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
11
12
 
12
13
  var BaseModel = /** @class */ (function () {
13
14
  function BaseModel(args) {
@@ -289,7 +290,7 @@
289
290
  Status["CANCELLED"] = "Cancelado";
290
291
  })(exports.Status || (exports.Status = {}));
291
292
 
292
- /******************************************************************************
293
+ /*! *****************************************************************************
293
294
  Copyright (c) Microsoft Corporation.
294
295
 
295
296
  Permission to use, copy, modify, and/or distribute this software for any
@@ -356,64 +357,6 @@
356
357
  function __param(paramIndex, decorator) {
357
358
  return function (target, key) { decorator(target, key, paramIndex); };
358
359
  }
359
- function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
360
- function accept(f) { if (f !== void 0 && typeof f !== "function")
361
- throw new TypeError("Function expected"); return f; }
362
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
363
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
364
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
365
- var _, done = false;
366
- for (var i = decorators.length - 1; i >= 0; i--) {
367
- var context = {};
368
- for (var p in contextIn)
369
- context[p] = p === "access" ? {} : contextIn[p];
370
- for (var p in contextIn.access)
371
- context.access[p] = contextIn.access[p];
372
- context.addInitializer = function (f) { if (done)
373
- throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
374
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
375
- if (kind === "accessor") {
376
- if (result === void 0)
377
- continue;
378
- if (result === null || typeof result !== "object")
379
- throw new TypeError("Object expected");
380
- if (_ = accept(result.get))
381
- descriptor.get = _;
382
- if (_ = accept(result.set))
383
- descriptor.set = _;
384
- if (_ = accept(result.init))
385
- initializers.push(_);
386
- }
387
- else if (_ = accept(result)) {
388
- if (kind === "field")
389
- initializers.push(_);
390
- else
391
- descriptor[key] = _;
392
- }
393
- }
394
- if (target)
395
- Object.defineProperty(target, contextIn.name, descriptor);
396
- done = true;
397
- }
398
- ;
399
- function __runInitializers(thisArg, initializers, value) {
400
- var useValue = arguments.length > 2;
401
- for (var i = 0; i < initializers.length; i++) {
402
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
403
- }
404
- return useValue ? value : void 0;
405
- }
406
- ;
407
- function __propKey(x) {
408
- return typeof x === "symbol" ? x : "".concat(x);
409
- }
410
- ;
411
- function __setFunctionName(f, name, prefix) {
412
- if (typeof name === "symbol")
413
- name = name.description ? "[".concat(name.description, "]") : "";
414
- return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
415
- }
416
- ;
417
360
  function __metadata(metadataKey, metadataValue) {
418
361
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
419
362
  return Reflect.metadata(metadataKey, metadataValue);
@@ -445,7 +388,7 @@
445
388
  function step(op) {
446
389
  if (f)
447
390
  throw new TypeError("Generator is already executing.");
448
- while (g && (g = 0, op[0] && (_ = 0)), _)
391
+ while (_)
449
392
  try {
450
393
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
451
394
  return t;
@@ -509,11 +452,7 @@
509
452
  var __createBinding = Object.create ? (function (o, m, k, k2) {
510
453
  if (k2 === undefined)
511
454
  k2 = k;
512
- var desc = Object.getOwnPropertyDescriptor(m, k);
513
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
514
- desc = { enumerable: true, get: function () { return m[k]; } };
515
- }
516
- Object.defineProperty(o, k2, desc);
455
+ Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
517
456
  }) : (function (o, m, k, k2) {
518
457
  if (k2 === undefined)
519
458
  k2 = k;
@@ -613,7 +552,7 @@
613
552
  function __asyncDelegator(o) {
614
553
  var i, p;
615
554
  return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
616
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
555
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
617
556
  }
618
557
  function __asyncValues(o) {
619
558
  if (!Symbol.asyncIterator)
@@ -667,11 +606,6 @@
667
606
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
668
607
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
669
608
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
670
- }
671
- function __classPrivateFieldIn(state, receiver) {
672
- if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
673
- throw new TypeError("Cannot use 'in' operator on non-object");
674
- return typeof state === "function" ? receiver === state : state.has(receiver);
675
609
  }
676
610
 
677
611
  var Edition = /** @class */ (function (_super) {
@@ -1531,8 +1465,8 @@
1531
1465
  OrderStatus["EM_PREPARO"] = "Preparando pedido";
1532
1466
  OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
1533
1467
  OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
1534
- OrderStatus["ENVIADO"] = "Enviado";
1535
- OrderStatus["ENTREGUE"] = "Entregue";
1468
+ OrderStatus["ENVIADO"] = "Pedido Enviado";
1469
+ OrderStatus["ENTREGUE"] = "Pedido entregue";
1536
1470
  OrderStatus["CANCELADO"] = "Cancelado";
1537
1471
  OrderStatus["CREDIT_CARD"] = "credit_card";
1538
1472
  })(exports.OrderStatus || (exports.OrderStatus = {}));
@@ -1961,30 +1895,6 @@
1961
1895
  }());
1962
1896
 
1963
1897
  var withFirestore = function (MixinBase) {
1964
- var isObjectsAndNoDate = function (data) { return data &&
1965
- !Array.isArray(data) &&
1966
- typeof data === 'object' &&
1967
- (data === null || data === void 0 ? void 0 : data.constructor.name) !== 'Timestamp' &&
1968
- !('seconds' in data); };
1969
- var bindDate = function (data, keyName) {
1970
- if ((data === null || data === void 0 ? void 0 : data.constructor.name) === 'Timestamp')
1971
- return data.toDate();
1972
- if (data && typeof data === 'object' && 'seconds' in data)
1973
- return new Date(data.seconds * 1000);
1974
- if (typeof data === 'number' && ['createdAt', 'updatedAt'].includes(keyName))
1975
- return new Date(data);
1976
- return data;
1977
- };
1978
- var bindAllDateFromObject = function (data) {
1979
- return Object.keys(data).reduce(function (object, key) {
1980
- var _a;
1981
- return (Object.assign(Object.assign({}, object), (_a = {}, _a[key] = isObjectsAndNoDate(data[key])
1982
- ? bindAllDateFromObject(data[key])
1983
- : Array.isArray(data[key])
1984
- ? data[key].map(function (element) { return (isObjectsAndNoDate(element) ? bindAllDateFromObject(element) : element); })
1985
- : bindDate(data[key], key), _a)));
1986
- }, {});
1987
- };
1988
1898
  return /** @class */ (function (_super) {
1989
1899
  __extends(class_1, _super);
1990
1900
  function class_1() {
@@ -1999,18 +1909,12 @@
1999
1909
  toFirestore: function (data) { return ((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data); },
2000
1910
  fromFirestore: function (snap) {
2001
1911
  var data = snap.data();
2002
- var bindedData;
2003
- try {
2004
- var ids = { id: snap.id };
2005
- bindedData = bindAllDateFromObject(data);
2006
- return _this.model.toInstance(Object.assign(Object.assign({}, bindedData), ids));
2007
- }
2008
- catch (error) {
2009
- console.info('id', snap.id);
2010
- console.info('data', JSON.stringify(bindedData));
2011
- console.error(error);
2012
- throw error;
2013
- }
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 }));
2014
1918
  },
2015
1919
  };
2016
1920
  };
@@ -2072,16 +1976,6 @@
2072
1976
  }(MixinBase));
2073
1977
  };
2074
1978
 
2075
- var FirestoreFieldType;
2076
- (function (FirestoreFieldType) {
2077
- FirestoreFieldType["String"] = "string";
2078
- FirestoreFieldType["Number"] = "number";
2079
- FirestoreFieldType["Boolean"] = "boolean";
2080
- FirestoreFieldType["Timestamp"] = "timestamp";
2081
- FirestoreFieldType["Array"] = "array";
2082
- FirestoreFieldType["Map"] = "map";
2083
- })(FirestoreFieldType || (FirestoreFieldType = {}));
2084
-
2085
1979
  var withFindFirestore = function (MixinBase) {
2086
1980
  var checkIfIsFilterOption = function (filter) { return !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator); };
2087
1981
  var getValueFromFilter = function (filter) {
@@ -2106,16 +2000,13 @@
2106
2000
  ? fieldName.toString()
2107
2001
  : Object.keys(plainInstance).find(function (key) { return plainInstance[key]; });
2108
2002
  if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.LIKE) {
2109
- if (Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
2110
- (_this.fields[firestoreFieldName] === FirestoreFieldType.Array || !_this.fields[firestoreFieldName]))
2003
+ if (Array.isArray(options === null || options === void 0 ? void 0 : options.value))
2111
2004
  return queryReference.where(firestoreFieldName, 'array-contains-any', options.value);
2112
2005
  queryReference = queryReference.where(firestoreFieldName, '>=', options.value);
2113
2006
  queryReference = queryReference.where(firestoreFieldName, '<=', options.value + "~");
2114
2007
  return queryReference;
2115
2008
  }
2116
- if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.IN &&
2117
- Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
2118
- (_this.fields[firestoreFieldName] === FirestoreFieldType.Array || !_this.fields[firestoreFieldName]))
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))
2119
2010
  return queryReference.where(firestoreFieldName, 'array-contains', options.value);
2120
2011
  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)) {
2121
2012
  return Object.keys(options).reduce(function (queryReferenceWithWhere, key) { return _this.buildWhereSentence(queryReferenceWithWhere, fieldName.toString() + "." + key, options[key]); }, queryReference);
@@ -2124,37 +2015,35 @@
2124
2015
  };
2125
2016
  return _this;
2126
2017
  }
2127
- FindFirestore.prototype.find = function (_b) {
2128
- var _c = _b === void 0 ? {} : _b, filters = _c.filters, limits = _c.limits, orderBy = _c.orderBy, options = _c.options;
2129
- var _a;
2018
+ FindFirestore.prototype.find = function (_a) {
2019
+ var _b = _a === void 0 ? {} : _a, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
2130
2020
  return __awaiter(this, void 0, void 0, function () {
2131
- var orderByKeys, enableCount, query, filtersKeysWithUnordered, docs, data;
2132
- return __generator(this, function (_b) {
2133
- switch (_b.label) {
2021
+ var orderByKeys, query, filtersKeysWithUnordered, docs, data;
2022
+ return __generator(this, function (_a) {
2023
+ switch (_a.label) {
2134
2024
  case 0:
2135
2025
  orderByKeys = Object.keys(orderBy || {});
2136
- enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
2137
2026
  query = this.collection(this.buildCollectionPathForFind(filters || {}));
2138
2027
  query = this.makeFirestoreWhere(query, filters || {});
2139
2028
  if (orderByKeys.length) {
2140
2029
  filtersKeysWithUnordered = Object.keys(filters || {}).filter(function (filterKey) { return !orderByKeys.includes(filterKey); });
2141
2030
  if (filtersKeysWithUnordered.length)
2142
2031
  filtersKeysWithUnordered.forEach(function (filterKey) {
2143
- var _b;
2144
- return (orderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(filters[filterKey].operator) ? (_b = {}, _b[filterKey] = 'asc', _b) : {})), orderBy));
2032
+ var _a;
2033
+ return (orderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(filters[filterKey].operator) ? (_a = {}, _a[filterKey] = 'asc', _a) : {})), orderBy));
2145
2034
  });
2146
2035
  Object.keys(orderBy).forEach(function (fieldName) { return (query = query.orderBy(fieldName, orderBy[fieldName])); });
2147
2036
  }
2148
2037
  return [4 /*yield*/, this.defineLimits(query, filters, limits)];
2149
2038
  case 1:
2150
- query = _b.sent();
2039
+ query = _a.sent();
2151
2040
  return [4 /*yield*/, query.get()];
2152
2041
  case 2:
2153
- docs = _b.sent();
2042
+ docs = _a.sent();
2154
2043
  data = docs.docs.map(function (doc) { return doc.data(); });
2155
2044
  return [2 /*return*/, {
2156
2045
  data: data,
2157
- count: enableCount ? this.calculateCount(data, limits) : Infinity,
2046
+ count: this.calculateCount(data, limits),
2158
2047
  }];
2159
2048
  }
2160
2049
  });
@@ -2169,23 +2058,23 @@
2169
2058
  };
2170
2059
  FindFirestore.prototype.defineLimits = function (query, filters, limits) {
2171
2060
  return __awaiter(this, void 0, void 0, function () {
2172
- var _b, _c;
2173
- return __generator(this, function (_d) {
2174
- switch (_d.label) {
2061
+ var _a, _b;
2062
+ return __generator(this, function (_c) {
2063
+ switch (_c.label) {
2175
2064
  case 0:
2176
2065
  if (!(limits === null || limits === void 0 ? void 0 : limits.offset)) return [3 /*break*/, 3];
2177
2066
  if (!this.model.isModel(limits.offset)) return [3 /*break*/, 2];
2178
- _c = (_b = query).startAfter;
2067
+ _b = (_a = query).startAfter;
2179
2068
  return [4 /*yield*/, this.collection(this.buildCollectionPathForFind(filters))
2180
2069
  .doc(limits.offset[limits.offset.identifiersFields.shift()])
2181
2070
  .get()];
2182
2071
  case 1:
2183
- query = _c.apply(_b, [_d.sent()]);
2072
+ query = _b.apply(_a, [_c.sent()]);
2184
2073
  return [3 /*break*/, 3];
2185
2074
  case 2:
2186
2075
  if (lodash.isNumber(limits.offset) || lodash.isString(limits.offset))
2187
2076
  query = query.startAt(limits.offset);
2188
- _d.label = 3;
2077
+ _c.label = 3;
2189
2078
  case 3:
2190
2079
  if (limits === null || limits === void 0 ? void 0 : limits.limit)
2191
2080
  query = query.limit(limits.limit);
@@ -2877,8 +2766,7 @@
2877
2766
  var _a;
2878
2767
  if (!!((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length)) {
2879
2768
  order.lineItems = order.lineItems.map(function (lineItem) {
2880
- var _a;
2881
- if (!!((_a = lineItem.price) === null || _a === void 0 ? void 0 : _a[order.shop])) {
2769
+ if (!!lineItem.price[order.shop]) {
2882
2770
  var shopPrice = lineItem['price'][order.shop];
2883
2771
  lineItem['price'] = shopPrice;
2884
2772
  }
@@ -2889,9 +2777,6 @@
2889
2777
  };
2890
2778
  _this.collectionName = 'orders';
2891
2779
  _this.model = Order;
2892
- _this.fields = {
2893
- status: FirestoreFieldType.String,
2894
- };
2895
2780
  return _this;
2896
2781
  }
2897
2782
  OrderFirestoreRepository.prototype.buildModelInstance = function () {
@@ -3529,19 +3414,21 @@
3529
3414
  };
3530
3415
  HasuraGraphQLMixin.prototype.fetch = function (params) {
3531
3416
  return __awaiter(this, void 0, void 0, function () {
3532
- var headers, result;
3417
+ var headers, response, result;
3533
3418
  return __generator(this, function (_a) {
3534
3419
  switch (_a.label) {
3535
3420
  case 0:
3536
3421
  headers = this.headers;
3537
- return [4 /*yield*/, axios__default["default"]({
3538
- url: "" + this.endpoint,
3422
+ return [4 /*yield*/, fetch__default["default"]("" + this.endpoint, {
3539
3423
  method: 'POST',
3540
- data: params,
3424
+ body: JSON.stringify(params),
3541
3425
  headers: headers,
3542
3426
  })];
3543
3427
  case 1:
3544
- result = (_a.sent()).data;
3428
+ response = _a.sent();
3429
+ return [4 /*yield*/, response.json()];
3430
+ case 2:
3431
+ result = _a.sent();
3545
3432
  if (!lodash.isNil(result.errors))
3546
3433
  throw new Error(JSON.stringify(result.errors));
3547
3434
  return [2 /*return*/, result.data];
@@ -3713,16 +3600,14 @@
3713
3600
  function FindHasuraGraphQLMixin() {
3714
3601
  return _super !== null && _super.apply(this, arguments) || this;
3715
3602
  }
3716
- FindHasuraGraphQLMixin.prototype.find = function (params) {
3717
- var _a;
3603
+ FindHasuraGraphQLMixin.prototype.find = function (options) {
3718
3604
  return __awaiter(this, void 0, void 0, function () {
3719
- var _b, filters, limits, orderBy, options, enableCount, variablesCount, variables, result, data;
3605
+ var _b, filters, limits, orderBy, variablesCount, variables, result, data, count;
3720
3606
  var _this = this;
3721
3607
  return __generator(this, function (_c) {
3722
3608
  switch (_c.label) {
3723
3609
  case 0:
3724
- _b = params || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy, options = _b.options;
3725
- enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
3610
+ _b = options || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
3726
3611
  variablesCount = Object.assign(Object.assign({}, (lodash.isNil(orderBy) ? {} : { order_by: { type: this.tableName + "_order_by!", list: true, value: orderBy } })), (lodash.isNil(filters)
3727
3612
  ? {}
3728
3613
  : {
@@ -3733,11 +3618,11 @@
3733
3618
  },
3734
3619
  }));
3735
3620
  variables = Object.assign(Object.assign({}, (lodash.isNil(limits) ? {} : limits)), variablesCount);
3736
- return [4 /*yield*/, this.query(__spreadArray([
3621
+ return [4 /*yield*/, this.query([
3737
3622
  {
3738
3623
  operation: this.tableName,
3739
- fields: params.fields
3740
- ? params.fields
3624
+ fields: options.fields
3625
+ ? options.fields
3741
3626
  .map(function (fieldName) {
3742
3627
  var _a;
3743
3628
  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; });
@@ -3745,20 +3630,18 @@
3745
3630
  .filter(Boolean)
3746
3631
  : this.fields,
3747
3632
  variables: variables,
3748
- }
3749
- ], __read((enableCount
3750
- ? [
3751
- {
3752
- operation: this.tableName + "_aggregate",
3753
- fields: [{ aggregate: ['count'] }],
3754
- variables: variablesCount,
3755
- },
3756
- ]
3757
- : []))))];
3633
+ },
3634
+ {
3635
+ operation: this.tableName + "_aggregate",
3636
+ fields: [{ aggregate: ['count'] }],
3637
+ variables: variablesCount,
3638
+ },
3639
+ ])];
3758
3640
  case 1:
3759
3641
  result = _c.sent();
3760
3642
  data = result[this.tableName].map(function (row) { return _this.convertDataFromHasura(row); });
3761
- return [2 /*return*/, { data: data, count: enableCount ? result[this.tableName + "_aggregate"].aggregate.count : Infinity }];
3643
+ count = result[this.tableName + "_aggregate"].aggregate.count;
3644
+ return [2 /*return*/, { count: count, data: data }];
3762
3645
  }
3763
3646
  });
3764
3647
  });
@@ -3912,7 +3795,7 @@
3912
3795
  switch (_d.label) {
3913
3796
  case 0:
3914
3797
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3915
- return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })];
3798
+ return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3916
3799
  case 1:
3917
3800
  _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3918
3801
  return [3 /*break*/, 3];
@@ -3966,19 +3849,19 @@
3966
3849
  };
3967
3850
  CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
3968
3851
  return __awaiter(this, void 0, void 0, function () {
3969
- var data;
3970
- return __generator(this, function (_c) {
3971
- switch (_c.label) {
3852
+ var _c, data, count;
3853
+ return __generator(this, function (_d) {
3854
+ switch (_d.label) {
3972
3855
  case 0:
3973
3856
  if (!slug)
3974
3857
  return [2 /*return*/];
3975
- return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true }, options: { enableCount: false } })];
3858
+ return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
3976
3859
  case 1:
3977
- data = (_c.sent()).data;
3978
- if (!data.length)
3979
- throw new NotFoundError("Category with slug " + slug + " not found");
3980
- if (data.length > 1)
3860
+ _c = _d.sent(), data = _c.data, count = _c.count;
3861
+ if (count > 1)
3981
3862
  throw new DuplicatedResultsError('Query returned duplicated values');
3863
+ if (!count)
3864
+ throw new NotFoundError("Category with slug " + slug + " not found");
3982
3865
  return [2 /*return*/, data.shift()];
3983
3866
  }
3984
3867
  });
@@ -3987,46 +3870,17 @@
3987
3870
  CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
3988
3871
  if (limit === void 0) { limit = 4; }
3989
3872
  return __awaiter(this, void 0, void 0, function () {
3990
- var categoriesFirestore, categoriesHasura, categories, _c, _d, _e, _f, _g, _h, _j, _k, homeSections;
3873
+ var _c, categories, count, homeSections;
3991
3874
  var _this = this;
3992
- return __generator(this, function (_l) {
3993
- switch (_l.label) {
3994
- case 0:
3995
- if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
3996
- return [2 /*return*/, []];
3997
- categoriesFirestore = categoryIds.filter(function (categoryId) { return Number.isNaN(+categoryId); });
3998
- categoriesHasura = categoryIds.filter(function (categoryId) { return +categoryId > 0; });
3999
- categories = [];
4000
- if (!categoriesFirestore.length) return [3 /*break*/, 2];
4001
- _d = (_c = categories.push).apply;
4002
- _e = [categories];
4003
- _f = [[]];
4004
- return [4 /*yield*/, this.find({
4005
- filters: { firestoreId: { operator: exports.Where.IN, value: categoriesFirestore.filter(Boolean) }, published: true },
4006
- }).then(function (_c) {
4007
- var data = _c.data;
4008
- return data;
4009
- })];
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
+ })];
4010
3880
  case 1:
4011
- _d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_l.sent())])]))]));
4012
- _l.label = 2;
4013
- case 2:
4014
- if (!categoriesHasura.length) return [3 /*break*/, 4];
4015
- _h = (_g = categories.push).apply;
4016
- _j = [categories];
4017
- _k = [[]];
4018
- return [4 /*yield*/, this.find({
4019
- filters: { id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) }, published: true },
4020
- }).then(function (_c) {
4021
- var data = _c.data;
4022
- return data;
4023
- })];
4024
- case 3:
4025
- _h.apply(_g, _j.concat([__spreadArray.apply(void 0, _k.concat([__read.apply(void 0, [(_l.sent())])]))]));
4026
- _l.label = 4;
4027
- case 4:
4028
- if (!categories.length)
4029
- return [2 /*return*/, []];
3881
+ _c = _d.sent(), categories = _c.data, count = _c.count;
3882
+ if (!count)
3883
+ throw new NotFoundError('Categories not found');
4030
3884
  return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
4031
3885
  var _c;
4032
3886
  return __generator(this, function (_d) {
@@ -4041,24 +3895,23 @@
4041
3895
  }
4042
3896
  });
4043
3897
  }); }))];
4044
- case 5:
4045
- homeSections = _l.sent();
3898
+ case 2:
3899
+ homeSections = _d.sent();
4046
3900
  return [2 /*return*/, homeSections];
4047
3901
  }
4048
3902
  });
4049
3903
  });
4050
3904
  };
4051
3905
  CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
4052
- var _a;
4053
3906
  return __awaiter(this, void 0, void 0, function () {
4054
3907
  var products, productsData;
4055
3908
  return __generator(this, function (_c) {
4056
3909
  switch (_c.label) {
4057
3910
  case 0:
4058
- if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
4059
- return [2 /*return*/, []];
3911
+ if (!category.products)
3912
+ throw new RequiredArgumentError(['Category products is empty']);
4060
3913
  products = [];
4061
- 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: [
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: [
4062
3915
  'id',
4063
3916
  'name',
4064
3917
  'slug',
@@ -4082,7 +3935,7 @@
4082
3935
  'tags',
4083
3936
  'type',
4084
3937
  'shoppingCount',
4085
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }))];
3938
+ ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
4086
3939
  case 1:
4087
3940
  productsData = (_c.sent()).data;
4088
3941
  products.push.apply(products, __spreadArray([], __read(productsData)));
@@ -4100,7 +3953,7 @@
4100
3953
  case 0:
4101
3954
  if (!Number.isNaN(+id))
4102
3955
  return [2 /*return*/, id];
4103
- return [4 /*yield*/, this.find({ filters: { firestoreId: id }, options: { enableCount: false } })];
3956
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4104
3957
  case 1:
4105
3958
  data = (_c.sent()).data;
4106
3959
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
@@ -4420,7 +4273,7 @@
4420
4273
  switch (_f.label) {
4421
4274
  case 0:
4422
4275
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
4423
- return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })];
4276
+ return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
4424
4277
  case 1:
4425
4278
  _c = (_a = (_f.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
4426
4279
  return [3 /*break*/, 4];
@@ -4465,21 +4318,21 @@
4465
4318
  ProductHasuraGraphQLRepository.prototype.getBySlug = function (slug) {
4466
4319
  var _a;
4467
4320
  return __awaiter(this, void 0, void 0, function () {
4468
- var result, product;
4469
- return __generator(this, function (_c) {
4470
- switch (_c.label) {
4321
+ var result, product, _c;
4322
+ return __generator(this, function (_d) {
4323
+ switch (_d.label) {
4471
4324
  case 0: return [4 /*yield*/, this.find({
4472
4325
  filters: {
4473
4326
  slug: slug,
4474
4327
  },
4475
- fields: this.fields.map(function (field) { return typeof field === 'string' ? field : Object.keys(field).shift(); }),
4476
- options: {
4477
- enableCount: false,
4478
- },
4479
4328
  })];
4480
4329
  case 1:
4481
- result = _c.sent();
4330
+ result = _d.sent();
4482
4331
  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();
4483
4336
  return [2 /*return*/, product];
4484
4337
  }
4485
4338
  });
@@ -4760,7 +4613,7 @@
4760
4613
  case 0:
4761
4614
  if (!Number.isNaN(+id))
4762
4615
  return [2 /*return*/, id];
4763
- return [4 /*yield*/, this.find({ filters: { firestoreId: id }, options: { enableCount: false } })];
4616
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4764
4617
  case 1:
4765
4618
  data = (_c.sent()).data;
4766
4619
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
@@ -4990,7 +4843,7 @@
4990
4843
  case 0:
4991
4844
  if (!Number.isNaN(+id))
4992
4845
  return [2 /*return*/, id];
4993
- return [4 /*yield*/, this.find({ filters: { firestoreId: id }, options: { enableCount: false } })];
4846
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4994
4847
  case 1:
4995
4848
  data = (_c.sent()).data;
4996
4849
  if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)