@infrab4a/connect 1.0.0-beta.13 → 1.0.0-beta.15

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.
@@ -3157,7 +3157,7 @@
3157
3157
  return params.toPlain();
3158
3158
  return Object.keys(params).reduce(function (data, currentKey) {
3159
3159
  var _a;
3160
- return (Object.assign(Object.assign({}, data), (_a = {}, _a[currentKey] = getValueByAction(params[currentKey]), _a)));
3160
+ return (Object.assign(Object.assign({}, data), (params[currentKey] && (_a = {}, _a[currentKey] = getValueByAction(params[currentKey]), _a))));
3161
3161
  }, {});
3162
3162
  };
3163
3163
  UpdateHasuraGraphQLMixin.prototype.getUpdateModelKeys = function (data) {
@@ -3568,8 +3568,8 @@
3568
3568
  description: {
3569
3569
  columnName: 'description',
3570
3570
  from: function (description) { return Object.values(exports.Shops).reduce(function (shops, shop) {
3571
- var _b;
3572
- return (Object.assign(Object.assign({}, shops), (_b = {}, _b[shop] = { description: description }, _b)));
3571
+ var _c;
3572
+ return (Object.assign(Object.assign({}, shops), (_c = {}, _c[shop] = { description: description }, _c)));
3573
3573
  }, {}); },
3574
3574
  to: function (value) { return Object.values(value).shift().description; },
3575
3575
  },
@@ -3582,13 +3582,13 @@
3582
3582
  price: {
3583
3583
  columnName: 'price',
3584
3584
  from: function (price, data) { return Object.values(exports.Shops).reduce(function (prices, shop) {
3585
- var _b;
3586
- return (Object.assign(Object.assign({}, prices), (_b = {}, _b[shop] = {
3585
+ var _c;
3586
+ return (Object.assign(Object.assign({}, prices), (_c = {}, _c[shop] = {
3587
3587
  price: price,
3588
3588
  fullPrice: data.full_price,
3589
3589
  subscriberDiscountPercentage: data.subscriber_discount_percentage,
3590
3590
  subscriberPrice: data.subscriber_price,
3591
- }, _b)));
3591
+ }, _c)));
3592
3592
  }, {}); },
3593
3593
  bindFindFilter: function (sentence) {
3594
3594
  var filters = Object.values(sentence).shift();
@@ -3614,7 +3614,7 @@
3614
3614
  stock: {
3615
3615
  columnName: 'stock',
3616
3616
  from: function (quantity) { return ({ quantity: quantity }); },
3617
- to: function (value) { return (value === null || value === void 0 ? void 0 : value.quantity) || value; },
3617
+ to: function (value) { return (lodash.isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity); },
3618
3618
  },
3619
3619
  },
3620
3620
  'slug',
@@ -3646,12 +3646,35 @@
3646
3646
  ],
3647
3647
  }) || this;
3648
3648
  }
