@infrab4a/connect 3.0.0-beta.0 → 3.0.0-beta.2

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 (23) hide show
  1. package/bundles/infrab4a-connect.umd.js +238 -146
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/generic/repository/enums/where.enum.d.ts +1 -0
  4. package/esm2015/domain/catalog/repositories/product.repository.js +1 -1
  5. package/esm2015/domain/generic/repository/enums/where.enum.js +2 -1
  6. package/esm2015/domain/shop-settings/models/home.js +1 -1
  7. package/esm2015/infra/elasticsearch/indexes/products-index.js +4 -5
  8. package/esm2015/infra/firebase/firestore/repositories/users/index.js +6 -7
  9. package/esm2015/infra/firebase/firestore/repositories/users/user-firestore.repository.js +4 -6
  10. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +60 -5
  11. package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +31 -8
  12. package/esm2015/infra/hasura-graphql/types/hasura-graphql-fields.type.js +1 -1
  13. package/fesm2015/infrab4a-connect.js +138 -76
  14. package/fesm2015/infrab4a-connect.js.map +1 -1
  15. package/infra/firebase/firestore/repositories/users/index.d.ts +5 -6
  16. package/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +1 -3
  17. package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +4 -1
  18. package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +1 -1
  19. package/package.json +1 -1
  20. package/esm2015/infra/firebase/firestore/models/user-search.js +0 -7
  21. package/esm2015/infra/firebase/firestore/repositories/users/user-search-firestore.repository.js +0 -12
  22. package/infra/firebase/firestore/models/user-search.d.ts +0 -9
  23. package/infra/firebase/firestore/repositories/users/user-search-firestore.repository.d.ts +0 -9
@@ -48,6 +48,7 @@
48
48
  exports.Where = void 0;
49
49
  (function (Where) {
50
50
  Where["EQUALS"] = "==";
51
+ Where["NOTEQUALS"] = "!=";
51
52
  Where["GT"] = ">";
52
53
  Where["GTE"] = ">=";
53
54
  Where["IN"] = "in";
@@ -1746,12 +1747,10 @@
1746
1747
  };
1747
1748
  ProductsIndex.prototype.findById = function (ids, options) {
1748
1749
  return __awaiter(this, void 0, void 0, function () {
1749
- var publishedField, fields, hits;
1750
- var _a;
1751
- return __generator(this, function (_b) {
1752
- switch (_b.label) {
1750
+ var fields, hits;
1751
+ return __generator(this, function (_a) {
1752
+ switch (_a.label) {
1753
1753
  case 0:
1754
- publishedField = options.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
1755
1754
  fields = [
1756
1755
  'brand',
1757
1756
  'id',
@@ -1779,9 +1778,9 @@
1779
1778
  },
1780
1779
  },
1781
1780
  {
1782
- term: (_a = {},
1783
- _a[publishedField] = true,
1784
- _a),
1781
+ term: {
1782
+ published: true,
1783
+ },
1785
1784
  }
1786
1785
  ], __read((options.hasStock
1787
1786
  ? [
@@ -1797,7 +1796,7 @@
1797
1796
  },
1798
1797
  } }, (options.size ? { size: options.size } : {})))];
1799
1798
  case 1:
1800
- hits = (_b.sent()).hits;
1799
+ hits = (_a.sent()).hits;
1801
1800
  return [2 /*return*/, hits.map(function (hit) { return Product.toInstance(hit._source); })];
1802
1801
  }
1803
1802
  });
@@ -1826,7 +1825,7 @@
1826
1825
  return [3 /*break*/, 6];
1827
1826
  case 4:
1828
1827
  error_1 = _a.sent();
1829
- console.info(error_1.message);
1828
+ console.error(error_1.message);
1830
1829
  return [4 /*yield*/, this.adapter.save("products/_doc/" + product.id, product.toPlain())];
1831
1830
  case 5:
1832
1831
  _a.sent();
@@ -2230,6 +2229,32 @@
2230
2229
  }(withUpdateFirestore(withGetFirestore(withFindFirestore(withDeleteFirestore(withCreateFirestore(MixinBase)))))));
2231
2230
  };
2232
2231
 
