@infrab4a/connect 3.4.0-beta.1 → 3.4.0-beta.11

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.
Files changed (38) hide show
  1. package/bundles/infrab4a-connect.umd.js +315 -144
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/catalog/models/category-filter.d.ts +8 -0
  4. package/domain/catalog/models/category.d.ts +3 -2
  5. package/domain/catalog/models/filter-option.d.ts +1 -1
  6. package/domain/catalog/models/filter.d.ts +2 -1
  7. package/domain/catalog/models/index.d.ts +1 -0
  8. package/domain/catalog/models/types/index.d.ts +0 -1
  9. package/domain/catalog/repositories/category-filter.repository.d.ts +5 -0
  10. package/domain/catalog/repositories/index.d.ts +1 -0
  11. package/esm2015/domain/catalog/models/category-filter.js +10 -0
  12. package/esm2015/domain/catalog/models/category.js +8 -1
  13. package/esm2015/domain/catalog/models/filter-option.js +1 -1
  14. package/esm2015/domain/catalog/models/filter.js +1 -1
  15. package/esm2015/domain/catalog/models/index.js +2 -1
  16. package/esm2015/domain/catalog/models/types/index.js +1 -2
  17. package/esm2015/domain/catalog/repositories/category-filter.repository.js +2 -0
  18. package/esm2015/domain/catalog/repositories/index.js +2 -1
  19. package/esm2015/infra/hasura-graphql/mixins/helpers/attribute-option.helper.js +2 -2
  20. package/esm2015/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.js +24 -0
  21. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +76 -4
  22. package/esm2015/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.js +65 -46
  23. package/esm2015/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.js +9 -29
  24. package/esm2015/infra/hasura-graphql/repositories/catalog/index.js +2 -1
  25. package/esm2015/infra/hasura-graphql/types/hasura-graphql-fields.type.js +1 -1
  26. package/esm2015/utils/index.js +6 -6
  27. package/fesm2015/infrab4a-connect.js +195 -88
  28. package/fesm2015/infrab4a-connect.js.map +1 -1
  29. package/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +11 -0
  30. package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +4 -1
  31. package/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +7 -6
  32. package/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +2 -6
  33. package/infra/hasura-graphql/repositories/catalog/index.d.ts +1 -0
  34. package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +1 -1
  35. package/package.json +1 -1
  36. package/utils/index.d.ts +5 -5
  37. package/domain/catalog/models/types/category-filter.type.d.ts +0 -4
  38. package/esm2015/domain/catalog/models/types/category-filter.type.js +0 -2
@@ -832,8 +832,6 @@
832
832
  return Address;
833
833
  }(BaseModel));
834
834
 
835
- var isUUID = function (value) { return lodash.isString(value) && /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(value); };
836
-
837
835
  var Base = /** @class */ (function () {
838
836
  function Base() {
839
837
  var args = [];
@@ -845,6 +843,8 @@
845
843
  return Base;
846
844
  }());
847
845
 
846
+ var isUUID = function (value) { return lodash.isString(value) && /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(value); };
847
+
848
848
  var parseDateTime = function (value) {
849
849
  if (!lodash.isString(value))
850
850
  return value;
@@ -1252,6 +1252,24 @@
1252
1252
  return RecoveryPassword;
1253
1253
  }());
1254
1254
 
