@infrab4a/connect 3.3.3-beta.0 → 3.3.3-beta.1

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 (49) hide show
  1. package/bundles/infrab4a-connect.umd.js +471 -14
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/catalog/models/category-filter.d.ts +9 -0
  4. package/domain/catalog/models/category.d.ts +3 -2
  5. package/domain/catalog/models/filter-option.d.ts +10 -0
  6. package/domain/catalog/models/filter.d.ts +13 -0
  7. package/domain/catalog/models/index.d.ts +3 -0
  8. package/domain/catalog/models/product.d.ts +1 -0
  9. package/domain/catalog/models/types/index.d.ts +0 -1
  10. package/domain/catalog/repositories/category-filter.repository.d.ts +5 -0
  11. package/domain/catalog/repositories/filter-option.repository.d.ts +4 -0
  12. package/domain/catalog/repositories/filter.repository.d.ts +4 -0
  13. package/domain/catalog/repositories/index.d.ts +3 -0
  14. package/domain/catalog/repositories/product.repository.d.ts +1 -0
  15. package/esm2015/domain/catalog/models/category-filter.js +10 -0
  16. package/esm2015/domain/catalog/models/category.js +8 -1
  17. package/esm2015/domain/catalog/models/filter-option.js +10 -0
  18. package/esm2015/domain/catalog/models/filter.js +10 -0
  19. package/esm2015/domain/catalog/models/index.js +4 -1
  20. package/esm2015/domain/catalog/models/product.js +1 -1
  21. package/esm2015/domain/catalog/models/types/index.js +1 -2
  22. package/esm2015/domain/catalog/repositories/category-filter.repository.js +2 -0
  23. package/esm2015/domain/catalog/repositories/filter-option.repository.js +2 -0
  24. package/esm2015/domain/catalog/repositories/filter.repository.js +2 -0
  25. package/esm2015/domain/catalog/repositories/index.js +4 -1
  26. package/esm2015/domain/catalog/repositories/product.repository.js +1 -1
  27. package/esm2015/infra/elasticsearch/indexes/products-index.js +3 -2
  28. package/esm2015/infra/firebase/firestore/repositories/catalog/product-firestore.repository.js +4 -1
  29. package/esm2015/infra/hasura-graphql/mixins/helpers/attribute-option.helper.js +2 -2
  30. package/esm2015/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.js +24 -0
  31. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +84 -4
  32. package/esm2015/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.js +123 -0
  33. package/esm2015/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.js +21 -0
  34. package/esm2015/infra/hasura-graphql/repositories/catalog/index.js +4 -1
  35. package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +17 -1
  36. package/esm2015/infra/hasura-graphql/types/hasura-graphql-fields.type.js +1 -1
  37. package/fesm2015/infrab4a-connect.js +295 -6
  38. package/fesm2015/infrab4a-connect.js.map +1 -1
  39. package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +1 -0
  40. package/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +11 -0
  41. package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +4 -1
  42. package/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +18 -0
  43. package/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +10 -0
  44. package/infra/hasura-graphql/repositories/catalog/index.d.ts +3 -0
  45. package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +1 -0
  46. package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +1 -1
  47. package/package.json +1 -1
  48. package/domain/catalog/models/types/category-filter.type.d.ts +0 -4
  49. package/esm2015/domain/catalog/models/types/category-filter.type.js +0 -2
@@ -1318,6 +1318,24 @@
1318
1318
  return RecoveryPassword;
1319
1319
  }());
1320
1320
 
