@infrab4a/connect 3.15.0-beta.1 → 3.16.0-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 (54) hide show
  1. package/bundles/infrab4a-connect.umd.js +706 -148
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/catalog/models/category-base.d.ts +30 -0
  4. package/domain/catalog/models/category-filter.d.ts +2 -0
  5. package/domain/catalog/models/category-for-product.d.ts +5 -0
  6. package/domain/catalog/models/category.d.ts +5 -27
  7. package/domain/catalog/models/index.d.ts +1 -0
  8. package/domain/catalog/models/kit-product.d.ts +3 -3
  9. package/domain/catalog/models/product-base.d.ts +40 -0
  10. package/domain/catalog/models/product-for-category.d.ts +7 -0
  11. package/domain/catalog/models/product-for-kit.d.ts +7 -0
  12. package/domain/catalog/models/product.d.ts +5 -40
  13. package/domain/catalog/models/wishlist.d.ts +6 -0
  14. package/domain/catalog/repositories/category-filter.repository.d.ts +1 -0
  15. package/domain/catalog/repositories/index.d.ts +1 -0
  16. package/domain/catalog/repositories/product.repository.d.ts +1 -1
  17. package/domain/catalog/repositories/wishlist.repository.d.ts +6 -0
  18. package/domain/generic/repository/find.repository.d.ts +1 -0
  19. package/domain/generic/repository/types/repository-find-result.type.d.ts +3 -0
  20. package/esm2015/domain/catalog/models/category-base.js +18 -0
  21. package/esm2015/domain/catalog/models/category-filter.js +6 -1
  22. package/esm2015/domain/catalog/models/category-for-product.js +7 -0
  23. package/esm2015/domain/catalog/models/category.js +6 -10
  24. package/esm2015/domain/catalog/models/index.js +2 -1
  25. package/esm2015/domain/catalog/models/kit-product.js +6 -6
  26. package/esm2015/domain/catalog/models/product-base.js +25 -0
  27. package/esm2015/domain/catalog/models/product-for-category.js +14 -0
  28. package/esm2015/domain/catalog/models/product-for-kit.js +14 -0
  29. package/esm2015/domain/catalog/models/product.js +6 -24
  30. package/esm2015/domain/catalog/models/wishlist.js +7 -0
  31. package/esm2015/domain/catalog/repositories/category-filter.repository.js +1 -1
  32. package/esm2015/domain/catalog/repositories/index.js +2 -1
  33. package/esm2015/domain/catalog/repositories/product.repository.js +1 -1
  34. package/esm2015/domain/catalog/repositories/wishlist.repository.js +2 -0
  35. package/esm2015/domain/generic/repository/find.repository.js +1 -1
  36. package/esm2015/domain/generic/repository/types/repository-find-result.type.js +1 -1
  37. package/esm2015/infra/elasticsearch/indexes/products-index.js +2 -2
  38. package/esm2015/infra/hasura-graphql/mixins/helpers/bind-filter-query.helper.js +2 -2
  39. package/esm2015/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.js +44 -14
  40. package/esm2015/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.js +52 -1
  41. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +36 -50
  42. package/esm2015/infra/hasura-graphql/repositories/catalog/index.js +2 -1
  43. package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +2 -2
  44. package/esm2015/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.js +252 -0
  45. package/esm2015/infra/hasura-graphql/types/graphql.repository.type.js +1 -1
  46. package/fesm2015/infrab4a-connect.js +469 -104
  47. package/fesm2015/infrab4a-connect.js.map +1 -1
  48. package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +3 -2
  49. package/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +2 -2
  50. package/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +1 -0
  51. package/infra/hasura-graphql/repositories/catalog/index.d.ts +1 -0
  52. package/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +27 -0
  53. package/infra/hasura-graphql/types/graphql.repository.type.d.ts +4 -3
  54. package/package.json +1 -1
@@ -1193,19 +1193,93 @@ class Filter extends BaseModel {
1193
1193
  }
1194
1194
  }
1195
1195
 