1255
+ var Filter = /** @class */ (function (_super) {
1256
+ __extends(Filter, _super);
1257
+ function Filter() {
1258
+ return _super !== null && _super.apply(this, arguments) || this;
1259
+ }
1260
+ Filter.prototype.identifierFields = function () {
1261
+ return ['id'];
1262
+ };
1263
+ Object.defineProperty(Filter, "identifiersFields", {
1264
+ get: function () {
1265
+ return ['id'];
1266
+ },
1267
+ enumerable: false,
1268
+ configurable: true
1269
+ });
1270
+ return Filter;
1271
+ }(BaseModel));
1272
+
1255
1273
  var Category = /** @class */ (function (_super) {
1256
1274
  __extends(Category, _super);
1257
1275
  function Category() {
@@ -1268,6 +1286,28 @@
1268
1286
  configurable: true
1269
1287
  });
1270
1288
  return Category;
1289
+ }(BaseModel));
1290
+ __decorate([
1291
+ classTransformer.Type(function () { return Filter; }),
1292
+ __metadata("design:type", Array)
1293
+ ], Category.prototype, "filters", void 0);
1294
+
1295
+ var CategoryFilter = /** @class */ (function (_super) {
1296
+ __extends(CategoryFilter, _super);
1297
+ function CategoryFilter() {
1298
+ return _super !== null && _super.apply(this, arguments) || this;
1299
+ }
1300
+ CategoryFilter.prototype.identifierFields = function () {
1301
+ return ['id'];
1302
+ };
1303
+ Object.defineProperty(CategoryFilter, "identifiersFields", {
1304
+ get: function () {
1305
+ return ['id'];
1306
+ },
1307
+ enumerable: false,
1308
+ configurable: true
1309
+ });
1310
+ return CategoryFilter;
1271
1311
  }(BaseModel));
1272
1312
 
1273
1313
  exports.GenderDestination = void 0;
@@ -1285,24 +1325,6 @@
1285
1325
  Shops["ALL"] = "ALL";
1286
1326
  })(exports.Shops || (exports.Shops = {}));
1287
1327
 
1288
- var Filter = /** @class */ (function (_super) {
1289
- __extends(Filter, _super);
1290
- function Filter() {
1291
- return _super !== null && _super.apply(this, arguments) || this;
1292
- }
1293
- Filter.prototype.identifierFields = function () {
1294
- return ['id'];
1295
- };
1296
- Object.defineProperty(Filter, "identifiersFields", {
1297
- get: function () {
1298
- return ['id'];
1299
- },
1300
- enumerable: false,
1301
- configurable: true
1302
- });
1303
- return Filter;
1304
- }(BaseModel));
1305
-
1306
1328
  var FilterOption = /** @class */ (function (_super) {
1307
1329
  __extends(FilterOption, _super);
1308
1330
  function FilterOption() {
@@ -3042,7 +3064,7 @@
3042
3064
  }());
3043
3065
  AttributeOptionHelper.FindByAttribute = function (attributeName, fields) {
3044
3066
  if (fields.includes(attributeName))
3045
- return { columnName: attributeName.toString(), attributeName: attributeName };
3067
+ return { columnName: attributeName.toString(), attributeName: attributeName, to: function (value) { return value; }, from: function (value) { return value; } };
3046
3068
  var field = fields.find(function (columnOption) { return lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()); });
3047
3069
  var fieldOption = field === null || field === void 0 ? void 0 : field[attributeName.toString()];
3048
3070
  if (lodash.isNil(fieldOption))
@@ -3736,9 +3758,32 @@
3736
3758
  return VariantHasuraGraphQL;
3737
3759
  }(Variant));
3738
3760
 