1321
+ var Filter = /** @class */ (function (_super) {
1322
+ __extends(Filter, _super);
1323
+ function Filter() {
1324
+ return _super !== null && _super.apply(this, arguments) || this;
1325
+ }
1326
+ Filter.prototype.identifierFields = function () {
1327
+ return ['id'];
1328
+ };
1329
+ Object.defineProperty(Filter, "identifiersFields", {
1330
+ get: function () {
1331
+ return ['id'];
1332
+ },
1333
+ enumerable: false,
1334
+ configurable: true
1335
+ });
1336
+ return Filter;
1337
+ }(BaseModel));
1338
+
1321
1339
  var Category = /** @class */ (function (_super) {
1322
1340
  __extends(Category, _super);
1323
1341
  function Category() {
@@ -1334,6 +1352,28 @@
1334
1352
  configurable: true
1335
1353
  });
1336
1354
  return Category;
1355
+ }(BaseModel));
1356
+ __decorate([
1357
+ classTransformer.Type(function () { return Filter; }),
1358
+ __metadata("design:type", Array)
1359
+ ], Category.prototype, "filters", void 0);
1360
+
1361
+ var CategoryFilter = /** @class */ (function (_super) {
1362
+ __extends(CategoryFilter, _super);
1363
+ function CategoryFilter() {
1364
+ return _super !== null && _super.apply(this, arguments) || this;
1365
+ }
1366
+ Object.defineProperty(CategoryFilter, "identifiersFields", {
1367
+ // identifierFields(): NonFunctionPropertyNames<CategoryFilter>[] {
1368
+ // return ['id']
1369
+ // }
1370
+ get: function () {
1371
+ return ['id', 'filterId', 'categoryId'];
1372
+ },
1373
+ enumerable: false,
1374
+ configurable: true
1375
+ });
1376
+ return CategoryFilter;
1337
1377
  }(BaseModel));
1338
1378
 
1339
1379
  exports.GenderDestination = void 0;
@@ -1351,6 +1391,24 @@
1351
1391
  Shops["ALL"] = "ALL";
1352
1392
  })(exports.Shops || (exports.Shops = {}));
1353
1393
 
1394
+ var FilterOption = /** @class */ (function (_super) {
1395
+ __extends(FilterOption, _super);
1396
+ function FilterOption() {
1397
+ return _super !== null && _super.apply(this, arguments) || this;
1398
+ }
1399
+ FilterOption.prototype.identifierFields = function () {
1400
+ return ['id'];
1401
+ };
1402
+ Object.defineProperty(FilterOption, "identifiersFields", {
1403
+ get: function () {
1404
+ return ['id'];
1405
+ },
1406
+ enumerable: false,
1407
+ configurable: true
1408
+ });
1409
+ return FilterOption;
1410
+ }(BaseModel));
1411
+
1354
1412
  var Product = /** @class */ (function (_super) {
1355
1413
  __extends(Product, _super);
1356
1414
  function Product() {
@@ -1863,8 +1921,9 @@
1863
1921
  'stock',
1864
1922
  'weight',
1865
1923
  'tags',
1924
+ 'filters',
1866
1925
  'hasVariants',
1867
- 'type'
1926
+ 'type',
1868
1927
  ];
1869
1928
  return [4 /*yield*/, this.adapter.query('products/_search', Object.assign({ _source: fields, query: {
1870
1929
  bool: {
@@ -2750,6 +2809,9 @@
2750
2809
  });
2751
2810
  });
2752
2811
  };
2812
+ ProductFirestoreRepository.prototype.cleanShoppingCountFromIds = function (ids) {
2813
+ return;
2814
+ };
2753
2815
  return ProductFirestoreRepository;
2754
2816
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2755
2817
 
@@ -3128,7 +3190,7 @@
3128
3190
  }());
3129
3191
  AttributeOptionHelper.FindByAttribute = function (attributeName, fields) {
3130
3192
  if (fields.includes(attributeName))
3131
- return { columnName: attributeName.toString(), attributeName: attributeName };
3193
+ return { columnName: attributeName.toString(), attributeName: attributeName, to: function (value) { return value; }, from: function (value) { return value; } };
3132
3194
  var field = fields.find(function (columnOption) { return lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()); });
3133
3195
  var fieldOption = field === null || field === void 0 ? void 0 : field[attributeName.toString()];
3134
3196
  if (lodash.isNil(fieldOption))
@@ -3824,9 +3886,32 @@
3824
3886
  return VariantHasuraGraphQL;
3825
3887
  }(Variant));
