@infrab4a/connect 1.0.0-beta.12 → 1.0.0-beta.14

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.
@@ -3548,10 +3548,10 @@
3548
3548
  return VariantHasuraGraphQL;
3549
3549
  }(Variant));
3550
3550
 
3551
- var ProductHasuraGraphQLRepository = /** @class */ (function (_super) {
3552
- __extends(ProductHasuraGraphQLRepository, _super);
3551
+ var ProductHasuraGraphQLRepository = /** @class */ (function (_super_1) {
3552
+ __extends(ProductHasuraGraphQLRepository, _super_1);
3553
3553
  function ProductHasuraGraphQLRepository(endpoint, authOptions) {
3554
- return _super.call(this, {
3554
+ return _super_1.call(this, {
3555
3555
  tableName: 'product',
3556
3556
  model: ProductHasuraGraphQL,
3557
3557
  endpoint: endpoint,
@@ -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,19 +3682,100 @@
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
  });
3666
3689
  });
3667
3690
  };
3691
+ ProductHasuraGraphQLRepository.prototype.update = function (params) {
3692
+ var _super = Object.create(null, {
3693
+ update: { get: function () { return _super_1.prototype.update; } }
3694
+ });
3695
+ return __awaiter(this, void 0, void 0, function () {
3696
+ var categories, checkId, data, plainData, id, product, _c, _d;
3697
+ return __generator(this, function (_e) {
3698
+ switch (_e.label) {
3699
+ case 0:
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)];
3703
+ case 1:
3704
+ id = _e.sent();
3705
+ return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
3706
+ case 2:
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 })];
3712
+ case 3:
3713
+ _d = (_e.sent());
3714
+ _e.label = 4;
3715
+ case 4:
3716
+ _c.categories = _d;
3717
+ return [2 /*return*/, product];
3718
+ }
3719
+ });
3720
+ });
3721
+ };
3722
+ ProductHasuraGraphQLRepository.prototype.updateCategories = function (productId, _c) {
3723
+ var categories = _c.categories;
3724
+ return __awaiter(this, void 0, void 0, function () {
3725
+ var plainData;
3726
+ return __generator(this, function (_c) {
3727
+ switch (_c.label) {
3728
+ case 0:
3729
+ plainData = this.paramsToPlain({ categories: categories });
3730
+ return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
3731
+ where: {
3732
+ type: 'category_product_bool_exp',
3733
+ required: true,
3734
+ value: { product_id: { _eq: productId } },
3735
+ },
3736
+ })];
3737
+ case 1:
3738
+ _c.sent();
3739
+ return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
3740
+ objects: {
3741
+ type: '[category_product_insert_input!]',
3742
+ required: true,
3743
+ value: plainData.categories.map(function (categoryId) { return ({ category_id: categoryId, product_id: productId }); }),
3744
+ },
3745
+ })];
3746
+ case 2:
3747
+ _c.sent();
3748
+ return [2 /*return*/, plainData.categories];
3749
+ }
3750
+ });
3751
+ });
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
+ };
3668
3772
  return ProductHasuraGraphQLRepository;
3669
3773
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3670
3774
 
3671
- var VariantHasuraGraphQLRepository = /** @class */ (function (_super) {
3672
- __extends(VariantHasuraGraphQLRepository, _super);
3775
+ var VariantHasuraGraphQLRepository = /** @class */ (function (_super_1) {
3776
+ __extends(VariantHasuraGraphQLRepository, _super_1);
3673
3777
  function VariantHasuraGraphQLRepository(endpoint, authOptions) {
3674
- return _super.call(this, {
3778
+ return _super_1.call(this, {
3675
3779
  tableName: 'product',
3676
3780
  model: VariantHasuraGraphQL,
3677
3781
  endpoint: endpoint,
@@ -3686,13 +3790,13 @@
3686
3790
  price: {
3687
3791
  columnName: 'price',
3688
3792
  from: function (price, data) { return Object.values(exports.Shops).reduce(function (prices, shop) {
3689
- var _a;
3690
- return (Object.assign(Object.assign({}, prices), (_a = {}, _a[shop] = {
3793
+ var _c;
3794
+ return (Object.assign(Object.assign({}, prices), (_c = {}, _c[shop] = {
3691
3795
  price: price,
3692
3796
  fullPrice: data.full_price,
3693
3797
  subscriberDiscountPercentage: data.subscriber_discount_percentage,
3694
3798
  subscriberPrice: data.subscriber_price,
3695
- }, _a)));
3799
+ }, _c)));
3696
3800
  }, {}); },
3697
3801
  bindFindFilter: function (sentence) {
3698
3802
  var filters = Object.values(sentence).shift();
@@ -3716,7 +3820,7 @@
3716
3820
  stock: {
3717
3821
  columnName: 'stock',
3718
3822
  from: function (quantity) { return ({ quantity: quantity }); },
3719
- 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); },
3720
3824
  },
3721
3825
  },
3722
3826
  'weight',
@@ -3727,6 +3831,71 @@
3727
3831
  ],
3728
3832
  }) || this;
3729
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
+ };
3730
3899
  return VariantHasuraGraphQLRepository;
3731
3900
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3732
3901