3761
+ var CategoryFilterHasuraGraphQLRepository = /** @class */ (function (_super) {
3762
+ __extends(CategoryFilterHasuraGraphQLRepository, _super);
3763
+ function CategoryFilterHasuraGraphQLRepository(endpoint, authOptions) {
3764
+ return _super.call(this, {
3765
+ tableName: 'category_filter',
3766
+ model: CategoryFilter,
3767
+ endpoint: endpoint,
3768
+ authOptions: authOptions,
3769
+ fields: ['id', { filterId: { columnName: 'filter_id' } }, { categoryId: { columnName: 'category_id' } }],
3770
+ }) || this;
3771
+ }
3772
+ CategoryFilterHasuraGraphQLRepository.prototype.deleteByCategoryAndFilter = function (categoryId, filterId) {
3773
+ return this.mutation('delete_category_filter', ['affected_rows'], {
3774
+ where: {
3775
+ type: 'category_filter_bool_exp',
3776
+ required: true,
3777
+ value: { category_id: { _eq: categoryId }, filterId: { _eq: filterId } },
3778
+ },
3779
+ });
3780
+ };
3781
+ return CategoryFilterHasuraGraphQLRepository;
3782
+ }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3783
+
3739
3784
  var CategoryHasuraGraphQLRepository = /** @class */ (function (_super_1) {
3740
3785
  __extends(CategoryHasuraGraphQLRepository, _super_1);
3741
- function CategoryHasuraGraphQLRepository(endpoint, authOptions, productRepository) {
3786
+ function CategoryHasuraGraphQLRepository(endpoint, authOptions, productRepository, categoryFilterRepository) {
3742
3787
  var _this = _super_1.call(this, {
3743
3788
  tableName: 'category',
3744
3789
  model: Category,
@@ -3774,7 +3819,17 @@
3774
3819
  },
3775
3820
  },
3776
3821
  },
3777
- 'filters',
3822
+ {
3823
+ filters: {
3824
+ columnName: 'filters',
3825
+ foreignKeyColumn: { filter_id: 'id' },
3826
+ fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
3827
+ bindPersistData: function (value) { return ({
3828
+ filters: { data: value.map(function (filter) { return ({ filter_id: filter.id }); }) },
3829
+ }); },
3830
+ from: function (filters) { return (filters === null || filters === void 0 ? void 0 : filters.map(function (filter) { return filter === null || filter === void 0 ? void 0 : filter.filter; })) || []; },
3831
+ },
3832
+ },
3778
3833
  { createdAt: { columnName: 'created_at' } },
3779
3834
  { updatedAt: { columnName: 'updated_at' } },
3780
3835
  {
@@ -3799,6 +3854,7 @@
3799
3854
  ],
3800
3855
  }) || this;
3801
3856
  _this.productRepository = productRepository;
3857
+ _this.categoryFilterRepository = categoryFilterRepository;
3802
3858
  return _this;
3803
3859
  }
3804
3860
  CategoryHasuraGraphQLRepository.prototype.create = function (params) {
@@ -3841,25 +3897,25 @@
3841
3897
  update: { get: function () { return _super_1.prototype.update; } }
3842
3898
  });
3843
3899
  return __awaiter(this, void 0, void 0, function () {
3844
- var products, checkId, metadata, data, plainData, id, category, _c, _d, _e, _f;
3845
- return __generator(this, function (_g) {
3846
- switch (_g.label) {
3900
+ var products, checkId, metadata, filters, data, plainData, id, category, _c, _d, _e, _f, _g, _h;
3901
+ return __generator(this, function (_j) {
3902
+ switch (_j.label) {
3847
3903
  case 0:
3848
- products = params.products, checkId = params.id, metadata = params.metadata, data = __rest(params, ["products", "id", "metadata"]);
3904
+ products = params.products, checkId = params.id, metadata = params.metadata, filters = params.filters, data = __rest(params, ["products", "id", "metadata", "filters"]);
3849
3905
  plainData = this.paramsToPlain({ id: checkId });
3850
3906
  return [4 /*yield*/, this.getId(plainData.id)];
3851
3907
  case 1:
3852
- id = _g.sent();
3908
+ id = _j.sent();
3853
3909
  return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
3854
3910
  case 2:
3855
- category = _g.sent();
3911
+ category = _j.sent();
3856
3912
  _c = category;
3857
3913
  _d = products;
3858
3914
  if (!_d) return [3 /*break*/, 4];
3859
3915
  return [4 /*yield*/, this.updateProducts(+id, { products: products })];
3860
3916
  case 3:
3861
- _d = (_g.sent());
3862
- _g.label = 4;
3917
+ _d = (_j.sent());
3918
+ _j.label = 4;
3863
3919
  case 4:
3864
3920
  _c.products = _d;
3865
3921
  _e = category;
@@ -3867,10 +3923,19 @@
3867
3923
  if (!_f) return [3 /*break*/, 6];
3868
3924
  return [4 /*yield*/, this.updateMetadata(+id, { metadata: metadata })];
3869
3925
  case 5:
3870
- _f = (_g.sent());
3871
- _g.label = 6;
3926
+ _f = (_j.sent());
3927
+ _j.label = 6;
3872
3928
  case 6:
3873
3929
  _e.metadata = _f;
3930
+ _g = category;
3931
+ _h = filters;
3932
+ if (!_h) return [3 /*break*/, 8];
3933
+ return [4 /*yield*/, this.updateFilters(+id, { filters: filters })];
3934
+ case 7:
3935
+ _h = (_j.sent());
3936
+ _j.label = 8;
3937
+ case 8:
3938
+ _g.filters = _h;
3874
3939
  return [2 /*return*/, category];
3875
3940
  }
3876
3941
  });
@@ -4096,12 +4161,111 @@
4096
4161
  });
4097
4162
  });
4098
4163
  };