3826
3888
 
3889
+ var CategoryFilterHasuraGraphQLRepository = /** @class */ (function (_super) {
3890
+ __extends(CategoryFilterHasuraGraphQLRepository, _super);
3891
+ function CategoryFilterHasuraGraphQLRepository(endpoint, authOptions) {
3892
+ return _super.call(this, {
3893
+ tableName: 'category_filter',
3894
+ model: CategoryFilter,
3895
+ endpoint: endpoint,
3896
+ authOptions: authOptions,
3897
+ fields: ['id', { filterId: { columnName: 'filter_id' } }, { categoryId: { columnName: 'category_id' } }],
3898
+ }) || this;
3899
+ }
3900
+ CategoryFilterHasuraGraphQLRepository.prototype.deleteByCategoryAndFilter = function (categoryId, filterId) {
3901
+ return this.mutation('delete_category_filter', ['affected_rows'], {
3902
+ where: {
3903
+ type: 'category_filter_bool_exp',
3904
+ required: true,
3905
+ value: { category_id: { _eq: categoryId }, filter_id: { _eq: filterId } },
3906
+ },
3907
+ });
3908
+ };
3909
+ return CategoryFilterHasuraGraphQLRepository;
3910
+ }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3911
+
3827
3912
  var CategoryHasuraGraphQLRepository = /** @class */ (function (_super_1) {
3828
3913
  __extends(CategoryHasuraGraphQLRepository, _super_1);
3829
- function CategoryHasuraGraphQLRepository(endpoint, authOptions, productRepository) {
3914
+ function CategoryHasuraGraphQLRepository(endpoint, authOptions, productRepository, categoryFilterRepository) {
3830
3915
  var _this = _super_1.call(this, {
3831
3916
  tableName: 'category',
3832
3917
  model: Category,
@@ -3862,7 +3947,17 @@
3862
3947
  },
3863
3948
  },
3864
3949
  },
3865
- 'filters',
3950
+ {
3951
+ filters: {
3952
+ columnName: 'filters',
3953
+ foreignKeyColumn: { filter_id: 'id' },
3954
+ fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
3955
+ bindPersistData: function (value) { return ({
3956
+ filters: { data: value.map(function (filter) { return ({ filter_id: filter.id }); }) },
3957
+ }); },
3958
+ 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; })) || []; },
3959
+ },
3960
+ },
3866
3961
  { createdAt: { columnName: 'created_at' } },
3867
3962
  { updatedAt: { columnName: 'updated_at' } },
3868
3963
  {
@@ -3887,6 +3982,7 @@
3887
3982
  ],
3888
3983
  }) || this;
3889
3984
  _this.productRepository = productRepository;
3985
+ _this.categoryFilterRepository = categoryFilterRepository;
3890
3986
  return _this;
3891
3987
  }
3892
3988
  CategoryHasuraGraphQLRepository.prototype.create = function (params) {
@@ -3929,25 +4025,25 @@
3929
4025
  update: { get: function () { return _super_1.prototype.update; } }
3930
4026
  });
