@infrab4a/connect 3.0.0-beta.1 → 3.0.0-beta.3
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.
- package/bundles/infrab4a-connect.umd.js +287 -149
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/domain/generic/repository/enums/where.enum.d.ts +1 -0
- package/esm2015/domain/catalog/repositories/product.repository.js +1 -1
- package/esm2015/domain/generic/repository/enums/where.enum.js +2 -1
- package/esm2015/domain/shop-settings/models/home.js +1 -1
- package/esm2015/infra/elasticsearch/indexes/products-index.js +2 -2
- package/esm2015/infra/firebase/firestore/repositories/users/index.js +6 -7
- package/esm2015/infra/firebase/firestore/repositories/users/user-firestore.repository.js +4 -6
- package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +59 -3
- package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +56 -9
- package/esm2015/infra/hasura-graphql/types/hasura-graphql-fields.type.js +1 -1
- package/fesm2015/infrab4a-connect.js +161 -73
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/firebase/firestore/repositories/users/index.d.ts +5 -6
- package/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +1 -3
- package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +4 -1
- package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +2 -1
- package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +1 -1
- package/package.json +1 -1
- package/esm2015/infra/firebase/firestore/models/user-search.js +0 -7
- package/esm2015/infra/firebase/firestore/repositories/users/user-search-firestore.repository.js +0 -12
- package/infra/firebase/firestore/models/user-search.d.ts +0 -9
- 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";
|
|
@@ -1824,7 +1825,7 @@
|
|
|
1824
1825
|
return [3 /*break*/, 6];
|
|
1825
1826
|
case 4:
|
|
1826
1827
|
error_1 = _a.sent();
|
|
1827
|
-
console.
|
|
1828
|
+
console.error(error_1.message);
|
|
1828
1829
|
return [4 /*yield*/, this.adapter.save("products/_doc/" + product.id, product.toPlain())];
|
|
1829
1830
|
case 5:
|
|
1830
1831
|
_a.sent();
|
|
@@ -2228,6 +2229,32 @@
|
|
|
2228
2229
|
}(withUpdateFirestore(withGetFirestore(withFindFirestore(withDeleteFirestore(withCreateFirestore(MixinBase)))))));
|
|
2229
2230
|
};
|
|
2230
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
|
+
|
|
2231
2258
|
var SubscriptionFirestoreRepository = /** @class */ (function (_super) {
|
|
2232
2259
|
__extends(SubscriptionFirestoreRepository, _super);
|
|
2233
2260
|
function SubscriptionFirestoreRepository(firestore) {
|
|
@@ -2240,40 +2267,53 @@
|
|
|
2240
2267
|
return SubscriptionFirestoreRepository;
|
|
2241
2268
|
}(withCrudFirestore(withHelpers(withFirestore(Base)))));
|
|
2242
2269
|
|
|
2243
|
-
var
|
|
2244
|
-
__extends(
|
|
2245
|
-
function
|
|
2246
|
-
|
|
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;
|
|
2247
2280
|
}
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
return ['id'];
|
|
2251
|
-
},
|
|
2252
|
-
enumerable: false,
|
|
2253
|
-
configurable: true
|
|
2254
|
-
});
|
|
2255
|
-
return UserSearch;
|
|
2256
|
-
}(BaseModel));
|
|
2281
|
+
return SubscriptionPaymentFirestoreRepository;
|
|
2282
|
+
}(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription)));
|
|
2257
2283
|
|
|
2258
|
-
var
|
|
2259
|
-
__extends(
|
|
2260
|
-
function
|
|
2284
|
+
var UserAddressFirestoreRepository = /** @class */ (function (_super) {
|
|
2285
|
+
__extends(UserAddressFirestoreRepository, _super);
|
|
2286
|
+
function UserAddressFirestoreRepository(firestore, parentRepository) {
|
|
2261
2287
|
var _this = _super.call(this) || this;
|
|
2262
2288
|
_this.firestore = firestore;
|
|
2263
|
-
_this.
|
|
2264
|
-
_this.
|
|
2289
|
+
_this.parentRepository = parentRepository;
|
|
2290
|
+
_this.collectionName = 'address';
|
|
2291
|
+
_this.parentIdField = 'userId';
|
|
2292
|
+
_this.model = UserAddress;
|
|
2265
2293
|
return _this;
|
|
2266
2294
|
}
|
|
2267
|
-
return
|
|
2268
|
-
}(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)));
|
|
2269
2311
|
|
|
2270
2312
|
var UserFirestoreRepository = /** @class */ (function (_super_1) {
|
|
2271
2313
|
__extends(UserFirestoreRepository, _super_1);
|
|
2272
|
-
function UserFirestoreRepository(firestore
|
|
2273
|
-
if (userSearchFirestoreRepository === void 0) { userSearchFirestoreRepository = new UserSearchFirestoreRepository(firestore); }
|
|
2314
|
+
function UserFirestoreRepository(firestore) {
|
|
2274
2315
|
var _this = _super_1.call(this) || this;
|
|
2275
2316
|
_this.firestore = firestore;
|
|
2276
|
-
_this.userSearchFirestoreRepository = userSearchFirestoreRepository;
|
|
2277
2317
|
_this.collectionName = 'users';
|
|
2278
2318
|
_this.model = User;
|
|
2279
2319
|
return _this;
|
|
@@ -2308,7 +2348,7 @@
|
|
|
2308
2348
|
var _a;
|
|
2309
2349
|
return __generator(this, function (_b) {
|
|
2310
2350
|
switch (_b.label) {
|
|
2311
|
-
case 0: return [4 /*yield*/, this.
|
|
2351
|
+
case 0: return [4 /*yield*/, this.find({ filters: (_a = {}, _a[field] = value, _a) })];
|
|
2312
2352
|
case 1:
|
|
2313
2353
|
result = _b.sent();
|
|
2314
2354
|
return [2 /*return*/, result.count > 0];
|
|
@@ -2371,48 +2411,6 @@
|
|
|
2371
2411
|
return UserFirestoreRepository;
|
|
2372
2412
|
}(withCrudFirestore(withHelpers(withFirestore(Base)))));
|
|
2373
2413
|
|
|
2374
|
-
var SubscriptionEditionFirestoreRepository = /** @class */ (function (_super) {
|
|
2375
|
-
__extends(SubscriptionEditionFirestoreRepository, _super);
|
|
2376
|
-
function SubscriptionEditionFirestoreRepository(firestore, parentRepository) {
|
|
2377
|
-
var _this = _super.call(this) || this;
|
|
2378
|
-
_this.firestore = firestore;
|
|
2379
|
-
_this.parentRepository = parentRepository;
|
|
2380
|
-
_this.collectionName = 'editions';
|
|
2381
|
-
_this.parentIdField = 'subscriptionId';
|
|
2382
|
-
_this.model = Edition;
|
|
2383
|
-
return _this;
|
|
2384
|
-
}
|
|
2385
|
-
return SubscriptionEditionFirestoreRepository;
|
|
2386
|
-
}(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription)));
|
|
2387
|
-
|
|
2388
|
-
var UserBeautyProfileFirestoreRepository = /** @class */ (function (_super) {
|
|
2389
|
-
__extends(UserBeautyProfileFirestoreRepository, _super);
|
|
2390
|
-
function UserBeautyProfileFirestoreRepository(firestore, parentRepository) {
|
|
2391
|
-
var _this = _super.call(this) || this;
|
|
2392
|
-
_this.firestore = firestore;
|
|
2393
|
-
_this.parentRepository = parentRepository;
|
|
2394
|
-
_this.collectionName = 'CX';
|
|
2395
|
-
_this.parentIdField = 'userId';
|
|
2396
|
-
_this.model = BeautyProfile;
|
|
2397
|
-
return _this;
|
|
2398
|
-
}
|
|
2399
|
-
return UserBeautyProfileFirestoreRepository;
|
|
2400
|
-
}(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User)));
|
|
2401
|
-
|
|
2402
|
-
var UserAddressFirestoreRepository = /** @class */ (function (_super) {
|
|
2403
|
-
__extends(UserAddressFirestoreRepository, _super);
|
|
2404
|
-
function UserAddressFirestoreRepository(firestore, parentRepository) {
|
|
2405
|
-
var _this = _super.call(this) || this;
|
|
2406
|
-
_this.firestore = firestore;
|
|
2407
|
-
_this.parentRepository = parentRepository;
|
|
2408
|
-
_this.collectionName = 'address';
|
|
2409
|
-
_this.parentIdField = 'userId';
|
|
2410
|
-
_this.model = UserAddress;
|
|
2411
|
-
return _this;
|
|
2412
|
-
}
|
|
2413
|
-
return UserAddressFirestoreRepository;
|
|
2414
|
-
}(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User)));
|
|
2415
|
-
|
|
2416
2414
|
var UserPaymentMethodFirestoreRepository = /** @class */ (function (_super) {
|
|
2417
2415
|
__extends(UserPaymentMethodFirestoreRepository, _super);
|
|
2418
2416
|
function UserPaymentMethodFirestoreRepository(firestore, parentRepository) {
|
|
@@ -2427,32 +2425,6 @@
|
|
|
2427
2425
|
return UserPaymentMethodFirestoreRepository;
|
|
2428
2426
|
}(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User)));
|
|
2429
2427
|
|
|
2430
|
-
var SubscriptionPaymentFirestoreRepository = /** @class */ (function (_super) {
|
|
2431
|
-
__extends(SubscriptionPaymentFirestoreRepository, _super);
|
|
2432
|
-
function SubscriptionPaymentFirestoreRepository(firestore, parentRepository) {
|
|
2433
|
-
var _this = _super.call(this) || this;
|
|
2434
|
-
_this.firestore = firestore;
|
|
2435
|
-
_this.parentRepository = parentRepository;
|
|
2436
|
-
_this.collectionName = 'payments';
|
|
2437
|
-
_this.parentIdField = 'subscriptionId';
|
|
2438
|
-
_this.model = SubscriptionPayment;
|
|
2439
|
-
return _this;
|
|
2440
|
-
}
|
|
2441
|
-
return SubscriptionPaymentFirestoreRepository;
|
|
2442
|
-
}(withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription)));
|
|
2443
|
-
|
|
2444
|
-
var LeadFirestoreRepository = /** @class */ (function (_super) {
|
|
2445
|
-
__extends(LeadFirestoreRepository, _super);
|
|
2446
|
-
function LeadFirestoreRepository(firestore) {
|
|
2447
|
-
var _this = _super.call(this) || this;
|
|
2448
|
-
_this.firestore = firestore;
|
|
2449
|
-
_this.collectionName = 'leads';
|
|
2450
|
-
_this.model = Lead;
|
|
2451
|
-
return _this;
|
|
2452
|
-
}
|
|
2453
|
-
return LeadFirestoreRepository;
|
|
2454
|
-
}(withCrudFirestore(withHelpers(withFirestore(Base)))));
|
|
2455
|
-
|
|
2456
2428
|
var CategoryFirestoreRepository = /** @class */ (function (_super) {
|
|
2457
2429
|
__extends(CategoryFirestoreRepository, _super);
|
|
2458
2430
|
function CategoryFirestoreRepository(firestore) {
|
|
@@ -3699,34 +3671,65 @@
|
|
|
3699
3671
|
});
|
|
3700
3672
|
var _a;
|
|
3701
3673
|
return __awaiter(this, void 0, void 0, function () {
|
|
3702
|
-
var
|
|
3703
|
-
return __generator(this, function (
|
|
3704
|
-
switch (
|
|
3674
|
+
var _c;
|
|
3675
|
+
return __generator(this, function (_d) {
|
|
3676
|
+
switch (_d.label) {
|
|
3705
3677
|
case 0:
|
|
3706
3678
|
if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
|
|
3707
3679
|
return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
|
|
3708
3680
|
case 1:
|
|
3709
|
-
|
|
3681
|
+
_c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
|
|
3710
3682
|
return [3 /*break*/, 3];
|
|
3711
3683
|
case 2:
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
case 3: return [2 /*return*/,
|
|
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];
|
|
3715
3718
|
}
|
|
3716
3719
|
});
|
|
3717
3720
|
});
|
|
3718
3721
|
};
|
|
3719
3722
|
CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
|
|
3720
3723
|
return __awaiter(this, void 0, void 0, function () {
|
|
3721
|
-
var
|
|
3722
|
-
return __generator(this, function (
|
|
3723
|
-
switch (
|
|
3724
|
+
var _c, data, count;
|
|
3725
|
+
return __generator(this, function (_d) {
|
|
3726
|
+
switch (_d.label) {
|
|
3724
3727
|
case 0:
|
|
3725
3728
|
if (!slug)
|
|
3726
3729
|
return [2 /*return*/];
|
|
3727
3730
|
return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
|
|
3728
3731
|
case 1:
|
|
3729
|
-
|
|
3732
|
+
_c = _d.sent(), data = _c.data, count = _c.count;
|
|
3730
3733
|
if (count > 1)
|
|
3731
3734
|
throw new DuplicatedResultsError('Query returned duplicated values');
|
|
3732
3735
|
if (!count)
|
|
@@ -3739,33 +3742,33 @@
|
|
|
3739
3742
|
CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
|
|
3740
3743
|
if (limit === void 0) { limit = 4; }
|
|
3741
3744
|
return __awaiter(this, void 0, void 0, function () {
|
|
3742
|
-
var
|
|
3745
|
+
var _c, categories, count, homeSections;
|
|
3743
3746
|
var _this = this;
|
|
3744
|
-
return __generator(this, function (
|
|
3745
|
-
switch (
|
|
3747
|
+
return __generator(this, function (_d) {
|
|
3748
|
+
switch (_d.label) {
|
|
3746
3749
|
case 0: return [4 /*yield*/, this.find({
|
|
3747
3750
|
filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
|
|
3748
3751
|
})];
|
|
3749
3752
|
case 1:
|
|
3750
|
-
|
|
3753
|
+
_c = _d.sent(), categories = _c.data, count = _c.count;
|
|
3751
3754
|
if (!count)
|
|
3752
3755
|
throw new NotFoundError('Categories not found');
|
|
3753
3756
|
return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
3754
|
-
var
|
|
3755
|
-
return __generator(this, function (
|
|
3756
|
-
switch (
|
|
3757
|
+
var _c;
|
|
3758
|
+
return __generator(this, function (_d) {
|
|
3759
|
+
switch (_d.label) {
|
|
3757
3760
|
case 0:
|
|
3758
|
-
|
|
3761
|
+
_c = {
|
|
3759
3762
|
category: category
|
|
3760
3763
|
};
|
|
3761
3764
|
return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
|
|
3762
|
-
case 1: return [2 /*return*/, (
|
|
3763
|
-
|
|
3765
|
+
case 1: return [2 /*return*/, (_c.products = _d.sent(),
|
|
3766
|
+
_c)];
|
|
3764
3767
|
}
|
|
3765
3768
|
});
|
|
3766
3769
|
}); }))];
|
|
3767
3770
|
case 2:
|
|
3768
|
-
homeSections =
|
|
3771
|
+
homeSections = _d.sent();
|
|
3769
3772
|
return [2 /*return*/, homeSections];
|
|
3770
3773
|
}
|
|
3771
3774
|
});
|
|
@@ -3774,8 +3777,8 @@
|
|
|
3774
3777
|
CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
|
|
3775
3778
|
return __awaiter(this, void 0, void 0, function () {
|
|
3776
3779
|
var products, productsData;
|
|
3777
|
-
return __generator(this, function (
|
|
3778
|
-
switch (
|
|
3780
|
+
return __generator(this, function (_c) {
|
|
3781
|
+
switch (_c.label) {
|
|
3779
3782
|
case 0:
|
|
3780
3783
|
if (!category.products)
|
|
3781
3784
|
throw new RequiredArgumentError(['Category products is empty']);
|
|
@@ -3804,13 +3807,77 @@
|
|
|
3804
3807
|
'tags',
|
|
3805
3808
|
] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
|
|
3806
3809
|
case 1:
|
|
3807
|
-
productsData = (
|
|
3810
|
+
productsData = (_c.sent()).data;
|
|
3808
3811
|
products.push.apply(products, __spreadArray([], __read(productsData)));
|
|
3809
3812
|
return [2 /*return*/, products];
|
|
3810
3813
|
}
|
|
3811
3814
|
});
|
|
3812
3815
|
});
|
|
3813
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
|
+
};
|
|
3814
3881
|
return CategoryHasuraGraphQLRepository;
|
|
3815
3882
|
}(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
|
|
3816
3883
|
|
|
@@ -3921,6 +3988,13 @@
|
|
|
3921
3988
|
],
|
|
3922
3989
|
},
|
|
3923
3990
|
},
|
|
3991
|
+
{
|
|
3992
|
+
reviews: {
|
|
3993
|
+
columnName: 'reviews',
|
|
3994
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
3995
|
+
fields: _this.reviewsFields,
|
|
3996
|
+
},
|
|
3997
|
+
},
|
|
3924
3998
|
{
|
|
3925
3999
|
metadata: {
|
|
3926
4000
|
columnName: 'metadata',
|
|
@@ -3955,15 +4029,17 @@
|
|
|
3955
4029
|
enumerable: false,
|
|
3956
4030
|
configurable: true
|
|
3957
4031
|
});
|
|
3958
|
-
ProductHasuraGraphQLRepository.prototype.create = function (
|
|
4032
|
+
ProductHasuraGraphQLRepository.prototype.create = function (params) {
|
|
3959
4033
|
var _super = Object.create(null, {
|
|
3960
4034
|
create: { get: function () { return _super_1.prototype.create; } }
|
|
3961
4035
|
});
|
|
3962
4036
|
return __awaiter(this, void 0, void 0, function () {
|
|
3963
|
-
var product, _c, error_1;
|
|
4037
|
+
var metadata, data, product, _c, error_1;
|
|
3964
4038
|
return __generator(this, function (_d) {
|
|
3965
4039
|
switch (_d.label) {
|
|
3966
|
-
case 0:
|
|
4040
|
+
case 0:
|
|
4041
|
+
metadata = params.metadata, data = __rest(params, ["metadata"]);
|
|
4042
|
+
return [4 /*yield*/, _super.create.call(this, lodash.omit(Object.assign(Object.assign({}, data), { metadata: metadata || { description: null, title: null } }), ['reviews']))];
|
|
3967
4043
|
case 1:
|
|
3968
4044
|
product = _d.sent();
|
|
3969
4045
|
_d.label = 2;
|
|
@@ -3991,27 +4067,32 @@
|
|
|
3991
4067
|
});
|
|
3992
4068
|
var _a;
|
|
3993
4069
|
return __awaiter(this, void 0, void 0, function () {
|
|
3994
|
-
var product, _c, _d;
|
|
3995
|
-
return __generator(this, function (
|
|
3996
|
-
switch (
|
|
4070
|
+
var product, _c, _d, _e;
|
|
4071
|
+
return __generator(this, function (_f) {
|
|
4072
|
+
switch (_f.label) {
|
|
3997
4073
|
case 0:
|
|
3998
4074
|
if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
|
|
3999
4075
|
return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
|
|
4000
4076
|
case 1:
|
|
4001
|
-
_c = (_a = (
|
|
4077
|
+
_c = (_a = (_f.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
|
|
4002
4078
|
return [3 /*break*/, 4];
|
|
4003
4079
|
case 2: return [4 /*yield*/, _super.get.call(this, identifiers)];
|
|
4004
4080
|
case 3:
|
|
4005
|
-
_c =
|
|
4006
|
-
|
|
4081
|
+
_c = _f.sent();
|
|
4082
|
+
_f.label = 4;
|
|
4007
4083
|
case 4:
|
|
4008
4084
|
product = _c;
|
|
4009
4085
|
if (product.productId)
|
|
4010
4086
|
throw new NotFoundError('Product not found, it is a variant');
|
|
4011
4087
|
_d = product;
|
|
4088
|
+
_e = product.reviews;
|
|
4089
|
+
if (_e) return [3 /*break*/, 6];
|
|
4012
4090
|
return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
|
|
4013
4091
|
case 5:
|
|
4014
|
-
|
|
4092
|
+
_e = (_f.sent());
|
|
4093
|
+
_f.label = 6;
|
|
4094
|
+
case 6:
|
|
4095
|
+
_d.reviews = _e;
|
|
4015
4096
|
return [2 /*return*/, product];
|
|
4016
4097
|
}
|
|
4017
4098
|
});
|
|
@@ -4022,10 +4103,14 @@
|
|
|
4022
4103
|
find: { get: function () { return _super_1.prototype.find; } }
|
|
4023
4104
|
});
|
|
4024
4105
|
return __awaiter(this, void 0, void 0, function () {
|
|
4025
|
-
var _a, filters, options;
|
|
4106
|
+
var _a, filters, fields, options, bindFields;
|
|
4026
4107
|
return __generator(this, function (_c) {
|
|
4027
|
-
_a = params || {}, filters = _a.filters, options = __rest(_a, ["filters"]);
|
|
4028
|
-
|
|
4108
|
+
_a = params || {}, filters = _a.filters, fields = _a.fields, options = __rest(_a, ["filters", "fields"]);
|
|
4109
|
+
bindFields = fields ||
|
|
4110
|
+
this.fields
|
|
4111
|
+
.map(function (field) { return (typeof field === 'string' ? field : Object.keys(field).shift()); })
|
|
4112
|
+
.filter(function (field) { return field !== 'reviews'; });
|
|
4113
|
+
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 }))];
|
|
4029
4114
|
});
|
|
4030
4115
|
});
|
|
4031
4116
|
};
|
|
@@ -4057,25 +4142,25 @@
|
|
|
4057
4142
|
update: { get: function () { return _super_1.prototype.update; } }
|
|
4058
4143
|
});
|
|
4059
4144
|
return __awaiter(this, void 0, void 0, function () {
|
|
4060
|
-
var categories, kitProducts, reviews, checkId, rate, data, plainData, id, product, _c, _d, _e, _f, _g, _h;
|
|
4061
|
-
return __generator(this, function (
|
|
4062
|
-
switch (
|
|
4145
|
+
var categories, kitProducts, reviews, checkId, rate, metadata, data, plainData, id, product, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
4146
|
+
return __generator(this, function (_l) {
|
|
4147
|
+
switch (_l.label) {
|
|
4063
4148
|
case 0:
|
|
4064
|
-
categories = params.categories, kitProducts = params.kitProducts, reviews = params.reviews, checkId = params.id, rate = params.rate, data = __rest(params, ["categories", "kitProducts", "reviews", "id", "rate"]);
|
|
4149
|
+
categories = params.categories, kitProducts = params.kitProducts, reviews = params.reviews, checkId = params.id, rate = params.rate, metadata = params.metadata, data = __rest(params, ["categories", "kitProducts", "reviews", "id", "rate", "metadata"]);
|
|
4065
4150
|
plainData = this.paramsToPlain({ id: checkId });
|
|
4066
4151
|
return [4 /*yield*/, this.getId(plainData.id)];
|
|
4067
4152
|
case 1:
|
|
4068
|
-
id =
|
|
4153
|
+
id = _l.sent();
|
|
4069
4154
|
return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
|
|
4070
4155
|
case 2:
|
|
4071
|
-
product =
|
|
4156
|
+
product = _l.sent();
|
|
4072
4157
|
_c = product;
|
|
4073
4158
|
_d = categories;
|
|
4074
4159
|
if (!_d) return [3 /*break*/, 4];
|
|
4075
4160
|
return [4 /*yield*/, this.updateCategories(+id, { categories: categories })];
|
|
4076
4161
|
case 3:
|
|
4077
|
-
_d = (
|
|
4078
|
-
|
|
4162
|
+
_d = (_l.sent());
|
|
4163
|
+
_l.label = 4;
|
|
4079
4164
|
case 4:
|
|
4080
4165
|
_c.categories = _d;
|
|
4081
4166
|
_e = product;
|
|
@@ -4083,8 +4168,8 @@
|
|
|
4083
4168
|
if (!_f) return [3 /*break*/, 6];
|
|
4084
4169
|
return [4 /*yield*/, this.updateKitProducts(+id, { kitProducts: kitProducts })];
|
|
4085
4170
|
case 5:
|
|
4086
|
-
_f = (
|
|
4087
|
-
|
|
4171
|
+
_f = (_l.sent());
|
|
4172
|
+
_l.label = 6;
|
|
4088
4173
|
case 6:
|
|
4089
4174
|
_e.kitProducts = _f;
|
|
4090
4175
|
_g = product;
|
|
@@ -4092,10 +4177,19 @@
|
|
|
4092
4177
|
if (!_h) return [3 /*break*/, 8];
|
|
4093
4178
|
return [4 /*yield*/, this.updateReviews(+id, { reviews: reviews })];
|
|
4094
4179
|
case 7:
|
|
4095
|
-
_h = (
|
|
4096
|
-
|
|
4180
|
+
_h = (_l.sent());
|
|
4181
|
+
_l.label = 8;
|
|
4097
4182
|
case 8:
|
|
4098
4183
|
_g.reviews = _h;
|
|
4184
|
+
_j = product;
|
|
4185
|
+
_k = metadata;
|
|
4186
|
+
if (!_k) return [3 /*break*/, 10];
|
|
4187
|
+
return [4 /*yield*/, this.updateMetadata(+id, { metadata: metadata })];
|
|
4188
|
+
case 9:
|
|
4189
|
+
_k = (_l.sent());
|
|
4190
|
+
_l.label = 10;
|
|
4191
|
+
case 10:
|
|
4192
|
+
_j.metadata = _k;
|
|
4099
4193
|
return [2 /*return*/, product];
|
|
4100
4194
|
}
|
|
4101
4195
|
});
|
|
@@ -4103,18 +4197,18 @@
|
|
|
4103
4197
|
};
|
|
4104
4198
|
ProductHasuraGraphQLRepository.prototype.fetchReviews = function (status) {
|
|
4105
4199
|
return __awaiter(this, void 0, void 0, function () {
|
|
4106
|
-
var
|
|
4200
|
+
var reviewsExpression, data;
|
|
4107
4201
|
var _c, _d;
|
|
4108
4202
|
var _this = this;
|
|
4109
4203
|
return __generator(this, function (_e) {
|
|
4110
4204
|
switch (_e.label) {
|
|
4111
4205
|
case 0:
|
|
4112
|
-
|
|
4206
|
+
reviewsExpression = {
|
|
4113
4207
|
status: status === 'pending'
|
|
4114
4208
|
? (_c = {}, _c[HasuraGraphQLWhere.ISNULL] = true, _c) : (_d = {}, _d[HasuraGraphQLWhere.EQUALS] = status === 'approved', _d),
|
|
4115
4209
|
};
|
|
4116
4210
|
return [4 /*yield*/, this.query('product', ['id', 'name', 'sku', { reviews: { columnName: 'reviews', fields: this.reviewsFields } }], {
|
|
4117
|
-
where: { value: { reviews:
|
|
4211
|
+
where: { value: { reviews: reviewsExpression }, type: 'product_bool_exp', required: true },
|
|
4118
4212
|
})];
|
|
4119
4213
|
case 1:
|
|
4120
4214
|
data = (_e.sent()).product;
|
|
@@ -4134,7 +4228,7 @@
|
|
|
4134
4228
|
return __generator(this, function (_c) {
|
|
4135
4229
|
switch (_c.label) {
|
|
4136
4230
|
case 0:
|
|
4137
|
-
|
|
4231
|
+
if (!('action' in categories && categories.action === 'remove')) return [3 /*break*/, 2];
|
|
4138
4232
|
return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
|
|
4139
4233
|
where: {
|
|
4140
4234
|
type: 'category_product_bool_exp',
|
|
@@ -4143,6 +4237,20 @@
|
|
|
4143
4237
|
},
|
|
4144
4238
|
})];
|
|
4145
4239
|
case 1:
|
|
4240
|
+
_c.sent();
|
|
4241
|
+
return [2 /*return*/, []];
|
|
4242
|
+
case 2:
|
|
4243
|
+
plainData = this.paramsToPlain({ categories: categories });
|
|
4244
|
+
if (!plainData.categories || plainData.categories.length <= 0)
|
|
4245
|
+
return [2 /*return*/, []];
|
|
4246
|
+
return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
|
|
4247
|
+
where: {
|
|
4248
|
+
type: 'category_product_bool_exp',
|
|
4249
|
+
required: true,
|
|
4250
|
+
value: { product_id: { _eq: productId } },
|
|
4251
|
+
},
|
|
4252
|
+
})];
|
|
4253
|
+
case 3:
|
|
4146
4254
|
_c.sent();
|
|
4147
4255
|
return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
|
|
4148
4256
|
objects: {
|
|
@@ -4151,7 +4259,7 @@
|
|
|
4151
4259
|
value: plainData.categories.map(function (categoryId) { return ({ category_id: categoryId, product_id: productId }); }),
|
|
4152
4260
|
},
|
|
4153
4261
|
})];
|
|
4154
|
-
case
|
|
4262
|
+
case 4:
|
|
4155
4263
|
_c.sent();
|
|
4156
4264
|
return [2 /*return*/, plainData.categories];
|
|
4157
4265
|
}
|
|
@@ -4225,6 +4333,8 @@
|
|
|
4225
4333
|
return [2 /*return*/, reviews.value.map(function (review, index) { return !reviewIds_1[index] && review; }).filter(Boolean)];
|
|
4226
4334
|
case 3:
|
|
4227
4335
|
plainData = this.paramsToPlain({ reviews: reviews });
|
|
4336
|
+
if (!plainData.reviews || plainData.reviews.length <= 0)
|
|
4337
|
+
return [2 /*return*/, []];
|
|
4228
4338
|
return [2 /*return*/, Promise.all(plainData.reviews.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
|
|
4229
4339
|
var review, _c, _d;
|
|
4230
4340
|
return __generator(this, function (_e) {
|
|
@@ -4264,6 +4374,35 @@
|
|
|
4264
4374
|
});
|
|
4265
4375
|
});
|
|
4266
4376
|
};
|
|
4377
|
+
ProductHasuraGraphQLRepository.prototype.updateMetadata = function (productId, _c) {
|
|
4378
|
+
var metadata = _c.metadata;
|
|
4379
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4380
|
+
var plainData;
|
|
4381
|
+
return __generator(this, function (_c) {
|
|
4382
|
+
switch (_c.label) {
|
|
4383
|
+
case 0:
|
|
4384
|
+
plainData = this.paramsToPlain({ metadata: metadata });
|
|
4385
|
+
if (!plainData.metadata)
|
|
4386
|
+
return [2 /*return*/];
|
|
4387
|
+
return [4 /*yield*/, this.mutation('update_product_metadata_by_pk', ['product_id'], {
|
|
4388
|
+
pk_columns: {
|
|
4389
|
+
value: { product_id: productId },
|
|
4390
|
+
type: 'product_metadata_pk_columns_input',
|
|
4391
|
+
required: true,
|
|
4392
|
+
},
|
|
4393
|
+
_set: {
|
|
4394
|
+
value: lodash.omit(metadata, ['product_id']),
|
|
4395
|
+
type: 'product_metadata_set_input',
|
|
4396
|
+
required: true,
|
|
4397
|
+
},
|
|
4398
|
+
})];
|
|
4399
|
+
case 1:
|
|
4400
|
+
_c.sent();
|
|
4401
|
+
return [2 /*return*/, plainData.metadata];
|
|
4402
|
+
}
|
|
4403
|
+
});
|
|
4404
|
+
});
|
|
4405
|
+
};
|
|
4267
4406
|
ProductHasuraGraphQLRepository.prototype.getId = function (id) {
|
|
4268
4407
|
var _a, _b;
|
|
4269
4408
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -4694,7 +4833,6 @@
|
|
|
4694
4833
|
exports.UserFirestoreRepository = UserFirestoreRepository;
|
|
4695
4834
|
exports.UserPaymentMethod = UserPaymentMethod;
|
|
4696
4835
|
exports.UserPaymentMethodFirestoreRepository = UserPaymentMethodFirestoreRepository;
|
|
4697
|
-
exports.UserSearchFirestoreRepository = UserSearchFirestoreRepository;
|
|
4698
4836
|
exports.Variant = Variant;
|
|
4699
4837
|
exports.VariantHasuraGraphQL = VariantHasuraGraphQL;
|
|
4700
4838
|
exports.VariantHasuraGraphQLRepository = VariantHasuraGraphQLRepository;
|