1196
- class Category extends BaseModel {
1196
+ class CategoryBase extends BaseModel {
1197
1197
  static get identifiersFields() {
1198
1198
  return ['id'];
1199
1199
  }
1200
1200
  }
1201
1201
  __decorate([
1202
- Type(() => Category),
1203
- __metadata("design:type", Category)
1204
- ], Category.prototype, "parent", void 0);
1202
+ Type(() => CategoryBase),
1203
+ __metadata("design:type", CategoryBase)
1204
+ ], CategoryBase.prototype, "parent", void 0);
1205
1205
  __decorate([
1206
1206
  Type(() => Filter),
1207
1207
  __metadata("design:type", Array)
1208
- ], Category.prototype, "filters", void 0);
1208
+ ], CategoryBase.prototype, "filters", void 0);
1209
+
1210
+ class CategoryForProduct extends CategoryBase {
1211
+ static get identifiersFields() {
1212
+ return ['id'];
1213
+ }
1214
+ }
1215
+
1216
+ class ProductBase extends BaseModel {
1217
+ get evaluation() {
1218
+ return {
1219
+ reviews: this.reviews,
1220
+ count: this.reviewsTotal,
1221
+ rating: this.rate,
1222
+ };
1223
+ }
1224
+ set evaluation(evaluation) {
1225
+ if (!evaluation) {
1226
+ this.reviews = null;
1227
+ this.reviewsTotal = null;
1228
+ this.rate = null;
1229
+ return;
1230
+ }
1231
+ this.reviews = evaluation.reviews || this.reviews;
1232
+ this.reviewsTotal = evaluation.count || this.reviewsTotal;
1233
+ this.rate = evaluation.rating || this.rate;
1234
+ }
1235
+ static get identifiersFields() {
1236
+ return ['id'];
1237
+ }
1238
+ }
1239
+
1240
+ class ProductForKit extends ProductBase {
1241
+ static get identifiersFields() {
1242
+ return ['id'];
1243
+ }
1244
+ }
1245
+ __decorate([
1246
+ Type(() => CategoryForProduct),
1247
+ __metadata("design:type", CategoryForProduct)
1248
+ ], ProductForKit.prototype, "category", void 0);
1249
+
1250
+ class KitProduct extends BaseModel {
1251
+ static get identifiersFields() {
1252
+ return ['productId', 'kitProductId'];
1253
+ }
1254
+ }
1255
+ __decorate([
1256
+ Type(() => ProductForKit),
1257
+ __metadata("design:type", ProductForKit)
1258
+ ], KitProduct.prototype, "kit", void 0);
1259
+ __decorate([
1260
+ Type(() => ProductForKit),
1261
+ __metadata("design:type", ProductForKit)
1262
+ ], KitProduct.prototype, "product", void 0);
1263
+
1264
+ class ProductForCategory extends ProductBase {
1265
+ static get identifiersFields() {
1266
+ return ['id'];
1267
+ }
1268
+ }
1269
+ __decorate([
1270
+ Type(() => KitProduct),
1271
+ __metadata("design:type", Array)
1272
+ ], ProductForCategory.prototype, "kitProducts", void 0);
1273
+
1274
+ class Category extends CategoryBase {
1275
+ static get identifiersFields() {
1276
+ return ['id'];
1277
+ }
1278
+ }
1279
+ __decorate([
1280
+ Type(() => ProductForCategory),
1281
+ __metadata("design:type", Array)
1282
+ ], Category.prototype, "childrenProducts", void 0);
1209
1283
 