3931
4027
  return __awaiter(this, void 0, void 0, function () {
3932
- var products, checkId, metadata, data, plainData, id, category, _c, _d, _e, _f;
3933
- return __generator(this, function (_g) {
3934
- switch (_g.label) {
4028
+ var products, checkId, metadata, filters, data, plainData, id, category, _c, _d, _e, _f, _g, _h;
4029
+ return __generator(this, function (_j) {
4030
+ switch (_j.label) {
3935
4031
  case 0:
3936
- products = params.products, checkId = params.id, metadata = params.metadata, data = __rest(params, ["products", "id", "metadata"]);
4032
+ products = params.products, checkId = params.id, metadata = params.metadata, filters = params.filters, data = __rest(params, ["products", "id", "metadata", "filters"]);
3937
4033
  plainData = this.paramsToPlain({ id: checkId });
3938
4034
  return [4 /*yield*/, this.getId(plainData.id)];
3939
4035
  case 1:
3940
- id = _g.sent();
4036
+ id = _j.sent();
3941
4037
  return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
3942
4038
  case 2:
3943
- category = _g.sent();
4039
+ category = _j.sent();
3944
4040
  _c = category;
3945
4041
  _d = products;
3946
4042
  if (!_d) return [3 /*break*/, 4];
3947
4043
  return [4 /*yield*/, this.updateProducts(+id, { products: products })];
3948
4044
  case 3:
3949
- _d = (_g.sent());
3950
- _g.label = 4;
4045
+ _d = (_j.sent());
4046
+ _j.label = 4;
3951
4047
  case 4:
3952
4048
  _c.products = _d;
3953
4049
  _e = category;
@@ -3955,10 +4051,19 @@
3955
4051
  if (!_f) return [3 /*break*/, 6];
3956
4052
  return [4 /*yield*/, this.updateMetadata(+id, { metadata: metadata })];
3957
4053
  case 5:
3958
- _f = (_g.sent());
3959
- _g.label = 6;
4054
+ _f = (_j.sent());
4055
+ _j.label = 6;
3960
4056
  case 6:
3961
4057
  _e.metadata = _f;
4058
+ _g = category;
4059
+ _h = filters;
4060
+ if (!_h) return [3 /*break*/, 8];
4061
+ return [4 /*yield*/, this.updateFilters(+id, { filters: filters })];
4062
+ case 7:
4063
+ _h = (_j.sent());
4064
+ _j.label = 8;
4065
+ case 8:
4066
+ _g.filters = _h;
3962
4067
  return [2 /*return*/, category];
3963
4068
  }
3964
4069
  });
@@ -4184,9 +4289,334 @@
4184
4289
  });
4185
4290
  });
4186
4291
  };
