@infrab4a/connect 1.0.0-beta.19 → 1.0.0-beta.21
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 +356 -60
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/domain/catalog/models/types/product-review.type.d.ts +10 -8
- package/domain/catalog/repositories/product.repository.d.ts +8 -1
- package/domain/generic/repository/types/repository-find-filters.type.d.ts +1 -1
- package/esm2015/domain/catalog/models/types/product-review.type.js +1 -1
- package/esm2015/domain/catalog/repositories/product.repository.js +1 -1
- package/esm2015/domain/generic/repository/types/repository-find-filters.type.js +1 -1
- package/esm2015/infra/firebase/firestore/repositories/catalog/product-firestore.repository.js +30 -2
- package/esm2015/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.js +6 -2
- package/esm2015/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.js +2 -2
- package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +190 -35
- package/esm2015/infra/hasura-graphql/types/graphql.repository.type.js +1 -1
- package/esm2015/infra/hasura-graphql/types/hasura-graphql-fields.type.js +1 -1
- package/fesm2015/infrab4a-connect.js +222 -35
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +3 -1
- package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +2 -2
- package/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +2 -2
- package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +11 -1
- package/infra/hasura-graphql/types/graphql.repository.type.d.ts +2 -2
- package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +1 -1
- package/package.json +1 -1
|
@@ -2445,6 +2445,7 @@
|
|
|
2445
2445
|
function ProductFirestoreRepository(firestore) {
|
|
2446
2446
|
var _this = _super.call(this) || this;
|
|
2447
2447
|
_this.firestore = firestore;
|
|
2448
|
+
_this.reviews = {};
|
|
2448
2449
|
_this.collectionName = 'products';
|
|
2449
2450
|
_this.model = Product;
|
|
2450
2451
|
return _this;
|
|
@@ -2468,6 +2469,41 @@
|
|
|
2468
2469
|
});
|
|
2469
2470
|
});
|
|
2470
2471
|
};
|
|
2472
|
+
ProductFirestoreRepository.prototype.fetchReviews = function (status) {
|
|
2473
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2474
|
+
var products;
|
|
2475
|
+
var _this = this;
|
|
2476
|
+
return __generator(this, function (_b) {
|
|
2477
|
+
switch (_b.label) {
|
|
2478
|
+
case 0: return [4 /*yield*/, this.find()];
|
|
2479
|
+
case 1:
|
|
2480
|
+
products = (_b.sent()).data;
|
|
2481
|
+
products.forEach(function (product) {
|
|
2482
|
+
var _a;
|
|
2483
|
+
if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
|
|
2484
|
+
return;
|
|
2485
|
+
var productInfo = {
|
|
2486
|
+
productId: product.id,
|
|
2487
|
+
productName: product.name,
|
|
2488
|
+
productSku: product.sku,
|
|
2489
|
+
};
|
|
2490
|
+
_this.reviews.pending = [];
|
|
2491
|
+
_this.reviews.approved = [];
|
|
2492
|
+
_this.reviews.rejected = [];
|
|
2493
|
+
product.reviews.forEach(function (review) {
|
|
2494
|
+
if ([null, undefined].includes(review.status))
|
|
2495
|
+
return _this.reviews.pending.push(Object.assign(Object.assign({}, review), productInfo));
|
|
2496
|
+
if (review.status === false)
|
|
2497
|
+
return _this.reviews.rejected.push(Object.assign(Object.assign({}, review), productInfo));
|
|
2498
|
+
if (!!review.status)
|
|
2499
|
+
return _this.reviews.approved.push(Object.assign(Object.assign({}, review), productInfo));
|
|
2500
|
+
});
|
|
2501
|
+
});
|
|
2502
|
+
return [2 /*return*/, this.reviews[status]];
|
|
2503
|
+
}
|
|
2504
|
+
});
|
|
2505
|
+
});
|
|
2506
|
+
};
|
|
2471
2507
|
return ProductFirestoreRepository;
|
|
2472
2508
|
}(withCrudFirestore(withHelpers(withFirestore(Base)))));
|
|
2473
2509
|
|
|
@@ -2934,11 +2970,11 @@
|
|
|
2934
2970
|
CreateHasuraGraphQLMixin.prototype.create = function (data) {
|
|
2935
2971
|
return __awaiter(this, void 0, void 0, function () {
|
|
2936
2972
|
var newData;
|
|
2937
|
-
return __generator(this, function (
|
|
2938
|
-
switch (
|
|
2973
|
+
return __generator(this, function (_b) {
|
|
2974
|
+
switch (_b.label) {
|
|
2939
2975
|
case 0: return [4 /*yield*/, this.save(this.model.toInstance(data))];
|
|
2940
2976
|
case 1:
|
|
2941
|
-
newData =
|
|
2977
|
+
newData = _b.sent();
|
|
2942
2978
|
return [2 /*return*/, this.model.toInstance(newData)];
|
|
2943
2979
|
}
|
|
2944
2980
|
});
|
|
@@ -2948,19 +2984,23 @@
|
|
|
2948
2984
|
return __awaiter(this, void 0, void 0, function () {
|
|
2949
2985
|
var primaryKeyColumns, foreignKeyColumns, result;
|
|
2950
2986
|
var _this = this;
|
|
2951
|
-
return __generator(this, function (
|
|
2952
|
-
switch (
|
|
2987
|
+
return __generator(this, function (_b) {
|
|
2988
|
+
switch (_b.label) {
|
|
2953
2989
|
case 0:
|
|
2954
2990
|
primaryKeyColumns = this.model.identifiersFields.map(function (field) { return AttributeOptionHelper.FindByAttribute(field, _this.fields).columnName; });
|
|
2955
2991
|
foreignKeyColumns = this.fields
|
|
2956
2992
|
.map(function (field) {
|
|
2957
|
-
var
|
|
2993
|
+
var _b;
|
|
2958
2994
|
var columnOptions = Object.values(field).shift();
|
|
2959
2995
|
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
2960
2996
|
columnOptions.foreignKeyColumn && __spreadArray(__spreadArray([], __read(Object.values(columnOptions.foreignKeyColumn))), [
|
|
2961
|
-
(
|
|
2962
|
-
|
|
2963
|
-
|
|
2997
|
+
(_b = {},
|
|
2998
|
+
_b[columnOptions.columnName] = Object.keys(columnOptions.foreignKeyColumn).map(function (foreignKeyField) {
|
|
2999
|
+
var _a;
|
|
3000
|
+
return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) ||
|
|
3001
|
+
foreignKeyField;
|
|
3002
|
+
}),
|
|
3003
|
+
_b),
|
|
2964
3004
|
]));
|
|
2965
3005
|
})
|
|
2966
3006
|
.filter(Boolean)
|
|
@@ -2969,7 +3009,7 @@
|
|
|
2969
3009
|
object: { type: this.insertGraphQLObjectType, required: true, value: this.convertDataToHasura(data) },
|
|
2970
3010
|
})];
|
|
2971
3011
|
case 1:
|
|
2972
|
-
result =
|
|
3012
|
+
result = _b.sent();
|
|
2973
3013
|
return [2 /*return*/, Object.assign(Object.assign({}, data.toPlain()), this.convertDataFromHasura(result[this.insertGraphQLOperation]).toPlain())];
|
|
2974
3014
|
}
|
|
2975
3015
|
});
|
|
@@ -3146,7 +3186,7 @@
|
|
|
3146
3186
|
var getValueByAction = function (options) {
|
|
3147
3187
|
if (options instanceof BaseModel)
|
|
3148
3188
|
return options.toPlain();
|
|
3149
|
-
if (lodash.isNil(options.action))
|
|
3189
|
+
if (lodash.isNil(options === null || options === void 0 ? void 0 : options.action))
|
|
3150
3190
|
return options;
|
|
3151
3191
|
if ([exports.UpdateOptionActions.REMOVE_FIELD.toString(), exports.UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
3152
3192
|
return null;
|
|
@@ -3613,7 +3653,15 @@
|
|
|
3613
3653
|
var ProductHasuraGraphQLRepository = /** @class */ (function (_super_1) {
|
|
3614
3654
|
__extends(ProductHasuraGraphQLRepository, _super_1);
|
|
3615
3655
|
function ProductHasuraGraphQLRepository(endpoint, authOptions) {
|
|
3616
|
-
var _this = this
|
|
3656
|
+
var _this = _super_1.call(this, {
|
|
3657
|
+
tableName: 'product',
|
|
3658
|
+
model: ProductHasuraGraphQL,
|
|
3659
|
+
endpoint: endpoint,
|
|
3660
|
+
authOptions: authOptions,
|
|
3661
|
+
fields: [],
|
|
3662
|
+
}) || this;
|
|
3663
|
+
_this.bindReviewToModel = function (plain) { return (Object.assign(Object.assign({}, lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])), { createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at, updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at, personId: plain.person_id, orderId: plain.order_id })); };
|
|
3664
|
+
_this.bindReviewToHasura = function (review) { return (Object.assign(Object.assign({}, lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])), { person_id: review.personId, order_id: review.orderId })); };
|
|
3617
3665
|
var commonFields = [
|
|
3618
3666
|
{ id: { columnName: 'id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
|
|
3619
3667
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -3694,58 +3742,111 @@
|
|
|
3694
3742
|
{ createdAt: { columnName: 'created_at' } },
|
|
3695
3743
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
3696
3744
|
];
|
|
3697
|
-
_this =
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
bindPersistData: function (value) { return ({
|
|
3708
|
-
categories: { data: value.map(function (category) { return ({ category_id: +category }); }) },
|
|
3709
|
-
}); },
|
|
3710
|
-
to: function (categories) { return categories.map(function (categoryId) { return +categoryId; }); },
|
|
3711
|
-
from: function (categories) { return (categories === null || categories === void 0 ? void 0 : categories.map(function (category) { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || []; },
|
|
3712
|
-
},
|
|
3745
|
+
_this.fields = __spreadArray(__spreadArray([], __read(commonFields)), [
|
|
3746
|
+
{
|
|
3747
|
+
categories: {
|
|
3748
|
+
columnName: 'categories',
|
|
3749
|
+
fields: ['category_id'],
|
|
3750
|
+
bindPersistData: function (value) { return ({
|
|
3751
|
+
categories: { data: value.map(function (category) { return ({ category_id: +category }); }) },
|
|
3752
|
+
}); },
|
|
3753
|
+
to: function (categories) { return categories.map(function (categoryId) { return +categoryId; }); },
|
|
3754
|
+
from: function (categories) { return (categories === null || categories === void 0 ? void 0 : categories.map(function (category) { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || []; },
|
|
3713
3755
|
},
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3756
|
+
},
|
|
3757
|
+
{
|
|
3758
|
+
kitProducts: {
|
|
3759
|
+
columnName: 'kit_products',
|
|
3760
|
+
foreignKeyColumn: { productId: 'id' },
|
|
3761
|
+
fields: [
|
|
3762
|
+
{ productId: { columnName: 'product_id' } },
|
|
3763
|
+
{ kitProductId: { columnName: 'kit_product_id' } },
|
|
3764
|
+
'quantity',
|
|
3765
|
+
{ product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
|
|
3766
|
+
],
|
|
3725
3767
|
},
|
|
3726
|
-
|
|
3727
|
-
|
|
3768
|
+
},
|
|
3769
|
+
]);
|
|
3728
3770
|
return _this;
|
|
3729
3771
|
}
|
|
3772
|
+
Object.defineProperty(ProductHasuraGraphQLRepository.prototype, "reviewsFields", {
|
|
3773
|
+
get: function () {
|
|
3774
|
+
return [
|
|
3775
|
+
'id',
|
|
3776
|
+
'shop',
|
|
3777
|
+
'rate',
|
|
3778
|
+
'author',
|
|
3779
|
+
'email',
|
|
3780
|
+
'location',
|
|
3781
|
+
'review',
|
|
3782
|
+
'status',
|
|
3783
|
+
'title',
|
|
3784
|
+
'person_id',
|
|
3785
|
+
'points',
|
|
3786
|
+
'order_id',
|
|
3787
|
+
'created_at',
|
|
3788
|
+
'updated_at',
|
|
3789
|
+
];
|
|
3790
|
+
},
|
|
3791
|
+
enumerable: false,
|
|
3792
|
+
configurable: true
|
|
3793
|
+
});
|
|
3794
|
+
ProductHasuraGraphQLRepository.prototype.create = function (data) {
|
|
3795
|
+
var _super = Object.create(null, {
|
|
3796
|
+
create: { get: function () { return _super_1.prototype.create; } }
|
|
3797
|
+
});
|
|
3798
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3799
|
+
var product, _c, error_1;
|
|
3800
|
+
return __generator(this, function (_d) {
|
|
3801
|
+
switch (_d.label) {
|
|
3802
|
+
case 0: return [4 /*yield*/, _super.create.call(this, lodash.omit(data, ['reviews']))];
|
|
3803
|
+
case 1:
|
|
3804
|
+
product = _d.sent();
|
|
3805
|
+
_d.label = 2;
|
|
3806
|
+
case 2:
|
|
3807
|
+
_d.trys.push([2, 4, , 6]);
|
|
3808
|
+
_c = product;
|
|
3809
|
+
return [4 /*yield*/, this.updateReviews(+product.id, data)];
|
|
3810
|
+
case 3:
|
|
3811
|
+
_c.reviews = _d.sent();
|
|
3812
|
+
return [3 /*break*/, 6];
|
|
3813
|
+
case 4:
|
|
3814
|
+
error_1 = _d.sent();
|
|
3815
|
+
return [4 /*yield*/, this.delete({ id: product.id })];
|
|
3816
|
+
case 5:
|
|
3817
|
+
_d.sent();
|
|
3818
|
+
throw error_1;
|
|
3819
|
+
case 6: return [2 /*return*/, product];
|
|
3820
|
+
}
|
|
3821
|
+
});
|
|
3822
|
+
});
|
|
3823
|
+
};
|
|
3730
3824
|
ProductHasuraGraphQLRepository.prototype.get = function (identifiers) {
|
|
3731
3825
|
var _super = Object.create(null, {
|
|
3732
3826
|
get: { get: function () { return _super_1.prototype.get; } }
|
|
3733
3827
|
});
|
|
3734
3828
|
var _a;
|
|
3735
3829
|
return __awaiter(this, void 0, void 0, function () {
|
|
3736
|
-
var _c;
|
|
3737
|
-
return __generator(this, function (
|
|
3738
|
-
switch (
|
|
3830
|
+
var product, _c, _d;
|
|
3831
|
+
return __generator(this, function (_e) {
|
|
3832
|
+
switch (_e.label) {
|
|
3739
3833
|
case 0:
|
|
3740
3834
|
if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
|
|
3741
3835
|
return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
|
|
3742
3836
|
case 1:
|
|
3743
|
-
_c = (_a = (
|
|
3744
|
-
return [3 /*break*/,
|
|
3745
|
-
case 2:
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3837
|
+
_c = (_a = (_e.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
|
|
3838
|
+
return [3 /*break*/, 4];
|
|
3839
|
+
case 2: return [4 /*yield*/, _super.get.call(this, identifiers)];
|
|
3840
|
+
case 3:
|
|
3841
|
+
_c = _e.sent();
|
|
3842
|
+
_e.label = 4;
|
|
3843
|
+
case 4:
|
|
3844
|
+
product = _c;
|
|
3845
|
+
_d = product;
|
|
3846
|
+
return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
|
|
3847
|
+
case 5:
|
|
3848
|
+
_d.reviews = _e.sent();
|
|
3849
|
+
return [2 /*return*/, product];
|
|
3749
3850
|
}
|
|
3750
3851
|
});
|
|
3751
3852
|
});
|
|
@@ -3774,25 +3875,25 @@
|
|
|
3774
3875
|
update: { get: function () { return _super_1.prototype.update; } }
|
|
3775
3876
|
});
|
|
3776
3877
|
return __awaiter(this, void 0, void 0, function () {
|
|
3777
|
-
var categories, kitProducts, checkId, data, plainData, id, product, _c, _d, _e, _f;
|
|
3778
|
-
return __generator(this, function (
|
|
3779
|
-
switch (
|
|
3878
|
+
var categories, kitProducts, reviews, checkId, data, plainData, id, product, _c, _d, _e, _f, _g, _h;
|
|
3879
|
+
return __generator(this, function (_j) {
|
|
3880
|
+
switch (_j.label) {
|
|
3780
3881
|
case 0:
|
|
3781
|
-
categories = params.categories, kitProducts = params.kitProducts, checkId = params.id, data = __rest(params, ["categories", "kitProducts", "id"]);
|
|
3882
|
+
categories = params.categories, kitProducts = params.kitProducts, reviews = params.reviews, checkId = params.id, data = __rest(params, ["categories", "kitProducts", "reviews", "id"]);
|
|
3782
3883
|
plainData = this.paramsToPlain({ id: checkId });
|
|
3783
3884
|
return [4 /*yield*/, this.getId(plainData.id)];
|
|
3784
3885
|
case 1:
|
|
3785
|
-
id =
|
|
3886
|
+
id = _j.sent();
|
|
3786
3887
|
return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
|
|
3787
3888
|
case 2:
|
|
3788
|
-
product =
|
|
3889
|
+
product = _j.sent();
|
|
3789
3890
|
_c = product;
|
|
3790
3891
|
_d = categories;
|
|
3791
3892
|
if (!_d) return [3 /*break*/, 4];
|
|
3792
3893
|
return [4 /*yield*/, this.updateCategories(+id, { categories: categories })];
|
|
3793
3894
|
case 3:
|
|
3794
|
-
_d = (
|
|
3795
|
-
|
|
3895
|
+
_d = (_j.sent());
|
|
3896
|
+
_j.label = 4;
|
|
3796
3897
|
case 4:
|
|
3797
3898
|
_c.categories = _d;
|
|
3798
3899
|
_e = product;
|
|
@@ -3800,15 +3901,50 @@
|
|
|
3800
3901
|
if (!_f) return [3 /*break*/, 6];
|
|
3801
3902
|
return [4 /*yield*/, this.updateKitProducts(+id, { kitProducts: kitProducts })];
|
|
3802
3903
|
case 5:
|
|
3803
|
-
_f = (
|
|
3804
|
-
|
|
3904
|
+
_f = (_j.sent());
|
|
3905
|
+
_j.label = 6;
|
|
3805
3906
|
case 6:
|
|
3806
3907
|
_e.kitProducts = _f;
|
|
3908
|
+
_g = product;
|
|
3909
|
+
_h = reviews;
|
|
3910
|
+
if (!_h) return [3 /*break*/, 8];
|
|
3911
|
+
return [4 /*yield*/, this.updateReviews(+id, { reviews: reviews })];
|
|
3912
|
+
case 7:
|
|
3913
|
+
_h = (_j.sent());
|
|
3914
|
+
_j.label = 8;
|
|
3915
|
+
case 8:
|
|
3916
|
+
_g.reviews = _h;
|
|
3807
3917
|
return [2 /*return*/, product];
|
|
3808
3918
|
}
|
|
3809
3919
|
});
|
|
3810
3920
|
});
|
|
3811
3921
|
};
|
|
3922
|
+
ProductHasuraGraphQLRepository.prototype.fetchReviews = function (status) {
|
|
3923
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3924
|
+
var reviews, data;
|
|
3925
|
+
var _c, _d;
|
|
3926
|
+
var _this = this;
|
|
3927
|
+
return __generator(this, function (_e) {
|
|
3928
|
+
switch (_e.label) {
|
|
3929
|
+
case 0:
|
|
3930
|
+
reviews = {
|
|
3931
|
+
status: status === 'pending'
|
|
3932
|
+
? (_c = {}, _c[HasuraGraphQLWhere.ISNULL] = true, _c) : (_d = {}, _d[HasuraGraphQLWhere.EQUALS] = status === 'approved', _d),
|
|
3933
|
+
};
|
|
3934
|
+
return [4 /*yield*/, this.query('product', ['id', 'name', 'sku', { reviews: { columnName: 'reviews', fields: this.reviewsFields } }], {
|
|
3935
|
+
where: { value: { reviews: reviews }, type: 'product_bool_exp', required: true },
|
|
3936
|
+
})];
|
|
3937
|
+
case 1:
|
|
3938
|
+
data = (_e.sent()).product;
|
|
3939
|
+
return [2 /*return*/, data.reduce(function (reviews, product) { return __spreadArray(__spreadArray([], __read(reviews)), __read(product.reviews
|
|
3940
|
+
.filter(function (review) { return (status === 'pending' && [undefined, null].includes(review.status)) ||
|
|
3941
|
+
(status === 'approved' && review.status === true) ||
|
|
3942
|
+
(status === 'rejected' && review.status === false); })
|
|
3943
|
+
.map(function (review) { return (Object.assign(Object.assign({}, _this.bindReviewToModel(review)), { productId: product.id, productName: product.name, productSku: product.sku })); }))); }, [])];
|
|
3944
|
+
}
|
|
3945
|
+
});
|
|
3946
|
+
});
|
|
3947
|
+
};
|
|
3812
3948
|
ProductHasuraGraphQLRepository.prototype.updateCategories = function (productId, _c) {
|
|
3813
3949
|
var categories = _c.categories;
|
|
3814
3950
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3875,6 +4011,75 @@
|
|
|
3875
4011
|
});
|
|
3876
4012
|
});
|
|
3877
4013
|
};
|
|
4014
|
+
ProductHasuraGraphQLRepository.prototype.updateReviews = function (productId, _c) {
|
|
4015
|
+
var reviews = _c.reviews;
|
|
4016
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4017
|
+
var reviewIds_1, plainData;
|
|
4018
|
+
var _this = this;
|
|
4019
|
+
return __generator(this, function (_c) {
|
|
4020
|
+
switch (_c.label) {
|
|
4021
|
+
case 0:
|
|
4022
|
+
if (!('action' in reviews && reviews.action === 'remove')) return [3 /*break*/, 3];
|
|
4023
|
+
return [4 /*yield*/, Promise.all(reviews.value.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
|
|
4024
|
+
var review;
|
|
4025
|
+
return __generator(this, function (_c) {
|
|
4026
|
+
switch (_c.label) {
|
|
4027
|
+
case 0: return [4 /*yield*/, this.findReview(reviewData, productId)];
|
|
4028
|
+
case 1:
|
|
4029
|
+
review = _c.sent();
|
|
4030
|
+
return [2 /*return*/, review === null || review === void 0 ? void 0 : review.id];
|
|
4031
|
+
}
|
|
4032
|
+
});
|
|
4033
|
+
}); }))];
|
|
4034
|
+
case 1:
|
|
4035
|
+
reviewIds_1 = _c.sent();
|
|
4036
|
+
return [4 /*yield*/, this.mutation('delete_product_review', ['affected_rows'], {
|
|
4037
|
+
where: { value: { id: { _in: reviewIds_1.filter(Boolean) } }, type: 'product_review_bool_exp', required: true },
|
|
4038
|
+
})];
|
|
4039
|
+
case 2:
|
|
4040
|
+
_c.sent();
|
|
4041
|
+
return [2 /*return*/, reviews.value.map(function (review, index) { return !reviewIds_1[index] && review; }).filter(Boolean)];
|
|
4042
|
+
case 3:
|
|
4043
|
+
plainData = this.paramsToPlain({ reviews: reviews });
|
|
4044
|
+
return [2 /*return*/, Promise.all(plainData.reviews.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
|
|
4045
|
+
var review, _c, _d;
|
|
4046
|
+
return __generator(this, function (_e) {
|
|
4047
|
+
switch (_e.label) {
|
|
4048
|
+
case 0: return [4 /*yield*/, this.findReview(reviewData, productId)];
|
|
4049
|
+
case 1:
|
|
4050
|
+
review = _e.sent();
|
|
4051
|
+
if (!review) return [3 /*break*/, 3];
|
|
4052
|
+
_c = this.bindReviewToModel;
|
|
4053
|
+
return [4 /*yield*/, this.mutation('update_product_review_by_pk', this.reviewsFields, {
|
|
4054
|
+
pk_columns: {
|
|
4055
|
+
value: { id: review.id },
|
|
4056
|
+
type: 'product_review_pk_columns_input',
|
|
4057
|
+
required: true,
|
|
4058
|
+
},
|
|
4059
|
+
_set: {
|
|
4060
|
+
value: lodash.omit(this.bindReviewToHasura(reviewData), ['id', 'product_id']),
|
|
4061
|
+
type: 'product_review_set_input',
|
|
4062
|
+
required: true,
|
|
4063
|
+
},
|
|
4064
|
+
})];
|
|
4065
|
+
case 2: return [2 /*return*/, _c.apply(this, [(_e.sent()).update_product_review_by_pk])];
|
|
4066
|
+
case 3:
|
|
4067
|
+
_d = this.bindReviewToModel;
|
|
4068
|
+
return [4 /*yield*/, this.mutation('insert_product_review_one', this.reviewsFields, {
|
|
4069
|
+
object: {
|
|
4070
|
+
value: lodash.omit(Object.assign(Object.assign({}, this.bindReviewToHasura(reviewData)), { product_id: productId }), ['id']),
|
|
4071
|
+
type: 'product_review_insert_input',
|
|
4072
|
+
required: true,
|
|
4073
|
+
},
|
|
4074
|
+
})];
|
|
4075
|
+
case 4: return [2 /*return*/, _d.apply(this, [(_e.sent()).insert_product_review_one])];
|
|
4076
|
+
}
|
|
4077
|
+
});
|
|
4078
|
+
}); }))];
|
|
4079
|
+
}
|
|
4080
|
+
});
|
|
4081
|
+
});
|
|
4082
|
+
};
|
|
3878
4083
|
ProductHasuraGraphQLRepository.prototype.getId = function (id) {
|
|
3879
4084
|
var _a, _b;
|
|
3880
4085
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3894,6 +4099,97 @@
|
|
|
3894
4099
|
});
|
|
3895
4100
|
});
|
|
3896
4101
|
};
|
|
4102
|
+
ProductHasuraGraphQLRepository.prototype.findReviewsByProduct = function (productId) {
|
|
4103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4104
|
+
var data;
|
|
4105
|
+
var _this = this;
|
|
4106
|
+
return __generator(this, function (_c) {
|
|
4107
|
+
switch (_c.label) {
|
|
4108
|
+
case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
|
|
4109
|
+
where: {
|
|
4110
|
+
value: {
|
|
4111
|
+
product_id: { _eq: productId },
|
|
4112
|
+
},
|
|
4113
|
+
type: 'product_review_bool_exp',
|
|
4114
|
+
required: true,
|
|
4115
|
+
},
|
|
4116
|
+
})];
|
|
4117
|
+
case 1:
|
|
4118
|
+
data = (_c.sent()).product_review;
|
|
4119
|
+
return [2 /*return*/, data && data.map(function (review) { return _this.bindReviewToModel(review); })];
|
|
4120
|
+
}
|
|
4121
|
+
});
|
|
4122
|
+
});
|
|
4123
|
+
};
|
|
4124
|
+
ProductHasuraGraphQLRepository.prototype.findReview = function (review, productId) {
|
|
4125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4126
|
+
var loadedReview;
|
|
4127
|
+
return __generator(this, function (_c) {
|
|
4128
|
+
switch (_c.label) {
|
|
4129
|
+
case 0:
|
|
4130
|
+
if (review.id)
|
|
4131
|
+
return [2 /*return*/, review];
|
|
4132
|
+
if (!review.personId) return [3 /*break*/, 2];
|
|
4133
|
+
return [4 /*yield*/, this.getReviewByPersonId(review.personId, productId)];
|
|
4134
|
+
case 1:
|
|
4135
|
+
loadedReview = _c.sent();
|
|
4136
|
+
_c.label = 2;
|
|
4137
|
+
case 2:
|
|
4138
|
+
if (!(!loadedReview && review.author && review.email)) return [3 /*break*/, 4];
|
|
4139
|
+
return [4 /*yield*/, this.getReviewByAuthorAndEmail(review.author, review.email, productId)];
|
|
4140
|
+
case 3:
|
|
4141
|
+
loadedReview = _c.sent();
|
|
4142
|
+
_c.label = 4;
|
|
4143
|
+
case 4: return [2 /*return*/, loadedReview || review];
|
|
4144
|
+
}
|
|
4145
|
+
});
|
|
4146
|
+
});
|
|
4147
|
+
};
|
|
4148
|
+
ProductHasuraGraphQLRepository.prototype.getReviewByPersonId = function (personId, productId) {
|
|
4149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4150
|
+
var data;
|
|
4151
|
+
return __generator(this, function (_c) {
|
|
4152
|
+
switch (_c.label) {
|
|
4153
|
+
case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
|
|
4154
|
+
where: {
|
|
4155
|
+
value: {
|
|
4156
|
+
product_id: { _eq: productId },
|
|
4157
|
+
person_id: { _eq: personId },
|
|
4158
|
+
},
|
|
4159
|
+
type: "product_review_bool_exp",
|
|
4160
|
+
required: true,
|
|
4161
|
+
},
|
|
4162
|
+
})];
|
|
4163
|
+
case 1:
|
|
4164
|
+
data = (_c.sent()).product_review;
|
|
4165
|
+
return [2 /*return*/, data && data[0] && this.bindReviewToModel(data[0])];
|
|
4166
|
+
}
|
|
4167
|
+
});
|
|
4168
|
+
});
|
|
4169
|
+
};
|
|
4170
|
+
ProductHasuraGraphQLRepository.prototype.getReviewByAuthorAndEmail = function (author, email, productId) {
|
|
4171
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4172
|
+
var data;
|
|
4173
|
+
return __generator(this, function (_c) {
|
|
4174
|
+
switch (_c.label) {
|
|
4175
|
+
case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
|
|
4176
|
+
where: {
|
|
4177
|
+
value: {
|
|
4178
|
+
product_id: { _eq: productId },
|
|
4179
|
+
author: { _eq: author },
|
|
4180
|
+
email: { _eq: email },
|
|
4181
|
+
},
|
|
4182
|
+
type: "product_review_bool_exp",
|
|
4183
|
+
required: true,
|
|
4184
|
+
},
|
|
4185
|
+
})];
|
|
4186
|
+
case 1:
|
|
4187
|
+
data = (_c.sent()).product_review;
|
|
4188
|
+
return [2 /*return*/, data && data[0] && this.bindReviewToModel(data[0])];
|
|
4189
|
+
}
|
|
4190
|
+
});
|
|
4191
|
+
});
|
|
4192
|
+
};
|
|
3897
4193
|
return ProductHasuraGraphQLRepository;
|
|
3898
4194
|
}(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
|
|
3899
4195
|
|