4164
+ CategoryHasuraGraphQLRepository.prototype.updateFilters = function (categoryId, _c) {
4165
+ var filters = _c.filters;
4166
+ return __awaiter(this, void 0, void 0, function () {
4167
+ var i, filtersList, i, hasFilter, error_1, newCategoryFilter, filtersList, i, hasFilter, error_2, newCategoryFilter;
4168
+ return __generator(this, function (_c) {
4169
+ switch (_c.label) {
4170
+ case 0:
4171
+ if (!('action' in filters && filters.action === 'remove' && filters.value.length)) return [3 /*break*/, 5];
4172
+ i = 0;
4173
+ _c.label = 1;
4174
+ case 1:
4175
+ if (!(i < filters.value.length)) return [3 /*break*/, 4];
4176
+ return [4 /*yield*/, this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filters.value[i].id)];
4177
+ case 2:
4178
+ _c.sent();
4179
+ _c.label = 3;
4180
+ case 3:
4181
+ i++;
4182
+ return [3 /*break*/, 1];
4183
+ case 4: return [2 /*return*/, []];
4184
+ case 5:
4185
+ if (!('action' in filters && filters.action === 'merge' && filters.value.length)) return [3 /*break*/, 13];
4186
+ filtersList = [];
4187
+ i = 0;
4188
+ _c.label = 6;
4189
+ case 6:
4190
+ if (!(i < filters.value.length)) return [3 /*break*/, 12];
4191
+ _c.label = 7;
4192
+ case 7:
4193
+ _c.trys.push([7, 9, , 11]);
4194
+ return [4 /*yield*/, this.categoryFilterRepository
4195
+ .find({
4196
+ filters: {
4197
+ categoryId: categoryId,
4198
+ filterId: filters[i].id,
4199
+ },
4200
+ })
4201
+ .then(function (data) { return data.data.shift(); })];
4202
+ case 8:
4203
+ hasFilter = _c.sent();
4204
+ if (hasFilter)
4205
+ filtersList.push(hasFilter);
4206
+ return [3 /*break*/, 11];
4207
+ case 9:
4208
+ error_1 = _c.sent();
4209
+ return [4 /*yield*/, this.categoryFilterRepository.create({
4210
+ filterId: filters.value[i].id,
4211
+ categoryId: categoryId,
4212
+ })];
4213
+ case 10:
4214
+ newCategoryFilter = _c.sent();
4215
+ filtersList.push(newCategoryFilter);
4216
+ return [3 /*break*/, 11];
4217
+ case 11:
4218
+ i++;
4219
+ return [3 /*break*/, 6];
4220
+ case 12: return [2 /*return*/, filtersList];
4221
+ case 13:
4222
+ if (!(Array.isArray(filters) && filters.length)) return [3 /*break*/, 21];
4223
+ filtersList = [];
4224
+ i = 0;
4225
+ _c.label = 14;
4226
+ case 14:
4227
+ if (!(i < filters.length)) return [3 /*break*/, 20];
4228
+ _c.label = 15;
4229
+ case 15:
4230
+ _c.trys.push([15, 17, , 19]);
4231
+ return [4 /*yield*/, this.categoryFilterRepository
4232
+ .find({
4233
+ filters: {
4234
+ categoryId: categoryId,
4235
+ filterId: filters[i].id,
4236
+ },
4237
+ })
4238
+ .then(function (data) { return data.data.shift(); })];
4239
+ case 16:
4240
+ hasFilter = _c.sent();
4241
+ if (hasFilter)
4242
+ filtersList.push(hasFilter);
4243
+ return [3 /*break*/, 19];
4244
+ case 17:
4245
+ error_2 = _c.sent();
4246
+ return [4 /*yield*/, this.categoryFilterRepository.create({
4247
+ filterId: filters[i].id,
4248
+ categoryId: categoryId,
4249
+ })];
4250
+ case 18:
4251
+ newCategoryFilter = _c.sent();
4252
+ filtersList.push(newCategoryFilter);
4253
+ return [3 /*break*/, 19];
4254
+ case 19:
4255
+ i++;
4256
+ return [3 /*break*/, 14];
4257
+ case 20: return [2 /*return*/, filtersList];
4258
+ case 21: return [2 /*return*/];
4259
+ }
4260
+ });
4261
+ });
4262
+ };
4099
4263
  return CategoryHasuraGraphQLRepository;
