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

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.
@@ -35,13 +35,13 @@
35
35
  configurable: true
36
36
  });
37
37
  BaseModel.toInstance = function (data) {
38
- return classTransformer.plainToClass(this, data || {});
38
+ return classTransformer.plainToInstance(this, data || {});
39
39
  };
40
40
  BaseModel.isModel = function (value) {
41
41
  return value instanceof this;
42
42
  };
43
43
  BaseModel.prototype.toPlain = function () {
44
- return classTransformer.classToPlain(this);
44
+ return classTransformer.instanceToPlain(this);
45
45
  };
46
46
  return BaseModel;
47
47
  }());
@@ -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,
@@ -3665,6 +3665,64 @@
3665
3665
  });
3666
3666
  });
3667
3667
  };
3668
+ ProductHasuraGraphQLRepository.prototype.update = function (params) {
3669
+ var _super = Object.create(null, {
3670
+ update: { get: function () { return _super_1.prototype.update; } }
3671
+ });
3672
+ 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) {
3676
+ 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))];
3679
+ 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 })];
3685
+ case 2:
3686
+ _c = (_d.sent());
3687
+ _d.label = 3;
3688
+ case 3:
3689
+ _b.categories = _c;
3690
+ return [2 /*return*/, product];
3691
+ }
3692
+ });
3693
+ });
3694
+ };
3695
+ ProductHasuraGraphQLRepository.prototype.updateCategories = function (productId, _b) {
3696
+ var categories = _b.categories;
3697
+ return __awaiter(this, void 0, void 0, function () {
3698
+ var plainData;
3699
+ return __generator(this, function (_b) {
3700
+ switch (_b.label) {
3701
+ case 0:
3702
+ plainData = this.paramsToPlain({ categories: categories });
3703
+ return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
3704
+ where: {
3705
+ type: 'category_product_bool_exp',
3706
+ required: true,
3707
+ value: { product_id: { _eq: productId } },
3708
+ },
3709
+ })];
3710
+ case 1:
3711
+ _b.sent();
3712
+ return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
3713
+ objects: {
3714
+ type: '[category_product_insert_input!]',
3715
+ required: true,
3716
+ value: plainData.categories.map(function (categoryId) { return ({ category_id: categoryId, product_id: productId }); }),
3717
+ },
3718
+ })];
3719
+ case 2:
3720
+ _b.sent();
3721
+ return [2 /*return*/, plainData.categories];
3722
+ }
3723
+ });
3724
+ });
3725
+ };
3668
3726
  return ProductHasuraGraphQLRepository;
3669
3727
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3670
3728