1210
1284
  class CategoryCollectionChildren extends BaseModel {
1211
1285
  static get identifiersFields() {
@@ -1226,6 +1300,10 @@ __decorate([
1226
1300
  Type(() => Filter),
1227
1301
  __metadata("design:type", Filter)
1228
1302
  ], CategoryFilter.prototype, "filter", void 0);
1303
+ __decorate([
1304
+ Type(() => Category),
1305
+ __metadata("design:type", Category)
1306
+ ], CategoryFilter.prototype, "category", void 0);
1229
1307
 
1230
1308
  var GenderDestination;
1231
1309
  (function (GenderDestination) {
@@ -1248,55 +1326,29 @@ class FilterOption extends BaseModel {
1248
1326
  }
1249
1327
  }
1250
1328
 
1251
- class Product extends BaseModel {
1252
- get evaluation() {
1253
- return {
1254
- reviews: this.reviews,
1255
- count: this.reviewsTotal,
1256
- rating: this.rate,
1257
- };
1258
- }
1259
- set evaluation(evaluation) {
1260
- if (!evaluation) {
1261
- this.reviews = null;
1262
- this.reviewsTotal = null;
1263
- this.rate = null;
1264
- return;
1265
- }
1266
- this.reviews = evaluation.reviews || this.reviews;
1267
- this.reviewsTotal = evaluation.count || this.reviewsTotal;
1268
- this.rate = evaluation.rating || this.rate;
1269
- }
1329
+ class Product extends ProductBase {
1270
1330
  static get identifiersFields() {
1271
1331
  return ['id'];
1272
1332
  }
1273
1333
  }
1274
1334
  __decorate([
1275
- Type(() => Category),
1276
- __metadata("design:type", Category)
1335
+ Type(() => CategoryForProduct),
1336
+ __metadata("design:type", CategoryForProduct)
1277
1337
  ], Product.prototype, "category", void 0);
1278
1338
  __decorate([
1279
1339
  Type(() => KitProduct),
1280
1340
  __metadata("design:type", Array)
1281
1341
  ], Product.prototype, "kitProducts", void 0);
1282
1342
 
1283
- class KitProduct extends BaseModel {
1343
+ class Variant extends BaseModel {
1284
1344
  static get identifiersFields() {
1285
- return ['productId', 'kitProductId'];
1345
+ return ['id', 'productId'];
1286
1346
  }
1287
1347
  }
1288
- __decorate([
1289
- Type(() => Product),
1290
- __metadata("design:type", Product)
1291
- ], KitProduct.prototype, "kit", void 0);
1292
- __decorate([
1293
- Type(() => Product),
1294
- __metadata("design:type", Product)
1295
- ], KitProduct.prototype, "product", void 0);
1296
1348
 
1297
- class Variant extends BaseModel {
1349
+ class Wishlist extends Category {
1298
1350
  static get identifiersFields() {
1299
- return ['id', 'productId'];
1351
+ return ['id'];
1300
1352
  }
1301
1353
  }
1302
1354
 
@@ -1668,7 +1720,7 @@ class ProductsIndex {
1668
1720
  }
1669
1721
  search(searchTerm, total, shop) {
1670
1722
  return __awaiter(this, void 0, void 0, function* () {
1671
- const size = total >= 10 ? 500 : 9;
1723
+ const size = total || 9;
1672
1724
  const fields = [
1673
1725
  'EAN',
1674
1726
  'brand',
@@ -2759,7 +2811,7 @@ BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
2759
2811
  const fieldOptions = AttributeOptionHelper.FindByAttribute(key, (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || fields);
2760
2812
  const columnName = fieldOptions.columnName;
2761
2813
  const columnFields = fieldOptions.fields;
2762
- return Object.assign(Object.assign({}, variables), { [columnName]: BindFilterQueryHelper.BuildWhereSentence(key, options[key], columnFields || []) });
2814
+ return Object.assign(Object.assign({}, variables), { [columnName]: BindFilterQueryHelper.BuildWhereSentence(key, options[key], (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || columnFields || fields) });
2763
2815
  }, {});
2764
2816
  if (!Array.isArray(options) && !isNil(fieldSentenceOptions.fields))
2765
2817
  return {
@@ -3170,17 +3222,27 @@ const withFindHasuraGraphQL = (MixinBase) => {
3170
3222
  : []),
3171
3223
  ];
3172
3224
  };
3225
+ this.bindDistinctAttributes = (distinct, fields) => this.bindAttributesToColumns(distinct, fields);
3173
3226
  this.bindAttributesToColumns = (attributes, fields) => attributes.map((attr) => {
3174
3227
  var _a;
3175
3228
  return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
3176
3229
  });
3177
3230
  }
3178
3231
  find(params) {
3179
- var _a, _b, _c;
3232
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3180
3233
  return __awaiter(this, void 0, void 0, function* () {
3181
3234
  this.logger = DebugHelper.from(this, 'find');
3182
3235
  const { filters, limits, orderBy, options } = params || {};
3183
3236
  const enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
3237
+ const variablesFilters = isNil(filters)
3238
+ ? {}
3239
+ : {
3240
+ where: {
3241
+ value: BindFilterQueryHelper.MakeGraphQLWhere(filters, this.fields),
3242
+ type: `${this.tableName}_bool_exp`,
3243
+ required: true,
3244
+ },
3245
+ };
3184
3246
  const variablesCount = Object.assign(Object.assign({}, (isNil(orderBy)
3185
3247
  ? {}
3186
3248
  : {
@@ -3189,15 +3251,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
3189
3251
  list: true,
3190
3252
  value: this.bindOrderByAttributes(orderBy, this.fields),
3191
3253
  },
3192
- })), (isNil(filters)
3193
- ? {}
3194
- : {
3195
- where: {
3196
- value: BindFilterQueryHelper.MakeGraphQLWhere(filters, this.fields),
3197
- type: `${this.tableName}_bool_exp`,
3198
- required: true,
3199
- },
3200
- }));
3254
+ })), variablesFilters);
3201
3255
  const variables = Object.assign(Object.assign({}, (isNil(limits) ? {} : limits)), variablesCount);
3202
3256
  const aggregateFields = [
3203
3257
  ...(enableCount ? ['count'] : []),
@@ -3229,23 +3283,51 @@ const withFindHasuraGraphQL = (MixinBase) => {
3229
3283
  },
3230
3284
  ]
3231
3285
  : []),
3286
+ ...((!((_b = params.limits) === null || _b === void 0 ? void 0 : _b.offset) &&
3287
+ ((_d = (_c = params.options) === null || _c === void 0 ? void 0 : _c.distinct) === null || _d === void 0 ? void 0 : _d.map((distinct) => {
3288
+ var _a, _b;
3289
+ const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3290
+ const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
3291
+ return {
3292
+ operation: {
3293
+ name: `${this.tableName}`,
3294
+ alias: `${this.tableName}_${distinct}_distinct`,
3295
+ },
3296
+ fields: [distinctOption],
3297
+ variables: Object.assign(Object.assign({}, variablesFilters), { [`${this.tableName}_${fieldName}_distinct`]: {
3298
+ type: `${this.tableName}_select_column!`,
3299
+ list: true,
3300
+ value: fieldName,
3301
+ name: 'distinct_on',
3302
+ } }),
3303
+ };
3304
+ }))) ||
3305
+ []),
3232
3306
  ]);
3233
3307
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
3234
- return Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_b = options === null || options === void 0 ? void 0 : options.minimal) === null || _b === void 0 ? void 0 : _b.length)
3308
+ return Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_e = options === null || options === void 0 ? void 0 : options.minimal) === null || _e === void 0 ? void 0 : _e.length)
3235
3309
  ? {
3236
3310
  minimal: options.minimal.reduce((minimals, current) => {
3237
3311
  var _a;
3238
3312
  return (Object.assign(Object.assign({}, minimals), set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
3239
3313
  }, {}),
3240
3314
  }
3241
- : {})), (((_c = options === null || options === void 0 ? void 0 : options.maximum) === null || _c === void 0 ? void 0 : _c.length)
3315
+ : {})), (((_f = options === null || options === void 0 ? void 0 : options.maximum) === null || _f === void 0 ? void 0 : _f.length)
3242
3316
  ? {
3243
3317
  maximum: options.maximum.reduce((maximums, current) => {
3244
3318
  var _a;
3245
3319
  return (Object.assign(Object.assign({}, maximums), set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
3246
3320
  }, {}),
3247
3321
  }
3248
- : {}));
3322
+ : {})), (!((_g = params.limits) === null || _g === void 0 ? void 0 : _g.offset) &&
3323
+ ((_h = options === null || options === void 0 ? void 0 : options.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
3324
+ distinct: options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
3325
+ var _a, _b;
3326
+ const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
3327
+ const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
3328
+ return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
3329
+ }, {}),
3330
+ }));
3249
3331
  });