2232
+ var LeadFirestoreRepository = /** @class */ (function (_super) {
2233
+ __extends(LeadFirestoreRepository, _super);
2234
+ function LeadFirestoreRepository(firestore) {
2235
+ var _this = _super.call(this) || this;
2236
+ _this.firestore = firestore;
2237
+ _this.collectionName = 'leads';
2238
+ _this.model = Lead;
2239
+ return _this;
2240
+ }
2241
+ return LeadFirestoreRepository;
2242
+ }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2243
+
2244
+ var SubscriptionEditionFirestoreRepository = /** @class */ (function (_super) {
2245
+ __extends(SubscriptionEditionFirestoreRepository, _super);
2246
+ function SubscriptionEditionFirestoreRepository(firestore, parentRepository) {
2247
+ var _this = _super.call(this) || this;
2248
+ _this.firestore = firestore;
2249
+ _this.parentRepository = parentRepository;
2250
+ _this.collectionName = 'editions';
2251
+ _this.parentIdField = 'subscriptionId';
2252
+ _this.model = Edition;
2253
+ return _this;
2254
+ }
2255
+ return SubscriptionEditionFirestoreRepository;
2256
+ }(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription)));
2257
+
2233
2258
  var SubscriptionFirestoreRepository = /** @class */ (function (_super) {
2234
2259
  __extends(SubscriptionFirestoreRepository, _super);
2235
2260
  function SubscriptionFirestoreRepository(firestore) {
@@ -2242,40 +2267,53 @@
2242
2267
  return SubscriptionFirestoreRepository;
2243
2268
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2244
2269
 
2245
- var UserSearch = /** @class */ (function (_super) {
2246
- __extends(UserSearch, _super);
2247
- function UserSearch() {
2248
- return _super !== null && _super.apply(this, arguments) || this;
2270
+ var SubscriptionPaymentFirestoreRepository = /** @class */ (function (_super) {
2271
+ __extends(SubscriptionPaymentFirestoreRepository, _super);
2272
+ function SubscriptionPaymentFirestoreRepository(firestore, parentRepository) {
2273
+ var _this = _super.call(this) || this;
2274
+ _this.firestore = firestore;
2275
+ _this.parentRepository = parentRepository;
2276
+ _this.collectionName = 'payments';
2277
+ _this.parentIdField = 'subscriptionId';
2278
+ _this.model = SubscriptionPayment;
2279
+ return _this;
2249
2280
  }
2250
- Object.defineProperty(UserSearch, "identifiersFields", {
2251
- get: function () {
2252
- return ['id'];
2253
- },
2254
- enumerable: false,
2255
- configurable: true
2256
- });
2257
- return UserSearch;
2258
- }(BaseModel));
2281
+ return SubscriptionPaymentFirestoreRepository;
2282
+ }(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription)));
2259
2283
 
2260
- var UserSearchFirestoreRepository = /** @class */ (function (_super) {
2261
- __extends(UserSearchFirestoreRepository, _super);
2262
- function UserSearchFirestoreRepository(firestore) {
2284
+ var UserAddressFirestoreRepository = /** @class */ (function (_super) {
2285
+ __extends(UserAddressFirestoreRepository, _super);
2286
+ function UserAddressFirestoreRepository(firestore, parentRepository) {
2263
2287
  var _this = _super.call(this) || this;
2264
2288
  _this.firestore = firestore;
2265
- _this.collectionName = 'userSearch';
2266
- _this.model = UserSearch;
2289
+ _this.parentRepository = parentRepository;
2290
+ _this.collectionName = 'address';
2291
+ _this.parentIdField = 'userId';
2292
+ _this.model = UserAddress;
2267
2293
  return _this;
2268
2294
  }
2269
- return UserSearchFirestoreRepository;
2270
- }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2295
+ return UserAddressFirestoreRepository;
2296
+ }(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User)));
2297
+
2298
+ var UserBeautyProfileFirestoreRepository = /** @class */ (function (_super) {
2299
+ __extends(UserBeautyProfileFirestoreRepository, _super);
2300
+ function UserBeautyProfileFirestoreRepository(firestore, parentRepository) {
2301
+ var _this = _super.call(this) || this;
2302
+ _this.firestore = firestore;
2303
+ _this.parentRepository = parentRepository;
2304
+ _this.collectionName = 'CX';
2305
+ _this.parentIdField = 'userId';
2306
+ _this.model = BeautyProfile;
2307
+ return _this;
2308
+ }
2309
+ return UserBeautyProfileFirestoreRepository;
2310
+ }(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User)));
2271
2311
 
2272
2312
  var UserFirestoreRepository = /** @class */ (function (_super_1) {
2273
2313
  __extends(UserFirestoreRepository, _super_1);
2274
- function UserFirestoreRepository(firestore, userSearchFirestoreRepository) {
2275
- if (userSearchFirestoreRepository === void 0) { userSearchFirestoreRepository = new UserSearchFirestoreRepository(firestore); }
2314
+ function UserFirestoreRepository(firestore) {
2276
2315
  var _this = _super_1.call(this) || this;
2277
2316
  _this.firestore = firestore;
2278
- _this.userSearchFirestoreRepository = userSearchFirestoreRepository;
2279
2317
  _this.collectionName = 'users';
2280
2318
  _this.model = User;
2281
2319
  return _this;
@@ -2310,7 +2348,7 @@
2310
2348
  var _a;
2311
2349
  return __generator(this, function (_b) {
2312
2350
  switch (_b.label) {
2313
- case 0: return [4 /*yield*/, this.userSearchFirestoreRepository.find((_a = {}, _a[field] = { operator: exports.Where.EQUALS, value: value }, _a))];
2351
+ case 0: return [4 /*yield*/, this.find({ filters: (_a = {}, _a[field] = value, _a) })];
2314
2352
  case 1:
2315
2353
  result = _b.sent();
2316
2354
  return [2 /*return*/, result.count > 0];
@@ -2373,48 +2411,6 @@
2373
2411
  return UserFirestoreRepository;
2374
2412
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2375
2413
 
2376
- var SubscriptionEditionFirestoreRepository = /** @class */ (function (_super) {
2377
- __extends(SubscriptionEditionFirestoreRepository, _super);
2378
- function SubscriptionEditionFirestoreRepository(firestore, parentRepository) {
2379
- var _this = _super.call(this) || this;
2380
- _this.firestore = firestore;
2381
- _this.parentRepository = parentRepository;
2382
- _this.collectionName = 'editions';
2383
- _this.parentIdField = 'subscriptionId';
2384
- _this.model = Edition;
2385
- return _this;
2386
- }
2387
- return SubscriptionEditionFirestoreRepository;
2388
- }(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription)));
2389
-
2390
- var UserBeautyProfileFirestoreRepository = /** @class */ (function (_super) {
2391
- __extends(UserBeautyProfileFirestoreRepository, _super);
2392
- function UserBeautyProfileFirestoreRepository(firestore, parentRepository) {
2393
- var _this = _super.call(this) || this;
2394
- _this.firestore = firestore;
2395
- _this.parentRepository = parentRepository;
2396
- _this.collectionName = 'CX';
2397
- _this.parentIdField = 'userId';
2398
- _this.model = BeautyProfile;
2399
- return _this;
2400
- }
2401
- return UserBeautyProfileFirestoreRepository;
2402
- }(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User)));
2403
-
2404
- var UserAddressFirestoreRepository = /** @class */ (function (_super) {
2405
- __extends(UserAddressFirestoreRepository, _super);
2406
- function UserAddressFirestoreRepository(firestore, parentRepository) {
2407
- var _this = _super.call(this) || this;
2408
- _this.firestore = firestore;
2409
- _this.parentRepository = parentRepository;
2410
- _this.collectionName = 'address';
2411
- _this.parentIdField = 'userId';
2412
- _this.model = UserAddress;
2413
- return _this;
2414
- }
2415
- return UserAddressFirestoreRepository;
2416
- }(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User)));
2417
-
2418
2414
  var UserPaymentMethodFirestoreRepository = /** @class */ (function (_super) {
2419
2415
  __extends(UserPaymentMethodFirestoreRepository, _super);
2420
2416
  function UserPaymentMethodFirestoreRepository(firestore, parentRepository) {
@@ -2429,32 +2425,6 @@
2429
2425
  return UserPaymentMethodFirestoreRepository;
2430
2426
  }(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User)));
2431
2427
 
2432
- var SubscriptionPaymentFirestoreRepository = /** @class */ (function (_super) {
2433
- __extends(SubscriptionPaymentFirestoreRepository, _super);
2434
- function SubscriptionPaymentFirestoreRepository(firestore, parentRepository) {
2435
- var _this = _super.call(this) || this;
2436
- _this.firestore = firestore;
2437
- _this.parentRepository = parentRepository;
2438
- _this.collectionName = 'payments';
2439
- _this.parentIdField = 'subscriptionId';
2440
- _this.model = SubscriptionPayment;
2441
- return _this;
2442
- }
2443
- return SubscriptionPaymentFirestoreRepository;
2444
- }(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription)));
2445
-
2446
- var LeadFirestoreRepository = /** @class */ (function (_super) {
2447
- __extends(LeadFirestoreRepository, _super);
2448
- function LeadFirestoreRepository(firestore) {
2449
- var _this = _super.call(this) || this;
2450
- _this.firestore = firestore;
2451
- _this.collectionName = 'leads';
2452
- _this.model = Lead;
2453
- return _this;
2454
- }
2455
- return LeadFirestoreRepository;
2456
- }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2457
-
2458
2428
  var CategoryFirestoreRepository = /** @class */ (function (_super) {
2459
2429
  __extends(CategoryFirestoreRepository, _super);
2460
2430
  function CategoryFirestoreRepository(firestore) {
@@ -3701,34 +3671,65 @@
3701
3671
  });
3702
3672
  var _a;
3703
3673
  return __awaiter(this, void 0, void 0, function () {
3704
- var _b;
3705
- return __generator(this, function (_c) {
3706
- switch (_c.label) {
3674
+ var _c;
3675
+ return __generator(this, function (_d) {
3676
+ switch (_d.label) {
3707
3677
  case 0:
3708
3678
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3709
3679
  return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3710
3680
  case 1:
3711
- _b = (_a = (_c.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3681
+ _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3712
3682
  return [3 /*break*/, 3];
3713
3683
  case 2:
3714
- _b = _super.get.call(this, identifiers);
3715
- _c.label = 3;
3716
- case 3: return [2 /*return*/, _b];
3684
+ _c = _super.get.call(this, identifiers);
3685
+ _d.label = 3;
3686
+ case 3: return [2 /*return*/, _c];
3687
+ }
3688
+ });
3689
+ });
3690
+ };
3691
+ CategoryHasuraGraphQLRepository.prototype.update = function (params) {
3692
+ var _super = Object.create(null, {
3693
+ update: { get: function () { return _super_1.prototype.update; } }
3694
+ });
3695
+ return __awaiter(this, void 0, void 0, function () {
3696
+ var products, checkId, data, plainData, id, category, _c, _d;
3697
+ return __generator(this, function (_e) {
3698
+ switch (_e.label) {
3699
+ case 0:
3700
+ products = params.products, checkId = params.id, data = __rest(params, ["products", "id"]);
3701
+ plainData = this.paramsToPlain({ id: checkId });
3702
+ return [4 /*yield*/, this.getId(plainData.id)];
3703
+ case 1:
3704
+ id = _e.sent();
3705
+ return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
3706
+ case 2:
3707
+ category = _e.sent();
3708
+ _c = category;
3709
+ _d = products;
3710
+ if (!_d) return [3 /*break*/, 4];
3711
+ return [4 /*yield*/, this.updateProducts(+id, { products: products })];
3712
+ case 3:
3713
+ _d = (_e.sent());
3714
+ _e.label = 4;
3715
+ case 4:
3716
+ _c.products = _d;
3717
+ return [2 /*return*/, category];
3717
3718
  }
3718
3719
  });
3719
3720
  });
3720
3721
  };
3721
3722
  CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
3722
3723
  return __awaiter(this, void 0, void 0, function () {
3723
- var _b, data, count;
3724
- return __generator(this, function (_c) {
3725
- switch (_c.label) {
3724
+ var _c, data, count;
3725
+ return __generator(this, function (_d) {
3726
+ switch (_d.label) {
3726
3727
  case 0:
3727
3728
  if (!slug)
3728
3729
  return [2 /*return*/];
3729
3730
  return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
3730
3731
  case 1:
3731
- _b = _c.sent(), data = _b.data, count = _b.count;
3732
+ _c = _d.sent(), data = _c.data, count = _c.count;
3732
3733
  if (count > 1)
3733
3734
  throw new DuplicatedResultsError('Query returned duplicated values');
3734
3735
  if (!count)
@@ -3741,33 +3742,33 @@
3741
3742
  CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
3742
3743
  if (limit === void 0) { limit = 4; }
3743
3744
  return __awaiter(this, void 0, void 0, function () {
3744
- var _b, categories, count, homeSections;
3745
+ var _c, categories, count, homeSections;
3745
3746
  var _this = this;
3746
- return __generator(this, function (_c) {
3747
- switch (_c.label) {
3747
+ return __generator(this, function (_d) {
3748
+ switch (_d.label) {
3748
3749
  case 0: return [4 /*yield*/, this.find({
3749
3750
  filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
3750
3751
  })];
3751
3752
  case 1:
3752
- _b = _c.sent(), categories = _b.data, count = _b.count;
3753
+ _c = _d.sent(), categories = _c.data, count = _c.count;
3753
3754
  if (!count)
3754
3755
  throw new NotFoundError('Categories not found');
3755
3756
  return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
3756
- var _b;
3757
- return __generator(this, function (_c) {
3758
- switch (_c.label) {
3757
+ var _c;
3758
+ return __generator(this, function (_d) {
3759
+ switch (_d.label) {
3759
3760
  case 0:
3760
- _b = {
3761
+ _c = {
3761
3762
  category: category
3762
3763
  };
3763
3764
  return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
3764
- case 1: return [2 /*return*/, (_b.products = _c.sent(),
3765
- _b)];
3765
+ case 1: return [2 /*return*/, (_c.products = _d.sent(),
3766
+ _c)];
3766
3767
  }
3767
3768
  });
3768
3769
  }); }))];
3769
3770
  case 2:
3770
- homeSections = _c.sent();
3771
+ homeSections = _d.sent();
3771
3772
  return [2 /*return*/, homeSections];
3772
3773
  }
3773
3774
  });
@@ -3775,16 +3776,14 @@
3775
3776
  };
3776
3777
  CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
3777
3778
  return __awaiter(this, void 0, void 0, function () {
3778
- var products, publishedField, productsData;
3779
- var _b;
3779
+ var products, productsData;
3780
3780
  return __generator(this, function (_c) {
3781
3781
  switch (_c.label) {
3782
3782
  case 0:
3783
3783
  if (!category.products)
3784
3784
  throw new RequiredArgumentError(['Category products is empty']);
3785
3785
  products = [];
3786
- publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
3787
- return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign((_b = { id: { operator: exports.Where.IN, value: category.products } }, _b[publishedField] = true, _b), ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3786
+ return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign({ id: { operator: exports.Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3788
3787
  'id',
3789
3788
  'name',
3790
3789
  'slug',
@@ -3815,6 +3814,70 @@
3815
3814
  });
3816
3815
  });
3817
3816
  };
3817
+ CategoryHasuraGraphQLRepository.prototype.getId = function (id) {
3818
+ var _a, _b;
3819
+ return __awaiter(this, void 0, void 0, function () {
3820
+ var data;
3821
+ return __generator(this, function (_c) {
3822
+ switch (_c.label) {
3823
+ case 0:
3824
+ if (!Number.isNaN(+id))
3825
+ return [2 /*return*/, id];
3826
+ return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
3827
+ case 1:
3828
+ data = (_c.sent()).data;
3829
+ if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
3830
+ return [2 /*return*/, (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id];
3831
+ throw new NotFoundError("Category with id " + id + " not found");
3832
+ }
3833
+ });
3834
+ });
3835
+ };
3836
+ CategoryHasuraGraphQLRepository.prototype.updateProducts = function (categoryId, _c) {
3837
+ var products = _c.products;
3838
+ return __awaiter(this, void 0, void 0, function () {
3839
+ var plainData;
3840
+ return __generator(this, function (_c) {
3841
+ switch (_c.label) {
3842
+ case 0:
3843
+ if (!('action' in products && products.action === 'remove')) return [3 /*break*/, 2];
3844
+ return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
3845
+ where: {
3846
+ type: 'category_product_bool_exp',
3847
+ required: true,
3848
+ value: { category_id: { _eq: categoryId } },
3849
+ },
3850
+ })];
3851
+ case 1:
3852
+ _c.sent();
3853
+ return [2 /*return*/, []];
3854
+ case 2:
3855
+ plainData = this.paramsToPlain({ products: products });
3856
+ if (!plainData.products || plainData.products.length <= 0)
3857
+ return [2 /*return*/, []];
3858
+ return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
3859
+ where: {
3860
+ type: 'category_product_bool_exp',
3861
+ required: true,
3862
+ value: { category_id: { _eq: categoryId } },
3863
+ },
3864
+ })];
3865
+ case 3:
3866
+ _c.sent();
3867
+ return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
3868
+ objects: {
3869
+ type: '[category_product_insert_input!]',
3870
+ required: true,
3871
+ value: plainData.products.map(function (productId) { return ({ category_id: categoryId, product_id: productId }); }),
3872
+ },
3873
+ })];
3874
+ case 4:
3875
+ _c.sent();
3876
+ return [2 /*return*/, plainData.products];
3877
+ }
3878
+ });
3879
+ });
3880
+ };
3818
3881
  return CategoryHasuraGraphQLRepository;
3819
3882
  }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3820
3883
 
@@ -3925,6 +3988,13 @@
3925
3988
  ],
3926
3989
  },
3927
3990
  },
3991
+ {
3992
+ reviews: {
3993
+ columnName: 'reviews',
3994
+ foreignKeyColumn: { productId: 'id' },
3995
+ fields: _this.reviewsFields,
3996
+ },
3997
+ },
3928
3998
  {
3929
3999
  metadata: {
3930
4000
  columnName: 'metadata',
@@ -3995,27 +4065,32 @@
3995
4065
  });
3996
4066
  var _a;
3997
4067
  return __awaiter(this, void 0, void 0, function () {
3998
- var product, _c, _d;
3999
- return __generator(this, function (_e) {
4000
- switch (_e.label) {
4068
+ var product, _c, _d, _e;
4069
+ return __generator(this, function (_f) {
4070
+ switch (_f.label) {
4001
4071
  case 0:
4002
4072
  if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
4003
4073
  return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
4004
4074
  case 1:
4005
- _c = (_a = (_e.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
4075
+ _c = (_a = (_f.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
4006
4076
  return [3 /*break*/, 4];
4007
4077
  case 2: return [4 /*yield*/, _super.get.call(this, identifiers)];
4008
4078
  case 3:
4009
- _c = _e.sent();
4010
- _e.label = 4;
4079
+ _c = _f.sent();
4080
+ _f.label = 4;
4011
4081
  case 4:
4012
4082
  product = _c;
4013
4083
  if (product.productId)
4014
4084
  throw new NotFoundError('Product not found, it is a variant');
4015
4085
  _d = product;
4086
+ _e = product.reviews;
4087
+ if (_e) return [3 /*break*/, 6];
4016
4088
  return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
4017
4089
  case 5:
4018
- _d.reviews = _e.sent();
4090
+ _e = (_f.sent());
4091
+ _f.label = 6;
4092
+ case 6:
4093
+ _d.reviews = _e;
4019
4094
  return [2 /*return*/, product];
4020
4095
  }
4021
4096
  });
@@ -4026,10 +4101,14 @@
4026
4101
  find: { get: function () { return _super_1.prototype.find; } }
4027
4102
  });
4028
4103
  return __awaiter(this, void 0, void 0, function () {
4029
- var _a, filters, options;
4104
+ var _a, filters, fields, options, bindFields;
4030
4105
  return __generator(this, function (_c) {
4031
- _a = params || {}, filters = _a.filters, options = __rest(_a, ["filters"]);
4032
- return [2 /*return*/, _super.find.call(this, Object.assign(Object.assign({}, options), { filters: Object.assign(Object.assign({}, filters), { productId: { operator: exports.Where.ISNULL } }) }))];
4106
+ _a = params || {}, filters = _a.filters, fields = _a.fields, options = __rest(_a, ["filters", "fields"]);
4107
+ bindFields = fields ||
4108
+ this.fields
4109
+ .map(function (field) { return (typeof field === 'string' ? field : Object.keys(field).shift()); })
4110
+ .filter(function (field) { return field !== 'reviews'; });
4111
+ return [2 /*return*/, _super.find.call(this, Object.assign(Object.assign({}, options), { filters: Object.assign(Object.assign({}, filters), { productId: { operator: exports.Where.ISNULL } }), fields: bindFields }))];
4033
4112
  });
4034
4113
  });
4035
4114
  };
@@ -4107,18 +4186,18 @@
4107
4186
  };
4108
4187
  ProductHasuraGraphQLRepository.prototype.fetchReviews = function (status) {
4109
4188
  return __awaiter(this, void 0, void 0, function () {
4110
- var reviews, data;
4189
+ var reviewsExpression, data;
4111
4190
  var _c, _d;
4112
4191
  var _this = this;
4113
4192
  return __generator(this, function (_e) {
4114
4193
  switch (_e.label) {
4115
4194
  case 0:
4116
- reviews = {
4195
+ reviewsExpression = {
4117
4196
  status: status === 'pending'
4118
4197
  ? (_c = {}, _c[HasuraGraphQLWhere.ISNULL] = true, _c) : (_d = {}, _d[HasuraGraphQLWhere.EQUALS] = status === 'approved', _d),
4119
4198
  };
4120
4199
  return [4 /*yield*/, this.query('product', ['id', 'name', 'sku', { reviews: { columnName: 'reviews', fields: this.reviewsFields } }], {
4121
- where: { value: { reviews: reviews }, type: 'product_bool_exp', required: true },
4200
+ where: { value: { reviews: reviewsExpression }, type: 'product_bool_exp', required: true },
4122
4201
  })];
4123
4202
  case 1:
4124
4203
  data = (_e.sent()).product;
@@ -4138,7 +4217,7 @@
4138
4217
  return __generator(this, function (_c) {
4139
4218
  switch (_c.label) {
4140
4219
  case 0:
4141
- plainData = this.paramsToPlain({ categories: categories });
4220
+ if (!('action' in categories && categories.action === 'remove')) return [3 /*break*/, 2];
4142
4221
  return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
4143
4222
  where: {
4144
4223
  type: 'category_product_bool_exp',
@@ -4147,6 +4226,20 @@
4147
4226
  },
4148
4227
  })];
4149
4228
  case 1:
4229
+ _c.sent();
4230
+ return [2 /*return*/, []];
4231
+ case 2:
4232
+ plainData = this.paramsToPlain({ categories: categories });
4233
+ if (!plainData.categories || plainData.categories.length <= 0)
4234
+ return [2 /*return*/, []];
4235
+ return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
4236
+ where: {
4237
+ type: 'category_product_bool_exp',
4238
+ required: true,
4239
+ value: { product_id: { _eq: productId } },
4240
+ },
4241
+ })];
4242
+ case 3:
4150
4243
  _c.sent();
4151
4244
  return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
4152
4245
  objects: {
@@ -4155,7 +4248,7 @@
4155
4248
  value: plainData.categories.map(function (categoryId) { return ({ category_id: categoryId, product_id: productId }); }),
4156
4249
  },
4157
4250
  })];
4158
- case 2:
4251
+ case 4:
4159
4252
  _c.sent();
4160
4253
  return [2 /*return*/, plainData.categories];
4161
4254
  }
@@ -4205,8 +4298,6 @@
4205
4298
  return __generator(this, function (_c) {
4206
4299
  switch (_c.label) {
4207
4300
  case 0:
4208
- if (!reviews)
4209
- return [2 /*return*/, []];
4210
4301
  if (!('action' in reviews && reviews.action === 'remove')) return [3 /*break*/, 3];
4211
4302
  return [4 /*yield*/, Promise.all(reviews.value.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
4212
4303
  var review;
@@ -4229,6 +4320,8 @@
4229
4320
  return [2 /*return*/, reviews.value.map(function (review, index) { return !reviewIds_1[index] && review; }).filter(Boolean)];
4230
4321
  case 3:
4231
4322
  plainData = this.paramsToPlain({ reviews: reviews });
4323
+ if (!plainData.reviews || plainData.reviews.length <= 0)
4324
+ return [2 /*return*/, []];
4232
4325
  return [2 /*return*/, Promise.all(plainData.reviews.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
4233
4326
  var review, _c, _d;
4234
4327
  return __generator(this, function (_e) {
@@ -4698,7 +4791,6 @@
4698
4791
  exports.UserFirestoreRepository = UserFirestoreRepository;
4699
4792
  exports.UserPaymentMethod = UserPaymentMethod;
4700
4793
  exports.UserPaymentMethodFirestoreRepository = UserPaymentMethodFirestoreRepository;
4701
- exports.UserSearchFirestoreRepository = UserSearchFirestoreRepository;
4702
4794
  exports.Variant = Variant;
4703
4795
  exports.VariantHasuraGraphQL = VariantHasuraGraphQL;
4704
4796
  exports.VariantHasuraGraphQLRepository = VariantHasuraGraphQLRepository;