4100
4264
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4101
4265
 
4102
4266
  var FilterHasuraGraphQLRepository = /** @class */ (function (_super_1) {
4103
4267
  __extends(FilterHasuraGraphQLRepository, _super_1);
4104
- function FilterHasuraGraphQLRepository(endpoint, authOptions, filterOptionRepository) {
4268
+ function FilterHasuraGraphQLRepository(endpoint, authOptions, filterOptionRepository, categoryFilterRepository) {
4105
4269
  var _this = _super_1.call(this, {
4106
4270
  tableName: 'filter',
4107
4271
  model: Filter,
@@ -4110,9 +4274,10 @@
4110
4274
  fields: [
4111
4275
  'id',
4112
4276
  'description',
4277
+ 'slug',
4113
4278
  'enabled',
4114
- 'createdAt',
4115
- 'updatedAt',
4279
+ { createdAt: { columnName: 'created_at' } },
4280
+ { updatedAt: { columnName: 'updated_at' } },
4116
4281
  {
4117
4282
  options: {
4118
4283
  columnName: 'options',
@@ -4121,66 +4286,17 @@
4121
4286
  'id',
4122
4287
  { filterId: { columnName: 'filter_id' } },
4123
4288
  'description',
4124
- 'createdAt',
4125
- 'updatedAt'
4289
+ { createdAt: { columnName: 'created_at' } },
4290
+ { updatedAt: { columnName: 'updated_at' } },
4126
4291
  ],
4127
4292
  },
4128
- }
4293
+ },
4129
4294
  ],
4130
4295
  }) || this;
4131
4296
  _this.filterOptionRepository = filterOptionRepository;
4297
+ _this.categoryFilterRepository = categoryFilterRepository;
4132
4298
  return _this;
4133
4299
  }
4134
- FilterHasuraGraphQLRepository.prototype.get = function (identifiers) {
4135
- var _super = Object.create(null, {
4136
- get: { get: function () { return _super_1.prototype.get; } }
4137
- });
4138
- return __awaiter(this, void 0, void 0, function () {
4139
- var filter;
4140
- return __generator(this, function (_a) {
4141
- switch (_a.label) {
4142
- case 0: return [4 /*yield*/, _super.get.call(this, identifiers)];
4143
- case 1:
4144
- filter = _a.sent();
4145
- if (!filter)
4146
- throw new NotFoundError('Filter not found');
4147
- return [2 /*return*/, filter];
4148
- }
4149
- });
4150
- });
4151
- };
4152
- FilterHasuraGraphQLRepository.prototype.find = function (options) {
4153
- var _super = Object.create(null, {
4154
- find: { get: function () { return _super_1.prototype.find; } }
4155
- });
4156
- return __awaiter(this, void 0, void 0, function () {
4157
- var filter;
4158
- return __generator(this, function (_a) {
4159
- switch (_a.label) {
4160
- case 0: return [4 /*yield*/, _super.find.call(this, options)];
4161
- case 1:
4162
- filter = _a.sent();
4163
- return [2 /*return*/, filter];
4164
- }
4165
- });
4166
- });
4167
- };
4168
- FilterHasuraGraphQLRepository.prototype.create = function (params) {
4169
- var _super = Object.create(null, {
4170
- create: { get: function () { return _super_1.prototype.create; } }
4171
- });
4172
- return __awaiter(this, void 0, void 0, function () {
4173
- var filter;
4174
- return __generator(this, function (_a) {
4175
- switch (_a.label) {
4176
- case 0: return [4 /*yield*/, _super.create.call(this, params)];
4177
- case 1:
4178
- filter = _a.sent();
4179
- return [2 /*return*/, filter];
4180
- }
4181
- });
4182
- });
4183
- };
4184
4300
  FilterHasuraGraphQLRepository.prototype.update = function (params) {
4185
4301
  var _super = Object.create(null, {
4186
4302
  update: { get: function () { return _super_1.prototype.update; } }
@@ -4203,17 +4319,16 @@
4203
4319
  });
4204
4320
  });