3250
3332
  }
3251
3333
  };
@@ -3358,9 +3440,60 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
3358
3440
  ],
3359
3441
  },
3360
3442
  },
3443
+ {
3444
+ category: {
3445
+ columnName: 'category',
3446
+ foreignKeyColumn: { id: 'categoryId' },
3447
+ fields: [
3448
+ 'id',
3449
+ 'description',
3450
+ {
3451
+ products: {
3452
+ columnName: 'products',
3453
+ fields: ['product_id'],
3454
+ from: (value) => value.map((product) => product.product_id.toString()),
3455
+ to: (productIds) => productIds.map((productId) => ({
3456
+ product_id: +productId,
3457
+ })),
3458
+ },
3459
+ },
3460
+ {
3461
+ childrenProducts: {
3462
+ columnName: 'children_products',
3463
+ foreignKeyColumn: { category_id: 'id' },
3464
+ fields: [
3465
+ 'id',
3466
+ 'name',
3467
+ 'slug',
3468
+ {
3469
+ categories: {
3470
+ columnName: 'categories',
3471
+ fields: ['category_id'],
3472
+ bindPersistData: (value) => ({
3473
+ categories: { data: value.map((category) => ({ category_id: +category })) },
3474
+ }),
3475
+ to: (categories) => categories.map((categoryId) => +categoryId),
3476
+ from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || [],
3477
+ },
3478
+ },
3479
+ ],
3480
+ },
3481
+ },
3482
+ ],
3483
+ },
3484
+ },
3361
3485
  ],
