@infrab4a/connect 2.0.4 → 2.0.7

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.
@@ -3707,34 +3707,65 @@
3707
3707
  });
3708
3708
  var _a;
3709
3709
  return __awaiter(this, void 0, void 0, function () {
3710
- var _b;
3711
- return __generator(this, function (_c) {
3712
- switch (_c.label) {
3710
+ var _c;
3711
+ return __generator(this, function (_d) {
3712
+ switch (_d.label) {
3713
3713
  case 0:
3714
3714
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3715
3715
  return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3716
3716
  case 1:
3717
- _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];
3718
3718
  return [3 /*break*/, 3];
3719
3719
  case 2:
3720
- _b = _super.get.call(this, identifiers);
3721
- _c.label = 3;
3722
- 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];
3723
3754
  }
3724
3755
  });
3725
3756
  });
3726
3757
  };
3727
3758
  CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
3728
3759
  return __awaiter(this, void 0, void 0, function () {
3729
- var _b, data, count;
3730
- return __generator(this, function (_c) {
3731
- switch (_c.label) {
3760
+ var _c, data, count;
3761
+ return __generator(this, function (_d) {
3762
+ switch (_d.label) {
3732
3763
  case 0:
3733
3764
  if (!slug)
3734
3765
  return [2 /*return*/];
3735
3766
  return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
3736
3767
  case 1:
3737
- _b = _c.sent(), data = _b.data, count = _b.count;
3768
+ _c = _d.sent(), data = _c.data, count = _c.count;
3738
3769
  if (count > 1)
3739
3770
  throw new DuplicatedResultsError('Query returned duplicated values');
3740
3771
  if (!count)
@@ -3747,33 +3778,33 @@
3747
3778
  CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
3748
3779
  if (limit === void 0) { limit = 4; }
3749
3780
  return __awaiter(this, void 0, void 0, function () {
3750
- var _b, categories, count, homeSections;
3781
+ var _c, categories, count, homeSections;
3751
3782
  var _this = this;
3752
- return __generator(this, function (_c) {
3753
- switch (_c.label) {
3783
+ return __generator(this, function (_d) {
3784
+ switch (_d.label) {
3754
3785
  case 0: return [4 /*yield*/, this.find({
3755
3786
  filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
3756
3787
  })];
3757
3788
  case 1:
3758
- _b = _c.sent(), categories = _b.data, count = _b.count;
3789
+ _c = _d.sent(), categories = _c.data, count = _c.count;
3759
3790
  if (!count)
3760
3791
  throw new NotFoundError('Categories not found');
3761
3792
  return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
3762
- var _b;
3763
- return __generator(this, function (_c) {
3764
- switch (_c.label) {
3793
+ var _c;
3794
+ return __generator(this, function (_d) {
3795
+ switch (_d.label) {
3765
3796
  case 0:
3766
- _b = {
3797
+ _c = {
3767
3798
  category: category
3768
3799
  };
3769
3800
  return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
3770
- case 1: return [2 /*return*/, (_b.products = _c.sent(),
3771
- _b)];
3801
+ case 1: return [2 /*return*/, (_c.products = _d.sent(),
3802
+ _c)];
3772
3803
  }
3773
3804
  });
3774
3805
  }); }))];
3775
3806
  case 2:
3776
- homeSections = _c.sent();
3807
+ homeSections = _d.sent();
3777
3808
  return [2 /*return*/, homeSections];
3778
3809
  }
3779
3810
  });
@@ -3782,15 +3813,15 @@
3782
3813
  CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
3783
3814
  return __awaiter(this, void 0, void 0, function () {
3784
3815
  var products, publishedField, productsData;
3785
- var _b;
3786
- return __generator(this, function (_c) {
3787
- switch (_c.label) {
3816
+ var _c;
3817
+ return __generator(this, function (_d) {
3818
+ switch (_d.label) {
3788
3819
  case 0:
3789
3820
  if (!category.products)
3790
3821
  throw new RequiredArgumentError(['Category products is empty']);
3791
3822
  products = [];
3792
3823
  publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
3793
- 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: [
3794
3825
  'id',
3795
3826
  'name',
3796
3827
  'slug',
@@ -3816,13 +3847,63 @@
3816
3847
  'tags',
3817
3848
  ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
3818
3849
  case 1:
3819
- productsData = (_c.sent()).data;
3850
+ productsData = (_d.sent()).data;
3820
3851
  products.push.apply(products, __spreadArray([], __read(productsData)));
3821
3852
  return [2 /*return*/, products];
3822
3853
  }
3823
3854
  });
3824
3855
  });
3825
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
+ plainData = this.paramsToPlain({ products: products });
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 [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
3894
+ objects: {
3895
+ type: '[category_product_insert_input!]',
3896
+ required: true,
3897
+ value: plainData.products.map(function (productId) { return ({ category_id: categoryId, product_id: productId }); }),
3898
+ },
3899
+ })];
3900
+ case 2:
3901
+ _c.sent();
3902
+ return [2 /*return*/, plainData.products];
3903
+ }
3904
+ });
3905
+ });
3906
+ };
3826
3907
  return CategoryHasuraGraphQLRepository;
3827
3908
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3828
3909