4205
4321
  };
4206
- ;
4207
4322
  FilterHasuraGraphQLRepository.prototype.updateOptions = function (filterId, _a) {
4208
4323
  var options = _a.options;
4209
4324
  return __awaiter(this, void 0, void 0, function () {
4210
- var i, filterOptions, i, hasFilter, newOption;
4325
+ var i, filterOptions, i, hasFilter, error_1, newOption, filterOptions, i, hasFilter, error_2, newOption;
4211
4326
  return __generator(this, function (_a) {
4212
4327
  switch (_a.label) {
4213
4328
  case 0:
4214
4329
  if (!options)
4215
4330
  return [2 /*return*/, []];
4216
- if (!('action' in options && options.action === 'remove')) return [3 /*break*/, 5];
4331
+ if (!('action' in options && options.action === 'remove' && options.value.length)) return [3 /*break*/, 5];
4217
4332
  i = 0;
4218
4333
  _a.label = 1;
4219
4334
  case 1:
@@ -4227,86 +4342,144 @@
4227
4342
  return [3 /*break*/, 1];
4228
4343
  case 4: return [2 /*return*/, []];
4229
4344
  case 5:
4230
- if (!('action' in options && options.action === 'update')) return [3 /*break*/, 12];
4345
+ if (!('action' in options && options.action === 'merge' && options.value.length)) return [3 /*break*/, 13];
4231
4346
  filterOptions = [];
4232
4347
  i = 0;
4233
4348
  _a.label = 6;
4234
4349
  case 6:
4235
- if (!(i < options.value.length)) return [3 /*break*/, 11];
4236
- return [4 /*yield*/, this.filterOptionRepository.get({ id: options.value[i].id })];
4350
+ if (!(i < options.value.length)) return [3 /*break*/, 12];
4351
+ _a.label = 7;
4237
4352
  case 7:
4238
- hasFilter = _a.sent();
4239
- if (!!hasFilter) return [3 /*break*/, 9];
4240
- return [4 /*yield*/, this.filterOptionRepository.create(options.value[i])];
4353
+ _a.trys.push([7, 9, , 11]);
4354
+ return [4 /*yield*/, this.filterOptionRepository.get({ id: options.value[i].id })];
4241
4355
  case 8:
4242
- newOption = _a.sent();
4243
- filterOptions.push(newOption);
4244
- return [3 /*break*/, 10];
4356
+ hasFilter = _a.sent();
4357
+ if (hasFilter)
4358
+ filterOptions.push(hasFilter);
4359
+ return [3 /*break*/, 11];
4245
4360
  case 9:
4246
- filterOptions.push(hasFilter);
4247
- _a.label = 10;
4361
+ error_1 = _a.sent();
4362
+ return [4 /*yield*/, this.filterOptionRepository.create(Object.assign(Object.assign({}, options.value[i]), { filterId: filterId }))];
4248
4363
  case 10:
4364
+ newOption = _a.sent();
4365
+ filterOptions.push(newOption);
4366
+ return [3 /*break*/, 11];
4367
+ case 11:
4249
4368
  i++;
4250
4369
  return [3 /*break*/, 6];
4251
- case 11: return [2 /*return*/, filterOptions];
4252
- case 12: return [2 /*return*/];
4370
+ case 12: return [2 /*return*/, filterOptions];
4371
+ case 13:
4372
+ if (!(Array.isArray(options) && options.length)) return [3 /*break*/, 20];
4373
+ filterOptions = [];
4374
+ i = 0;
4375
+ _a.label = 14;
4376
+ case 14:
4377
+ if (!(i < options.length)) return [3 /*break*/, 20];
4378
+ _a.label = 15;
4379
+ case 15:
4380
+ _a.trys.push([15, 17, , 19]);
4381
+ return [4 /*yield*/, this.filterOptionRepository.get({ id: options[i].id })];
4382
+ case 16:
4383
+ hasFilter = _a.sent();
4384
+ if (hasFilter)
4385
+ filterOptions.push(hasFilter);
4386
+ return [3 /*break*/, 19];
4387
+ case 17:
4388
+ error_2 = _a.sent();
4389
+ return [4 /*yield*/, this.filterOptionRepository.create(Object.assign(Object.assign({}, options[i]), { filterId: filterId }))];
4390
+ case 18:
4391
+ newOption = _a.sent();
4392
+ filterOptions.push(newOption);
4393
+ return [3 /*break*/, 19];
4394
+ case 19:
4395
+ i++;
4396
+ return [3 /*break*/, 14];
4397
+ case 20: return [2 /*return*/, []];
4253
4398
  }
4254
4399
  });
4255
4400
  });
4256
4401
  };