3362
3486
  });
3363
3487
  }
3488
+ deleteByCategory(categoryId) {
3489
+ return this.mutation('delete_category_filter', ['affected_rows'], {
3490
+ where: {
3491
+ type: 'category_filter_bool_exp',
3492
+ required: true,
3493
+ value: { category_id: { _eq: categoryId } },
3494
+ },
3495
+ });
3496
+ }
3364
3497
  deleteByCategoryAndFilter(categoryId, filterId) {
3365
3498
  return this.mutation('delete_category_filter', ['affected_rows'], {
3366
3499
  where: {
@@ -3443,6 +3576,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
3443
3576
  },
3444
3577
  },
3445
3578
  { isCollection: { columnName: 'is_collection' } },
3579
+ { isWishlist: { columnName: 'is_wishlist' } },
3446
3580
  'reference',
3447
3581
  { parentId: { columnName: 'parent_id' } },
3448
3582
  {
@@ -3463,7 +3597,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
3463
3597
  });
3464
3598
  return __awaiter(this, void 0, void 0, function* () {
3465
3599
  const { metadata } = params, data = __rest(params, ["metadata"]);
3466
- return _super.create.call(this, Object.assign(Object.assign({}, data), { metadata: metadata || { description: null, title: null } }));
3600
+ return _super.create.call(this, Object.assign(Object.assign({}, data), { isWishlist: false, metadata: metadata || { description: null, title: null } }));
3467
3601
  });
3468
3602
  }
3469
3603
  get(identifiers) {
@@ -3485,7 +3619,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
3485
3619
  const { products, id: checkId, metadata, filters } = params, data = __rest(params, ["products", "id", "metadata", "filters"]);
3486
3620
  const plainData = this.paramsToPlain({ id: checkId });
3487
3621
  const id = yield this.getId(plainData.id);
3488
- const category = yield _super.update.call(this, Object.assign({ id }, data));
3622
+ const category = yield _super.update.call(this, Object.assign(Object.assign({ id }, data), { isWishlist: false }));
3489
3623
  category.products = products && (yield this.updateProducts(+id, { products }));
3490
3624
  category.metadata = metadata && (yield this.updateMetadata(+id, { metadata }));
3491
3625
  category.filters = filters && (yield this.updateFilters(+id, { filters }));
@@ -3501,6 +3635,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
3501
3635
  slug,
3502
3636
  shops: { operator: Where.IN, value: [shop] },
3503
3637
  published: { operator: Where.EQUALS, value: true },
3638
+ isWishlist: { operator: Where.EQUALS, value: false },
3504
3639
  },