4292
+ CategoryHasuraGraphQLRepository.prototype.updateFilters = function (categoryId, _c) {
4293
+ var filters = _c.filters;
4294
+ return __awaiter(this, void 0, void 0, function () {
4295
+ var i, filtersList, i, hasFilter, newCategoryFilter, error_1, filtersList, i, hasFilter, newCategoryFilter, error_2;
4296
+ return __generator(this, function (_c) {
4297
+ switch (_c.label) {
4298
+ case 0:
4299
+ if (!('action' in filters && filters.action === 'remove' && filters.value.length)) return [3 /*break*/, 5];
4300
+ i = 0;
4301
+ _c.label = 1;
4302
+ case 1:
4303
+ if (!(i < filters.value.length)) return [3 /*break*/, 4];
4304
+ return [4 /*yield*/, this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filters.value[i].id)];
4305
+ case 2:
4306
+ _c.sent();
4307
+ _c.label = 3;
4308
+ case 3:
4309
+ i++;
4310
+ return [3 /*break*/, 1];
4311
+ case 4: return [2 /*return*/, []];
4312
+ case 5:
4313
+ if (!('action' in filters && filters.action === 'merge' && filters.value.length)) return [3 /*break*/, 15];
4314
+ filtersList = [];
4315
+ i = 0;
4316
+ _c.label = 6;
4317
+ case 6:
4318
+ if (!(i < filters.value.length)) return [3 /*break*/, 14];
4319
+ _c.label = 7;
4320
+ case 7:
4321
+ _c.trys.push([7, 12, , 13]);
4322
+ return [4 /*yield*/, this.categoryFilterRepository
4323
+ .find({
4324
+ filters: {
4325
+ categoryId: categoryId,
4326
+ filterId: filters.value[i].id,
4327
+ },
4328
+ })
4329
+ .then(function (data) { return data.data.shift(); })];
4330
+ case 8:
4331
+ hasFilter = _c.sent();
4332
+ if (!hasFilter) return [3 /*break*/, 9];
4333
+ filtersList.push(hasFilter);
4334
+ return [3 /*break*/, 11];
4335
+ case 9: return [4 /*yield*/, this.categoryFilterRepository.create({
4336
+ filterId: filters.value[i].id,
4337
+ categoryId: categoryId,
4338
+ })];
4339
+ case 10:
4340
+ newCategoryFilter = _c.sent();
4341
+ filtersList.push(newCategoryFilter);
4342
+ _c.label = 11;
4343
+ case 11: return [3 /*break*/, 13];
4344
+ case 12:
4345
+ error_1 = _c.sent();
4346
+ console.log('catch error: ', error_1);
4347
+ return [3 /*break*/, 13];
4348
+ case 13:
4349
+ i++;
4350
+ return [3 /*break*/, 6];
4351
+ case 14: return [2 /*return*/, filtersList];
4352
+ case 15:
4353
+ if (!(Array.isArray(filters) && filters.length)) return [3 /*break*/, 25];
4354
+ filtersList = [];
4355
+ i = 0;
4356
+ _c.label = 16;
4357
+ case 16:
4358
+ if (!(i < filters.length)) return [3 /*break*/, 24];
4359
+ _c.label = 17;
4360
+ case 17:
4361
+ _c.trys.push([17, 22, , 23]);
4362
+ return [4 /*yield*/, this.categoryFilterRepository
4363
+ .find({
4364
+ filters: {
4365
+ categoryId: categoryId,
4366
+ filterId: filters[i].id,
4367
+ },
4368
+ })
4369
+ .then(function (data) { return data.data.shift(); })];
4370
+ case 18:
4371
+ hasFilter = _c.sent();
4372
+ if (!hasFilter) return [3 /*break*/, 19];
4373
+ filtersList.push(hasFilter);
4374
+ return [3 /*break*/, 21];
4375
+ case 19: return [4 /*yield*/, this.categoryFilterRepository.create({
4376
+ filterId: filters[i].id,
4377
+ categoryId: categoryId,
4378
+ })];
4379
+ case 20:
4380
+ newCategoryFilter = _c.sent();
4381
+ filtersList.push(newCategoryFilter);
4382
+ _c.label = 21;
4383
+ case 21: return [3 /*break*/, 23];
4384
+ case 22:
4385
+ error_2 = _c.sent();
4386
+ console.log('catch error: ', error_2);
4387
+ return [3 /*break*/, 23];
4388
+ case 23:
4389
+ i++;
4390
+ return [3 /*break*/, 16];
4391
+ case 24: return [2 /*return*/, filtersList];
4392
+ case 25: return [2 /*return*/];
4393
+ }
4394
+ });
4395
+ });
4396
+ };
4187
4397
  return CategoryHasuraGraphQLRepository;
4188
4398
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4189
4399
 