4257
- return FilterHasuraGraphQLRepository;
4258
- }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4259
-
4260
- var FilterOptionHasuraGraphQLRepository = /** @class */ (function (_super_1) {
4261
- __extends(FilterOptionHasuraGraphQLRepository, _super_1);
4262
- function FilterOptionHasuraGraphQLRepository(endpoint, authOptions) {
4263
- return _super_1.call(this, {
4264
- tableName: 'filter-option',
4265
- model: FilterOption,
4266
- endpoint: endpoint,
4267
- authOptions: authOptions,
4268
- fields: [],
4269
- }) || this;
4270
- }
4271
- FilterOptionHasuraGraphQLRepository.prototype.create = function (params) {
4272
- return _super_1.prototype.create.call(this, params);
4273
- };
4274
- FilterOptionHasuraGraphQLRepository.prototype.find = function (options) {
4402
+ FilterHasuraGraphQLRepository.prototype.delete = function (params) {
4275
4403
  var _super = Object.create(null, {
4276
- find: { get: function () { return _super_1.prototype.find; } }
4404
+ delete: { get: function () { return _super_1.prototype.delete; } }
4277
4405
  });
4278
4406
  return __awaiter(this, void 0, void 0, function () {
4279
- var filterOptions;
4407
+ var options, data, categoryFilters;
4280
4408
  return __generator(this, function (_a) {
4281
4409
  switch (_a.label) {
4282
- case 0: return [4 /*yield*/, _super.find.call(this, options)];
4410
+ case 0:
4411
+ options = params.options, data = __rest(params, ["options"]);
4412
+ return [4 /*yield*/, this.categoryFilterRepository
4413
+ .find({
4414
+ filters: {
4415
+ filterId: +data.id,
4416
+ },
4417
+ })
4418
+ .then(function (result) { return result.data; })];
4283
4419
  case 1:
4284
- filterOptions = _a.sent();
4285
- return [2 /*return*/, filterOptions];
4420
+ categoryFilters = _a.sent();
4421
+ if (categoryFilters.length)
4422
+ throw new Error('Erro: o filtro está associado a uma ou mais categoria(s)');
4423
+ return [4 /*yield*/, this.deleteOptions(options)];
4424
+ case 2:
4425
+ _a.sent();
4426
+ return [4 /*yield*/, _super.delete.call(this, { id: +data.id })];
4427
+ case 3:
4428
+ _a.sent();
4429
+ return [2 /*return*/];
4286
4430
  }
4287
4431
  });
4288
4432
  });
4289
4433
  };
4290
- FilterOptionHasuraGraphQLRepository.prototype.delete = function (identifiers) {
4291
- return _super_1.prototype.delete.call(this, identifiers);
4292
- };
4293
- FilterOptionHasuraGraphQLRepository.prototype.findByFilter = function (filterId) {
4434
+ FilterHasuraGraphQLRepository.prototype.deleteOptions = function (options) {
4294
4435
  return __awaiter(this, void 0, void 0, function () {
4295
- var options;
4436
+ var i, error_3;
4296
4437
  return __generator(this, function (_a) {
4297
4438
  switch (_a.label) {
4298
- case 0: return [4 /*yield*/, this.find({
4299
- filters: {
4300
- filterId: filterId,
4301
- },
4302
- })];
4439
+ case 0:
4440
+ i = 0;
4441
+ _a.label = 1;
4303
4442
  case 1:
4304
- options = _a.sent();
4305
- return [2 /*return*/, options];
4443
+ if (!(i < options.length)) return [3 /*break*/, 6];
4444
+ _a.label = 2;
4445
+ case 2:
4446
+ _a.trys.push([2, 4, , 5]);
4447
+ return [4 /*yield*/, this.filterOptionRepository.delete({ id: options[i].id })];
4448
+ case 3:
4449
+ _a.sent();
4450
+ return [3 /*break*/, 5];
4451
+ case 4:
4452
+ error_3 = _a.sent();
4453
+ console.log(error_3);
4454
+ return [3 /*break*/, 5];
4455
+ case 5:
4456
+ i++;
4457
+ return [3 /*break*/, 1];
4458
+ case 6: return [2 /*return*/];
4306
4459
  }
4307
4460
  });
4308
4461
  });
4309
4462
  };
4463
+ return FilterHasuraGraphQLRepository;
4464
+ }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4465
+
4466
+ var FilterOptionHasuraGraphQLRepository = /** @class */ (function (_super) {
4467
+ __extends(FilterOptionHasuraGraphQLRepository, _super);
4468
+ function FilterOptionHasuraGraphQLRepository(endpoint, authOptions) {
4469
+ return _super.call(this, {
4470
+ tableName: 'filter_option',
4471
+ model: FilterOption,
4472
+ endpoint: endpoint,
4473
+ authOptions: authOptions,
4474
+ fields: [
4475
+ 'id',
4476
+ 'description',
4477
+ { filterId: { columnName: 'filter_id' } },
4478
+ { createdAt: { columnName: 'created_at' } },
4479
+ { updatedAt: { columnName: 'updated_at' } },
4480
+ ],
4481
+ }) || this;
4482
+ }
4310
4483
  return FilterOptionHasuraGraphQLRepository;
4311
4484
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4312
4485
 
@@ -5178,10 +5351,6 @@
5178
5351
  enumerable: true,
5179
5352
  get: function () { return lodash.chunk; }
5180
5353
  });
5181
- Object.defineProperty(exports, 'difference', {
5182
- enumerable: true,
5183
- get: function () { return lodash.difference; }
5184
- });
5185
5354
  Object.defineProperty(exports, 'isBoolean', {
5186
5355
  enumerable: true,
5187
5356
  get: function () { return lodash.isBoolean; }
@@ -5245,6 +5414,8 @@
5245
5414
  exports.Buy2Win = Buy2Win;
5246
5415
  exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
5247
5416
  exports.Category = Category;
5417
+ exports.CategoryFilter = CategoryFilter;
5418
+ exports.CategoryFilterHasuraGraphQLRepository = CategoryFilterHasuraGraphQLRepository;
5248
5419
  exports.CategoryFirestoreRepository = CategoryFirestoreRepository;
5249
5420
  exports.CategoryHasuraGraphQL = CategoryHasuraGraphQL;
5250
5421
  exports.CategoryHasuraGraphQLRepository = CategoryHasuraGraphQLRepository;