3505
3640
  options: {
3506
3641
  enableCount: false,
@@ -3521,6 +3656,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
3521
3656
  filters: {
3522
3657
  shops: { operator: Where.IN, value: [shop] },
3523
3658
  published: { operator: Where.EQUALS, value: true },
3659
+ isWishlist: { operator: Where.EQUALS, value: false },
3524
3660
  },
3525
3661
  options: {
3526
3662
  enableCount: false,
@@ -3665,59 +3801,42 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
3665
3801
  }
3666
3802
  if ('action' in filters && filters.action === 'merge' && filters.value.length) {
3667
3803
  let filtersList = [];
3668
- for (let i = 0; i < filters.value.length; i++) {
3669
- try {
3670
- const hasFilter = yield this.categoryFilterRepository
3671
- .find({
3672
- filters: {
3673
- categoryId,
3674
- filterId: filters.value[i].id,
3675
- },
3676
- })
3677
- .then((data) => data.data.shift());
3678
- if (hasFilter) {
3679
- filtersList.push(hasFilter);
3680
- }
3681
- else {
3682
- const newCategoryFilter = yield this.categoryFilterRepository.create({
3683
- filterId: filters.value[i].id,
3684
- categoryId,
3685
- });
3686
- filtersList.push(newCategoryFilter);
3687
- }
3688
- }
3689
- catch (error) {
3690
- console.log('catch error: ', error);
3804
+ const currentFilters = yield this.categoryFilterRepository
3805
+ .find({
3806
+ filters: {
3807
+ categoryId,
3808
+ },
3809
+ })
3810
+ .then((res) => res.data);
3811
+ const currentFiltersId = currentFilters.map((f) => f.id);
3812
+ const filtersUpdatedId = filters.value.map((f) => f.id);
3813
+ const filterToBeDeleted = currentFiltersId.filter((c) => !filtersUpdatedId.includes(c));
3814
+ const filterToBeInserted = filtersUpdatedId.filter((c) => !currentFiltersId.includes(c));
3815
+ for (const filter of filterToBeDeleted) {
3816
+ const index = currentFilters.findIndex((f) => f.id == filter);
3817
+ if (index != -1) {
3818
+ currentFilters.splice(index, 1);
3691
3819
  }
3820
+ yield this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filter);
3692
3821
  }
3693
- return filtersList;
3822
+ for (const filter of filterToBeInserted) {
3823
+ const newCategoryFilter = yield this.categoryFilterRepository.create({
3824
+ filterId: filter,
3825
+ categoryId,
3826
+ });
3827
+ filtersList.push(newCategoryFilter);
3828
+ }
3829
+ return [...currentFilters, ...filtersList];
3694
3830
  }
3695
3831
  if (Array.isArray(filters) && filters.length) {
3832
+ yield this.categoryFilterRepository.deleteByCategory(categoryId);
3696
3833
  let filtersList = [];
3697
3834
  for (let i = 0; i < filters.length; i++) {
3698
- try {
3699
- const hasFilter = yield this.categoryFilterRepository
3700
- .find({
3701
- filters: {
3702
- categoryId,
3703
- filterId: filters[i].id,
3704
- },
3705
- })
3706
- .then((data) => data.data.shift());
3707
- if (hasFilter) {
3708
- filtersList.push(hasFilter);
3709
- }
3710
- else {
3711
- const newCategoryFilter = yield this.categoryFilterRepository.create({
3712
- filterId: filters[i].id,
3713
- categoryId,
3714
- });
3715
- filtersList.push(newCategoryFilter);
3716
- }
3717
- }
3718
- catch (error) {
3719
- console.log('catch error: ', error);
3720
- }
3835
+ const newCategoryFilter = yield this.categoryFilterRepository.create({
3836
+ filterId: filters[i].id,
3837
+ categoryId,
3838
+ });
3839
+ filtersList.push(newCategoryFilter);
3721
3840
  }
3722
3841
  return filtersList;
3723
3842
  }
@@ -4180,7 +4299,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
4180
4299
  }
4181
4300
  findCatalog(params, mainGender) {
4182
4301
  return __awaiter(this, void 0, void 0, function* () {
4183
- return this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true }), orderBy: Object.assign({ hasStock: 'desc', intGender: mainGender === 'female' ? 'desc' : 'asc' }, omit(params.orderBy, ['hasStock', 'intGender'])) }));
4302
+ return this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true }), orderBy: Object.assign(Object.assign({ hasStock: 'desc' }, (!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' })), omit(params.orderBy, ['hasStock', 'intGender'])) }));
4184
4303
  });
4185
4304
  }
4186
4305
  updateCategories(productId, { categories }) {
@@ -4489,9 +4608,255 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
4489
4608
  }
4490
4609
  }
4491
4610
 