3649
+ ProductHasuraGraphQLRepository.prototype.get = function (identifiers) {
3650
+ var _super = Object.create(null, {
3651
+ get: { get: function () { return _super_1.prototype.get; } }
3652
+ });
3653
+ var _a;
3654
+ return __awaiter(this, void 0, void 0, function () {
3655
+ var _c;
3656
+ return __generator(this, function (_d) {
3657
+ switch (_d.label) {
3658
+ case 0:
3659
+ if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3660
+ return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3661
+ case 1:
3662
+ _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3663
+ return [3 /*break*/, 3];
3664
+ case 2:
3665
+ _c = _super.get.call(this, identifiers);
3666
+ _d.label = 3;
3667
+ case 3: return [2 /*return*/, _c];
3668
+ }
3669
+ });
3670
+ });
3671
+ };
3649
3672
  ProductHasuraGraphQLRepository.prototype.getBySlug = function (slug, shop) {
3650
3673
  var _a;
3651
3674
  return __awaiter(this, void 0, void 0, function () {
3652
3675
  var result;
3653
- return __generator(this, function (_b) {
3654
- switch (_b.label) {
3676
+ return __generator(this, function (_c) {
3677
+ switch (_c.label) {
3655
3678
  case 0: return [4 /*yield*/, this.find({
3656
3679
  filters: {
3657
3680
  slug: { operator: exports.Where.EQUALS, value: slug },
@@ -3659,7 +3682,7 @@
3659
3682
  },
3660
3683
  })];
3661
3684
  case 1:
3662
- result = _b.sent();
3685
+ result = _c.sent();
3663
3686
  return [2 /*return*/, (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift()];
3664
3687
  }
3665
3688
  });
@@ -3670,34 +3693,38 @@
3670
3693
  update: { get: function () { return _super_1.prototype.update; } }
3671
3694
  });
3672
3695
  return __awaiter(this, void 0, void 0, function () {
3673
- var categories, id, data, product, _b, _c;
3674
- return __generator(this, function (_d) {
3675
- switch (_d.label) {
3696
+ var categories, checkId, data, plainData, id, product, _c, _d;
3697
+ return __generator(this, function (_e) {
3698
+ switch (_e.label) {
3676
3699
  case 0:
3677
- categories = params.categories, id = params.id, data = __rest(params, ["categories", "id"]);
3678
- return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
3700
+ categories = params.categories, checkId = params.id, data = __rest(params, ["categories", "id"]);
3701
+ plainData = this.paramsToPlain({ id: checkId });
3702
+ return [4 /*yield*/, this.getId(plainData.id)];
3679
3703
  case 1:
3680
- product = _d.sent();
3681
- _b = product;
3682
- _c = categories;
3683
- if (!_c) return [3 /*break*/, 3];
3684
- return [4 /*yield*/, this.updateCategories(+id, { categories: categories })];
3704
+ id = _e.sent();
3705
+ return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
3685
3706
  case 2:
3686
- _c = (_d.sent());
3687
- _d.label = 3;
3707
+ product = _e.sent();
3708
+ _c = product;
3709
+ _d = categories;
3710
+ if (!_d) return [3 /*break*/, 4];
3711
+ return [4 /*yield*/, this.updateCategories(+id, { categories: categories })];
3688
3712
  case 3:
3689
- _b.categories = _c;
3713
+ _d = (_e.sent());
3714
+ _e.label = 4;
3715
+ case 4:
3716
+ _c.categories = _d;
3690
3717
  return [2 /*return*/, product];
3691
3718
  }
3692
3719
  });
3693
3720
  });
3694
3721
  };
3695
- ProductHasuraGraphQLRepository.prototype.updateCategories = function (productId, _b) {
3696
- var categories = _b.categories;
3722
+ ProductHasuraGraphQLRepository.prototype.updateCategories = function (productId, _c) {
3723
+ var categories = _c.categories;
3697
3724
  return __awaiter(this, void 0, void 0, function () {
3698
3725
  var plainData;
3699
- return __generator(this, function (_b) {
3700
- switch (_b.label) {
3726
+ return __generator(this, function (_c) {
3727
+ switch (_c.label) {
3701
3728
  case 0:
3702
3729
  plainData = this.paramsToPlain({ categories: categories });
3703
3730
  return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
@@ -3708,7 +3735,7 @@
3708
3735
  },
3709
3736
  })];
3710
3737
  case 1:
3711
- _b.sent();
3738
+ _c.sent();
3712
3739
  return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
3713
3740
  objects: {
3714
3741
  type: '[category_product_insert_input!]',
@@ -3717,19 +3744,38 @@
3717
3744
  },
3718
3745
  })];
3719
3746
  case 2:
3720
- _b.sent();
3747
+ _c.sent();
3721
3748
  return [2 /*return*/, plainData.categories];
3722
3749
  }
3723
3750
  });
3724
3751
  });
3725
3752
  };
3753
+ ProductHasuraGraphQLRepository.prototype.getId = function (id) {
3754
+ var _a, _b;
3755
+ return __awaiter(this, void 0, void 0, function () {
3756
+ var data;
3757
+ return __generator(this, function (_c) {
3758
+ switch (_c.label) {
3759
+ case 0:
3760
+ if (!Number.isNaN(+id))
3761
+ return [2 /*return*/, id];
3762
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
3763
+ case 1:
3764
+ data = (_c.sent()).data;
3765
+ if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
3766
+ return [2 /*return*/, (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id];
3767
+ throw new NotFoundError("Product with id " + id + " not found");
3768
+ }
3769
+ });
3770
+ });
3771
+ };
3726
3772
  return ProductHasuraGraphQLRepository;
3727
3773
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3728
3774
 
3729
- var VariantHasuraGraphQLRepository = /** @class */ (function (_super) {
3730
- __extends(VariantHasuraGraphQLRepository, _super);
3775
+ var VariantHasuraGraphQLRepository = /** @class */ (function (_super_1) {
3776
+ __extends(VariantHasuraGraphQLRepository, _super_1);
3731
3777
  function VariantHasuraGraphQLRepository(endpoint, authOptions) {
3732
- return _super.call(this, {
3778
+ return _super_1.call(this, {
3733
3779
  tableName: 'product',
3734
3780
  model: VariantHasuraGraphQL,
3735
3781
  endpoint: endpoint,
@@ -3737,20 +3783,20 @@
3737
3783
  fields: [
3738
3784
  { id: { columnName: 'id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
3739
3785
  { firestoreId: { columnName: 'firestore_id' } },
3740
- { productId: { columnName: 'main_product_id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
3786
+ { productId: { columnName: 'main_product_id', to: function (value) { return +value; }, from: function (value) { return value === null || value === void 0 ? void 0 : value.toString(); } } },
3741
3787
  { EAN: { columnName: 'ean' } },
3742
3788
  { costPrice: { columnName: 'cost_price' } },
3743
3789
  {
3744
3790
  price: {
3745
3791
  columnName: 'price',
3746
3792
  from: function (price, data) { return Object.values(exports.Shops).reduce(function (prices, shop) {
3747
- var _a;
3748
- return (Object.assign(Object.assign({}, prices), (_a = {}, _a[shop] = {
3793
+ var _c;
3794
+ return (Object.assign(Object.assign({}, prices), (_c = {}, _c[shop] = {
3749
3795
  price: price,
3750
3796
  fullPrice: data.full_price,
3751
3797
  subscriberDiscountPercentage: data.subscriber_discount_percentage,
3752
3798
  subscriberPrice: data.subscriber_price,
3753
- }, _a)));
3799
+ }, _c)));
3754
3800
  }, {}); },
3755
3801
  bindFindFilter: function (sentence) {
3756
3802
  var filters = Object.values(sentence).shift();
@@ -3774,7 +3820,7 @@
3774
3820
  stock: {
3775
3821
  columnName: 'stock',
3776
3822
  from: function (quantity) { return ({ quantity: quantity }); },
3777
- to: function (value) { return (value === null || value === void 0 ? void 0 : value.quantity) || value; },
3823
+ to: function (value) { return (lodash.isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity); },
3778
3824
  },
3779
3825
  },
3780
3826
  'weight',
@@ -3785,6 +3831,71 @@
3785
3831
  ],
3786
3832
  }) || this;
3787
3833
  }
3834
+ VariantHasuraGraphQLRepository.prototype.get = function (identifiers) {
3835
+ var _super = Object.create(null, {
3836
+ get: { get: function () { return _super_1.prototype.get; } }
3837
+ });
3838
+ var _a;
3839
+ return __awaiter(this, void 0, void 0, function () {
3840
+ var _c;
3841
+ return __generator(this, function (_d) {
3842
+ switch (_d.label) {
3843
+ case 0:
3844
+ if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3845
+ return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3846
+ case 1:
3847
+ _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3848
+ return [3 /*break*/, 3];
3849
+ case 2:
3850
+ _c = _super.get.call(this, identifiers);
3851
+ _d.label = 3;
3852
+ case 3: return [2 /*return*/, _c];
3853
+ }
3854
+ });
3855
+ });
3856
+ };
3857
+ VariantHasuraGraphQLRepository.prototype.update = function (params) {
3858
+ var _super = Object.create(null, {
3859
+ update: { get: function () { return _super_1.prototype.update; } }
3860
+ });
3861
+ return __awaiter(this, void 0, void 0, function () {
3862
+ var productId, checkId, data, dataWithProductId, id, product;
3863
+ return __generator(this, function (_c) {
3864
+ switch (_c.label) {
3865
+ case 0:
3866
+ productId = params.productId, checkId = params.id, data = __rest(params, ["productId", "id"]);
3867
+ dataWithProductId = this.paramsToPlain({ id: checkId, productId: productId });
3868
+ return [4 /*yield*/, this.getId(dataWithProductId.id)];
3869
+ case 1:
3870
+ id = _c.sent();
3871
+ return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
3872
+ case 2:
3873
+ product = _c.sent();
3874
+ product.productId = dataWithProductId.productId;
3875
+ return [2 /*return*/, product];
3876
+ }
3877
+ });
3878
+ });
3879
+ };
3880
+ VariantHasuraGraphQLRepository.prototype.getId = function (id) {
3881
+ var _a, _b;
3882
+ return __awaiter(this, void 0, void 0, function () {
3883
+ var data;
3884
+ return __generator(this, function (_c) {
3885
+ switch (_c.label) {
3886
+ case 0:
3887
+ if (!Number.isNaN(+id))
3888
+ return [2 /*return*/, id];
3889
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
3890
+ case 1:
3891
+ data = (_c.sent()).data;
3892
+ if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
3893
+ return [2 /*return*/, (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id];
3894
+ throw new NotFoundError("Product with id " + id + " not found");
3895
+ }
3896
+ });
3897
+ });
3898
+ };
3788
3899
  return VariantHasuraGraphQLRepository;
3789
3900
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3790
3901