4400
+ var FilterHasuraGraphQLRepository = /** @class */ (function (_super_1) {
4401
+ __extends(FilterHasuraGraphQLRepository, _super_1);
4402
+ function FilterHasuraGraphQLRepository(endpoint, authOptions, filterOptionRepository, categoryFilterRepository) {
4403
+ var _this = _super_1.call(this, {
4404
+ tableName: 'filter',
4405
+ model: Filter,
4406
+ endpoint: endpoint,
4407
+ authOptions: authOptions,
4408
+ fields: [
4409
+ 'id',
4410
+ 'description',
4411
+ 'slug',
4412
+ 'enabled',
4413
+ { createdAt: { columnName: 'created_at' } },
4414
+ { updatedAt: { columnName: 'updated_at' } },
4415
+ {
4416
+ options: {
4417
+ columnName: 'options',
4418
+ foreignKeyColumn: { filterId: 'id' },
4419
+ fields: [
4420
+ 'id',
4421
+ { filterId: { columnName: 'filter_id' } },
4422
+ 'description',
4423
+ { createdAt: { columnName: 'created_at' } },
4424
+ { updatedAt: { columnName: 'updated_at' } },
4425
+ ],
4426
+ },
4427
+ },
4428
+ ],
4429
+ }) || this;
4430
+ _this.filterOptionRepository = filterOptionRepository;
4431
+ _this.categoryFilterRepository = categoryFilterRepository;
4432
+ return _this;
4433
+ }
4434
+ FilterHasuraGraphQLRepository.prototype.update = function (params) {
4435
+ var _super = Object.create(null, {
4436
+ update: { get: function () { return _super_1.prototype.update; } }
4437
+ });
4438
+ return __awaiter(this, void 0, void 0, function () {
4439
+ var options, data, filter, _a;
4440
+ return __generator(this, function (_b) {
4441
+ switch (_b.label) {
4442
+ case 0:
4443
+ options = params.options, data = __rest(params, ["options"]);
4444
+ return [4 /*yield*/, _super.update.call(this, data)];
4445
+ case 1:
4446
+ filter = _b.sent();
4447
+ _a = filter;
4448
+ return [4 /*yield*/, this.updateOptions(+data.id, { options: options })];
4449
+ case 2:
4450
+ _a.options = _b.sent();
4451
+ return [2 /*return*/, filter];
4452
+ }
4453
+ });
4454
+ });
4455
+ };
4456
+ FilterHasuraGraphQLRepository.prototype.updateOptions = function (filterId, _a) {
4457
+ var options = _a.options;
4458
+ return __awaiter(this, void 0, void 0, function () {
4459
+ var i, filterOptions, i, hasFilter, error_1, newOption, filterOptions, i, hasFilter, error_2, newOption;
4460
+ return __generator(this, function (_a) {
4461
+ switch (_a.label) {
4462
+ case 0:
4463
+ if (!options)
4464
+ return [2 /*return*/, []];
4465
+ if (!('action' in options && options.action === 'remove' && options.value.length)) return [3 /*break*/, 5];
4466
+ i = 0;
4467
+ _a.label = 1;
4468
+ case 1:
4469
+ if (!(i < options.value.length)) return [3 /*break*/, 4];
4470
+ return [4 /*yield*/, this.filterOptionRepository.delete({ id: options.value[i].id })];
4471
+ case 2:
4472
+ _a.sent();
4473
+ _a.label = 3;
4474
+ case 3:
4475
+ i++;
4476
+ return [3 /*break*/, 1];
4477
+ case 4: return [2 /*return*/, []];
4478
+ case 5:
4479
+ if (!('action' in options && options.action === 'merge' && options.value.length)) return [3 /*break*/, 13];
4480
+ filterOptions = [];
4481
+ i = 0;
4482
+ _a.label = 6;
4483
+ case 6:
4484
+ if (!(i < options.value.length)) return [3 /*break*/, 12];
4485
+ _a.label = 7;
4486
+ case 7:
4487
+ _a.trys.push([7, 9, , 11]);
4488
+ return [4 /*yield*/, this.filterOptionRepository.get({ id: options.value[i].id })];
4489
+ case 8:
4490
+ hasFilter = _a.sent();
4491
+ if (hasFilter)
4492
+ filterOptions.push(hasFilter);
4493
+ return [3 /*break*/, 11];
4494
+ case 9:
4495
+ error_1 = _a.sent();
4496
+ return [4 /*yield*/, this.filterOptionRepository.create(Object.assign(Object.assign({}, options.value[i]), { filterId: filterId }))];
4497
+ case 10:
4498
+ newOption = _a.sent();
4499
+ filterOptions.push(newOption);
4500
+ return [3 /*break*/, 11];
4501
+ case 11:
4502
+ i++;
4503
+ return [3 /*break*/, 6];
4504
+ case 12: return [2 /*return*/, filterOptions];
4505
+ case 13:
4506
+ if (!(Array.isArray(options) && options.length)) return [3 /*break*/, 20];
4507
+ filterOptions = [];
4508
+ i = 0;
4509
+ _a.label = 14;
4510
+ case 14:
4511
+ if (!(i < options.length)) return [3 /*break*/, 20];
4512
+ _a.label = 15;
4513
+ case 15:
4514
+ _a.trys.push([15, 17, , 19]);
4515
+ return [4 /*yield*/, this.filterOptionRepository.get({ id: options[i].id })];
4516
+ case 16:
4517
+ hasFilter = _a.sent();
4518
+ if (hasFilter)
4519
+ filterOptions.push(hasFilter);
4520
+ return [3 /*break*/, 19];
4521
+ case 17:
4522
+ error_2 = _a.sent();
4523
+ return [4 /*yield*/, this.filterOptionRepository.create(Object.assign(Object.assign({}, options[i]), { filterId: filterId }))];
4524
+ case 18:
4525
+ newOption = _a.sent();
4526
+ filterOptions.push(newOption);
4527
+ return [3 /*break*/, 19];
4528
+ case 19:
4529
+ i++;
4530
+ return [3 /*break*/, 14];
4531
+ case 20: return [2 /*return*/, []];
4532
+ }
4533
+ });
4534
+ });
4535
+ };
4536
+ FilterHasuraGraphQLRepository.prototype.delete = function (params) {
4537
+ var _super = Object.create(null, {
4538
+ delete: { get: function () { return _super_1.prototype.delete; } }
4539
+ });
4540
+ return __awaiter(this, void 0, void 0, function () {
4541
+ var options, data, categoryFilters;
4542
+ return __generator(this, function (_a) {
4543
+ switch (_a.label) {
4544
+ case 0:
4545
+ options = params.options, data = __rest(params, ["options"]);
4546
+ return [4 /*yield*/, this.categoryFilterRepository
4547
+ .find({
4548
+ filters: {
4549
+ filterId: +data.id,
4550
+ },
4551
+ })
4552
+ .then(function (result) { return result.data; })];
4553
+ case 1:
4554
+ categoryFilters = _a.sent();
4555
+ if (categoryFilters.length)
4556
+ throw new Error('Erro: o filtro está associado a uma ou mais categoria(s)');
4557
+ return [4 /*yield*/, this.deleteOptions(options)];
4558
+ case 2:
4559
+ _a.sent();
4560
+ return [4 /*yield*/, _super.delete.call(this, { id: +data.id })];
4561
+ case 3:
4562
+ _a.sent();
4563
+ return [2 /*return*/];
4564
+ }
4565
+ });
4566
+ });
4567
+ };
4568
+ FilterHasuraGraphQLRepository.prototype.deleteOptions = function (options) {
4569
+ return __awaiter(this, void 0, void 0, function () {
4570
+ var i, error_3;
4571
+ return __generator(this, function (_a) {
4572
+ switch (_a.label) {
4573
+ case 0:
4574
+ i = 0;
4575
+ _a.label = 1;
4576
+ case 1:
4577
+ if (!(i < options.length)) return [3 /*break*/, 6];
4578
+ _a.label = 2;
4579
+ case 2:
4580
+ _a.trys.push([2, 4, , 5]);
4581
+ return [4 /*yield*/, this.filterOptionRepository.delete({ id: options[i].id })];
4582
+ case 3:
4583
+ _a.sent();
4584
+ return [3 /*break*/, 5];
4585
+ case 4:
4586
+ error_3 = _a.sent();
4587
+ console.log(error_3);
4588
+ return [3 /*break*/, 5];
4589
+ case 5:
4590
+ i++;
4591
+ return [3 /*break*/, 1];
4592
+ case 6: return [2 /*return*/];
4593
+ }
4594
+ });
4595
+ });
4596
+ };
4597
+ return FilterHasuraGraphQLRepository;
4598
+ }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4599
+
4600
+ var FilterOptionHasuraGraphQLRepository = /** @class */ (function (_super) {
4601
+ __extends(FilterOptionHasuraGraphQLRepository, _super);
4602
+ function FilterOptionHasuraGraphQLRepository(endpoint, authOptions) {
4603
+ return _super.call(this, {
4604
+ tableName: 'filter_option',
4605
+ model: FilterOption,
4606
+ endpoint: endpoint,
4607
+ authOptions: authOptions,
4608
+ fields: [
4609
+ 'id',
4610
+ 'description',
4611
+ { filterId: { columnName: 'filter_id' } },
4612
+ { createdAt: { columnName: 'created_at' } },
4613
+ { updatedAt: { columnName: 'updated_at' } },
4614
+ ],
4615
+ }) || this;
4616
+ }
4617
+ return FilterOptionHasuraGraphQLRepository;
4618
+ }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4619
+
4190
4620
  var ProductHasuraGraphQLRepository = /** @class */ (function (_super_1) {
4191
4621
  __extends(ProductHasuraGraphQLRepository, _super_1);
4192
4622
  function ProductHasuraGraphQLRepository(endpoint, authOptions) {
@@ -4291,6 +4721,7 @@
4291
4721
  'weight',
4292
4722
  'gender',
4293
4723
  { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
4724
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
4294
4725
  { isKit: { columnName: 'is_kit' } },
4295
4726
  { createdAt: { columnName: 'created_at' } },
4296
4727
  { updatedAt: { columnName: 'updated_at' } },
@@ -4854,6 +5285,26 @@
4854
5285
  });
4855
5286
  });
4856
5287
  };
5288
+ ProductHasuraGraphQLRepository.prototype.cleanShoppingCountFromIds = function (ids) {
5289
+ return __awaiter(this, void 0, void 0, function () {
5290
+ return __generator(this, function (_c) {
5291
+ switch (_c.label) {
5292
+ case 0: return [4 /*yield*/, this.mutation('update_product', ['affected_rows'], {
5293
+ where: {
5294
+ value: { id: { _nin: ids } },
5295
+ type: 'product_bool_exp',
5296
+ required: true,
5297
+ },
5298
+ _set: {
5299
+ value: { shopping_count: 0 },
5300
+ type: 'product_set_input',
5301
+ },
5302
+ })];
5303
+ case 1: return [2 /*return*/, _c.sent()];
5304
+ }
5305
+ });
5306
+ });
5307
+ };
4857
5308
  return ProductHasuraGraphQLRepository;
4858
5309
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4859
5310
 
@@ -5122,6 +5573,8 @@
5122
5573
  exports.CampaignHashtag = CampaignHashtag;
5123
5574
  exports.CampaignHashtagFirestoreRepository = CampaignHashtagFirestoreRepository;
5124
5575
  exports.Category = Category;
5576
+ exports.CategoryFilter = CategoryFilter;
5577
+ exports.CategoryFilterHasuraGraphQLRepository = CategoryFilterHasuraGraphQLRepository;
5125
5578
  exports.CategoryFirestoreRepository = CategoryFirestoreRepository;
5126
5579
  exports.CategoryHasuraGraphQL = CategoryHasuraGraphQL;
5127
5580
  exports.CategoryHasuraGraphQLRepository = CategoryHasuraGraphQLRepository;
@@ -5133,6 +5586,10 @@
5133
5586
  exports.CouponFirestoreRepository = CouponFirestoreRepository;
5134
5587
  exports.DuplicatedResultsError = DuplicatedResultsError;
5135
5588
  exports.Edition = Edition;
5589
+ exports.Filter = Filter;
5590
+ exports.FilterHasuraGraphQLRepository = FilterHasuraGraphQLRepository;
5591
+ exports.FilterOption = FilterOption;
5592
+ exports.FilterOptionHasuraGraphQLRepository = FilterOptionHasuraGraphQLRepository;
5136
5593
  exports.Home = Home;
5137
5594
  exports.HomeFirestoreRepository = HomeFirestoreRepository;
5138
5595
  exports.InvalidArgumentError = InvalidArgumentError;