4611
+ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
4612
+ constructor(endpoint, authOptions, categoryFilterRepository) {
4613
+ super({
4614
+ tableName: 'category',
4615
+ model: Wishlist,
4616
+ endpoint,
4617
+ authOptions,
4618
+ fields: [
4619
+ { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
4620
+ { firestoreId: { columnName: 'firestore_id' } },
4621
+ 'name',
4622
+ 'description',
4623
+ 'image',
4624
+ 'published',
4625
+ 'shop',
4626
+ { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
4627
+ 'slug',
4628
+ { brandCategory: { columnName: 'brand_category' } },
4629
+ { brandCategoryBanner: { columnName: 'brand_banner' } },
4630
+ { brandCategoryBannerMobile: { columnName: 'brand_banner_mobile' } },
4631
+ { brandLogo: { columnName: 'brand_logo' } },
4632
+ { brandCondition: { columnName: 'brand_condition' } },
4633
+ {
4634
+ conditions: {
4635
+ columnName: 'tag_condition',
4636
+ type: HasuraGraphQLColumnType.Jsonb,
4637
+ from: (tags, row) => ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }),
4638
+ bindPersistData: (value) => {
4639
+ return {
4640
+ brand_condition: value.brand,
4641
+ tag_condition: (value === null || value === void 0 ? void 0 : value.tags) || [],
4642
+ };
4643
+ },
4644
+ bindFindFilter: (sentence) => {
4645
+ return Object.assign(Object.assign({}, (sentence.brand ? { brand_condition: sentence.brand } : {})), (sentence.tags ? { tag_condition: sentence.tags } : {}));
4646
+ },
4647
+ },
4648
+ },
4649
+ {
4650
+ filters: {
4651
+ columnName: 'filters',
4652
+ foreignKeyColumn: { filter_id: 'id' },
4653
+ fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
4654
+ bindPersistData: (value) => ({
4655
+ filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
4656
+ }),
4657
+ from: (filters) => (filters === null || filters === void 0 ? void 0 : filters.map((filter) => filter === null || filter === void 0 ? void 0 : filter.filter)) || [],
4658
+ },
4659
+ },
4660
+ { createdAt: { columnName: 'created_at' } },
4661
+ { updatedAt: { columnName: 'updated_at' } },
4662
+ {
4663
+ products: {
4664
+ columnName: 'products',
4665
+ fields: ['product_id'],
4666
+ from: (value) => value.map((product) => product.product_id.toString()),
4667
+ to: (productIds) => productIds.map((productId) => ({
4668
+ product_id: +productId,
4669
+ })),
4670
+ },
4671
+ },
4672
+ {
4673
+ metadata: {
4674
+ columnName: 'metadata',
4675
+ fields: ['title', 'description'],
4676
+ bindPersistData: (value) => ({
4677
+ metadata: { data: value },
4678
+ }),
4679
+ },
4680
+ },
4681
+ { isCollection: { columnName: 'is_collection' } },
4682
+ { isWishlist: { columnName: 'is_wishlist' } },
4683
+ 'reference',
4684
+ { parentId: { columnName: 'parent_id' } },
4685
+ {
4686
+ parent: {
4687
+ columnName: 'parent',
4688
+ foreignKeyColumn: { id: 'parentId' },
4689
+ fields: ['id', 'name', 'reference', 'slug'],
4690
+ },
4691
+ },
4692
+ { personId: { columnName: 'person_id' } },
4693
+ ],
4694
+ });
4695
+ this.categoryFilterRepository = categoryFilterRepository;
4696
+ }
4697
+ create(params) {
4698
+ const _super = Object.create(null, {
4699
+ create: { get: () => super.create }
4700
+ });
4701
+ return __awaiter(this, void 0, void 0, function* () {
4702
+ const { metadata } = params, data = __rest(params, ["metadata"]);
4703
+ return _super.create.call(this, Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadata: metadata || { description: data.description, title: data.name } }));
4704
+ });
4705
+ }
4706
+ get(identifiers) {
4707
+ const _super = Object.create(null, {
4708
+ get: { get: () => super.get }
4709
+ });
4710
+ return __awaiter(this, void 0, void 0, function* () {
4711
+ const data = yield _super.get.call(this, identifiers);
4712
+ if (!data.isWishlist)
4713
+ throw new NotFoundError(`Category with id ${identifiers.id} is not a wishlist`);
4714
+ return data;
4715
+ });
4716
+ }
4717
+ update(params) {
4718
+ const _super = Object.create(null, {
4719
+ update: { get: () => super.update }
4720
+ });
4721
+ return __awaiter(this, void 0, void 0, function* () {
4722
+ const { products, id: checkId, metadata, filters } = params, data = __rest(params, ["products", "id", "metadata", "filters"]);
4723
+ const plainData = this.paramsToPlain({ id: checkId });
4724
+ const id = plainData.id;
4725
+ const category = yield _super.update.call(this, Object.assign(Object.assign({ id }, data), { isWishlist: true, isCollection: true, brandCategory: false }));
4726
+ category.products = products && (yield this.updateProducts(+id, { products }));
4727
+ category.metadata = metadata && (yield this.updateMetadata(+id, { metadata }));
4728
+ return category;
4729
+ });
4730
+ }
4731
+ getWishlistBySlug(slug) {
4732
+ return __awaiter(this, void 0, void 0, function* () {
4733
+ if (!slug)
4734
+ return;
4735
+ const { data } = yield this.find({
4736
+ filters: {
4737
+ slug,
4738
+ isWishlist: { operator: Where.EQUALS, value: true },
4739
+ },
4740
+ options: {
4741
+ enableCount: false,
4742
+ },
4743
+ });
4744
+ if (!data.length)
4745
+ throw new NotFoundError(`Wishlist with slug ${slug} not found`);
4746
+ if (data.length > 1)
4747
+ throw new DuplicatedResultsError('Query returned duplicated values');
4748
+ return data.shift();
4749
+ });
4750
+ }
4751
+ getWishlistByPerson(personId) {
4752
+ return __awaiter(this, void 0, void 0, function* () {
4753
+ if (!personId)
4754
+ return;
4755
+ const { data } = yield this.find({
4756
+ filters: {
4757
+ personId: { operator: Where.EQUALS, value: personId },
4758
+ isWishlist: { operator: Where.EQUALS, value: true },
4759
+ },
4760
+ options: {
4761
+ enableCount: false,
4762
+ },
4763
+ });
4764
+ if (!data.length)
4765
+ throw new NotFoundError(`Wishlists from person ${personId} not found`);
4766
+ return data;
4767
+ });
4768
+ }
4769
+ updateProducts(categoryId, { products }) {
4770
+ return __awaiter(this, void 0, void 0, function* () {
4771
+ if ('action' in products && products.action === 'remove') {
4772
+ yield this.mutation('delete_category_product', ['affected_rows'], {
4773
+ where: {
4774
+ type: 'category_product_bool_exp',
4775
+ required: true,
4776
+ value: { category_id: { _eq: categoryId } },
4777
+ },
4778
+ });
4779
+ yield this.categoryFilterRepository.deleteByCategory(categoryId);
4780
+ return [];
4781
+ }
4782
+ const plainData = this.paramsToPlain({ products });
4783
+ if (!plainData.products || plainData.products.length <= 0)
4784
+ return [];
4785
+ yield this.mutation('delete_category_product', ['affected_rows'], {
4786
+ where: {
4787
+ type: 'category_product_bool_exp',
4788
+ required: true,
4789
+ value: { category_id: { _eq: categoryId } },
4790
+ },
4791
+ });
4792
+ yield this.categoryFilterRepository.deleteByCategory(categoryId);
4793
+ yield this.mutation('insert_category_product', ['affected_rows'], {
4794
+ objects: {
4795
+ type: '[category_product_insert_input!]',
4796
+ required: true,
4797
+ value: plainData.products.map((productId) => ({ category_id: categoryId, product_id: productId })),
4798
+ },
4799
+ });
4800
+ return plainData.products;
4801
+ });
4802
+ }
4803
+ updateMetadata(categoryId, { metadata }) {
4804
+ return __awaiter(this, void 0, void 0, function* () {
4805
+ const plainData = this.paramsToPlain({ metadata });
4806
+ if (!plainData.metadata)
4807
+ return;
4808
+ yield this.mutation('update_category_metadata_by_pk', ['category_id'], {
4809
+ pk_columns: {
4810
+ value: { category_id: categoryId },
4811
+ type: 'category_metadata_pk_columns_input',
4812
+ required: true,
4813
+ },
4814
+ _set: {
4815
+ value: omit(metadata, ['category_id']),
4816
+ type: 'category_metadata_set_input',
4817
+ required: true,
4818
+ },
4819
+ });
4820
+ return plainData.metadata;
4821
+ });
4822
+ }
4823
+ getCategoryBySlug(slug, _shop) {
4824
+ return this.getWishlistBySlug(slug);
4825
+ }
4826
+ getCategoryByShop(shop) {
4827
+ return __awaiter(this, void 0, void 0, function* () {
4828
+ if (!shop)
4829
+ return;
4830
+ const { data } = yield this.find({
4831
+ filters: {
4832
+ shops: { operator: Where.IN, value: [shop] },
4833
+ published: { operator: Where.EQUALS, value: true },
4834
+ isWishlist: { operator: Where.EQUALS, value: true },
4835
+ },
4836
+ options: {
4837
+ enableCount: false,
4838
+ },
4839
+ });
4840
+ return data;
4841
+ });
4842
+ }
4843
+ getCategoriesForHome(categoryIds, limit, gender) {
4844
+ return;
4845
+ }
4846
+ mountCategory(category, options) {
4847
+ return;
4848
+ }
4849
+ getChildren(parentId) {
4850
+ return;
4851
+ }
4852
+ isChild(id, parentId) {
4853
+ return;
4854
+ }
4855
+ }
4856
+
4492
4857
  /**
4493
4858
  * Generated bundle index. Do not edit.
4494
4859
  */
4495
4860
 
4496
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignBannerFirestoreRepository, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
4861
+ export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignBannerFirestoreRepository, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
4497
4862
  //# sourceMappingURL=infrab4a-connect.js.map