@infrab4a/connect 2.0.6 → 2.0.8

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.
@@ -48,6 +48,7 @@
48
48
  exports.Where = void 0;
49
49
  (function (Where) {
50
50
  Where["EQUALS"] = "==";
51
+ Where["NOTEQUALS"] = "!=";
51
52
  Where["GT"] = ">";
52
53
  Where["GTE"] = ">=";
53
54
  Where["IN"] = "in";
@@ -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
@@ -387,7 +388,7 @@
387
388
  function step(op) {
388
389
  if (f)
389
390
  throw new TypeError("Generator is already executing.");
390
- while (g && (g = 0, op[0] && (_ = 0)), _)
391
+ while (_)
391
392
  try {
392
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)
393
394
  return t;
@@ -451,11 +452,7 @@
451
452
  var __createBinding = Object.create ? (function (o, m, k, k2) {
452
453
  if (k2 === undefined)
453
454
  k2 = k;
454
- var desc = Object.getOwnPropertyDescriptor(m, k);
455
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
456
- desc = { enumerable: true, get: function () { return m[k]; } };
457
- }
458
- Object.defineProperty(o, k2, desc);
455
+ Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
459
456
  }) : (function (o, m, k, k2) {
460
457
  if (k2 === undefined)
461
458
  k2 = k;
@@ -610,11 +607,6 @@
610
607
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
611
608
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
612
609
  }
613
- function __classPrivateFieldIn(state, receiver) {
614
- if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
615
- throw new TypeError("Cannot use 'in' operator on non-object");
616
- return typeof state === "function" ? receiver === state : state.has(receiver);
617
- }
618
610
 
619
611
  var Edition = /** @class */ (function (_super) {
620
612
  __extends(Edition, _super);
@@ -3715,34 +3707,65 @@
3715
3707
  });
3716
3708
  var _a;
3717
3709
  return __awaiter(this, void 0, void 0, function () {
3718
- var _b;
3719
- return __generator(this, function (_c) {
3720
- switch (_c.label) {
3710
+ var _c;
3711
+ return __generator(this, function (_d) {
3712
+ switch (_d.label) {
3721
3713
  case 0:
3722
3714
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3723
3715
  return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3724
3716
  case 1:
3725
- _b = (_a = (_c.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3717
+ _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3726
3718
  return [3 /*break*/, 3];
3727
3719
  case 2:
3728
- _b = _super.get.call(this, identifiers);
3729
- _c.label = 3;
3730
- case 3: return [2 /*return*/, _b];
3720
+ _c = _super.get.call(this, identifiers);
3721
+ _d.label = 3;
3722
+ case 3: return [2 /*return*/, _c];
3723
+ }
3724
+ });
3725
+ });
3726
+ };
3727
+ CategoryHasuraGraphQLRepository.prototype.update = function (params) {
3728
+ var _super = Object.create(null, {
3729
+ update: { get: function () { return _super_1.prototype.update; } }
3730
+ });
3731
+ return __awaiter(this, void 0, void 0, function () {
3732
+ var products, checkId, data, plainData, id, category, _c, _d;
3733
+ return __generator(this, function (_e) {
3734
+ switch (_e.label) {
3735
+ case 0:
3736
+ products = params.products, checkId = params.id, data = __rest(params, ["products", "id"]);
3737
+ plainData = this.paramsToPlain({ id: checkId });
3738
+ return [4 /*yield*/, this.getId(plainData.id)];
3739
+ case 1:
3740
+ id = _e.sent();
3741
+ return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
3742
+ case 2:
3743
+ category = _e.sent();
3744
+ _c = category;
3745
+ _d = products;
3746
+ if (!_d) return [3 /*break*/, 4];
3747
+ return [4 /*yield*/, this.updateProducts(+id, { products: products })];
3748
+ case 3:
3749
+ _d = (_e.sent());
3750
+ _e.label = 4;
3751
+ case 4:
3752
+ _c.products = _d;
3753
+ return [2 /*return*/, category];
3731
3754
  }
3732
3755
  });
3733
3756
  });
3734
3757
  };
3735
3758
  CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
3736
3759
  return __awaiter(this, void 0, void 0, function () {
3737
- var _b, data, count;
3738
- return __generator(this, function (_c) {
3739
- switch (_c.label) {
3760
+ var _c, data, count;
3761
+ return __generator(this, function (_d) {
3762
+ switch (_d.label) {
3740
3763
  case 0:
3741
3764
  if (!slug)
3742
3765
  return [2 /*return*/];
3743
3766
  return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
3744
3767
  case 1:
3745
- _b = _c.sent(), data = _b.data, count = _b.count;
3768
+ _c = _d.sent(), data = _c.data, count = _c.count;
3746
3769
  if (count > 1)
3747
3770
  throw new DuplicatedResultsError('Query returned duplicated values');
3748
3771
  if (!count)
@@ -3755,33 +3778,33 @@
3755
3778
  CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
3756
3779
  if (limit === void 0) { limit = 4; }
3757
3780
  return __awaiter(this, void 0, void 0, function () {
3758
- var _b, categories, count, homeSections;
3781
+ var _c, categories, count, homeSections;
3759
3782
  var _this = this;
3760
- return __generator(this, function (_c) {
3761
- switch (_c.label) {
3783
+ return __generator(this, function (_d) {
3784
+ switch (_d.label) {
3762
3785
  case 0: return [4 /*yield*/, this.find({
3763
3786
  filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
3764
3787
  })];
3765
3788
  case 1:
3766
- _b = _c.sent(), categories = _b.data, count = _b.count;
3789
+ _c = _d.sent(), categories = _c.data, count = _c.count;
3767
3790
  if (!count)
3768
3791
  throw new NotFoundError('Categories not found');
3769
3792
  return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
3770
- var _b;
3771
- return __generator(this, function (_c) {
3772
- switch (_c.label) {
3793
+ var _c;
3794
+ return __generator(this, function (_d) {
3795
+ switch (_d.label) {
3773
3796
  case 0:
3774
- _b = {
3797
+ _c = {
3775
3798
  category: category
3776
3799
  };
3777
3800
  return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
3778
- case 1: return [2 /*return*/, (_b.products = _c.sent(),
3779
- _b)];
3801
+ case 1: return [2 /*return*/, (_c.products = _d.sent(),
3802
+ _c)];
3780
3803
  }
3781
3804
  });
3782
3805
  }); }))];
3783
3806
  case 2:
3784
- homeSections = _c.sent();
3807
+ homeSections = _d.sent();
3785
3808
  return [2 /*return*/, homeSections];
3786
3809
  }
3787
3810
  });
@@ -3790,15 +3813,15 @@
3790
3813
  CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
3791
3814
  return __awaiter(this, void 0, void 0, function () {
3792
3815
  var products, publishedField, productsData;
3793
- var _b;
3794
- return __generator(this, function (_c) {
3795
- switch (_c.label) {
3816
+ var _c;
3817
+ return __generator(this, function (_d) {
3818
+ switch (_d.label) {
3796
3819
  case 0:
3797
3820
  if (!category.products)
3798
3821
  throw new RequiredArgumentError(['Category products is empty']);
3799
3822
  products = [];
3800
3823
  publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
3801
- return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign((_b = { id: { operator: exports.Where.IN, value: category.products } }, _b[publishedField] = true, _b), ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3824
+ return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign((_c = { id: { operator: exports.Where.IN, value: category.products } }, _c[publishedField] = true, _c), ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3802
3825
  'id',
3803
3826
  'name',
3804
3827
  'slug',
@@ -3821,15 +3844,80 @@
3821
3844
  'shopAvailability',
3822
3845
  'sku',
3823
3846
  'rate',
3847
+ 'tags',
3824
3848
  ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
3825
3849
  case 1:
3826
- productsData = (_c.sent()).data;
3850
+ productsData = (_d.sent()).data;
3827
3851
  products.push.apply(products, __spreadArray([], __read(productsData)));
3828
3852
  return [2 /*return*/, products];
3829
3853
  }
3830
3854
  });
3831
3855
  });
3832
3856
  };
3857
+ CategoryHasuraGraphQLRepository.prototype.getId = function (id) {
3858
+ var _a, _b;
3859
+ return __awaiter(this, void 0, void 0, function () {
3860
+ var data;
3861
+ return __generator(this, function (_c) {
3862
+ switch (_c.label) {
3863
+ case 0:
3864
+ if (!Number.isNaN(+id))
3865
+ return [2 /*return*/, id];
3866
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
3867
+ case 1:
3868
+ data = (_c.sent()).data;
3869
+ if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
3870
+ return [2 /*return*/, (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id];
3871
+ throw new NotFoundError("Category with id " + id + " not found");
3872
+ }
3873
+ });
3874
+ });
3875
+ };
3876
+ CategoryHasuraGraphQLRepository.prototype.updateProducts = function (categoryId, _c) {
3877
+ var products = _c.products;
3878
+ return __awaiter(this, void 0, void 0, function () {
3879
+ var plainData;
3880
+ return __generator(this, function (_c) {
3881
+ switch (_c.label) {
3882
+ case 0:
3883
+ if (!('action' in products && products.action === 'remove')) return [3 /*break*/, 2];
3884
+ return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
3885
+ where: {
3886
+ type: 'category_product_bool_exp',
3887
+ required: true,
3888
+ value: { category_id: { _eq: categoryId } },
3889
+ },
3890
+ })];
3891
+ case 1:
3892
+ _c.sent();
3893
+ return [2 /*return*/, []];
3894
+ case 2:
3895
+ plainData = this.paramsToPlain({ products: products });
3896
+ if (!plainData.products || plainData.products.length <= 0)
3897
+ return [2 /*return*/, []];
3898
+ return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
3899
+ where: {
3900
+ type: 'category_product_bool_exp',
3901
+ required: true,
3902
+ value: { category_id: { _eq: categoryId } },
3903
+ },
3904
+ })];
3905
+ case 3:
3906
+ _c.sent();
3907
+ return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
3908
+ objects: {
3909
+ type: '[category_product_insert_input!]',
3910
+ required: true,
3911
+ value: plainData.products.map(function (productId) { return ({ category_id: categoryId, product_id: productId }); }),
3912
+ },
3913
+ })];
3914
+ case 4:
3915
+ _c.sent();
3916
+ return [2 /*return*/, plainData.products];
3917
+ }
3918
+ });
3919
+ });
3920
+ };
3833
3921
  return CategoryHasuraGraphQLRepository;
3834
3922
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3835
3923
 
@@ -4162,7 +4250,7 @@
4162
4250
  return __generator(this, function (_c) {
4163
4251
  switch (_c.label) {
4164
4252
  case 0:
4165
- plainData = this.paramsToPlain({ categories: categories });
4253
+ if (!('action' in categories && categories.action === 'remove')) return [3 /*break*/, 2];
4166
4254
  return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
4167
4255
  where: {
4168
4256
  type: 'category_product_bool_exp',
@@ -4171,6 +4259,20 @@
4171
4259
  },
4172
4260
  })];
4173
4261
  case 1:
4262
+ _c.sent();
4263
+ return [2 /*return*/, []];
4264
+ case 2:
4265
+ plainData = this.paramsToPlain({ categories: categories });
4266
+ if (!plainData.categories || plainData.categories.length <= 0)
4267
+ return [2 /*return*/, []];
4268
+ return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
4269
+ where: {
4270
+ type: 'category_product_bool_exp',
4271
+ required: true,
4272
+ value: { product_id: { _eq: productId } },
4273
+ },
4274
+ })];
4275
+ case 3:
4174
4276
  _c.sent();
4175
4277
  return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
4176
4278
  objects: {
@@ -4179,7 +4281,7 @@
4179
4281
  value: plainData.categories.map(function (categoryId) { return ({ category_id: categoryId, product_id: productId }); }),
4180
4282
  },
4181
4283
  })];
4182
- case 2:
4284
+ case 4:
4183
4285
  _c.sent();
4184
4286
  return [2 /*return*/, plainData.categories];
4185
4287
  }
@@ -4229,8 +4331,6 @@
4229
4331
  return __generator(this, function (_c) {
4230
4332
  switch (_c.label) {
4231
4333
  case 0:
4232
- if (!reviews)
4233
- return [2 /*return*/, []];
4234
4334
  if (!('action' in reviews && reviews.action === 'remove')) return [3 /*break*/, 3];
4235
4335
  return [4 /*yield*/, Promise.all(reviews.value.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
4236
4336
  var review;
@@ -4253,6 +4353,8 @@
4253
4353
  return [2 /*return*/, reviews.value.map(function (review, index) { return !reviewIds_1[index] && review; }).filter(Boolean)];
4254
4354
  case 3:
4255
4355
  plainData = this.paramsToPlain({ reviews: reviews });
4356
+ if (!plainData.reviews || plainData.reviews.length <= 0)
4357
+ return [2 /*return*/, []];
4256
4358
  return [2 /*return*/, Promise.all(plainData.reviews.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
4257
4359
  var review, _c, _d;
4258
4360
  return __generator(this, function (_e) {