@infrab4a/connect 1.0.0-beta.19 → 1.0.0-beta.20
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 +293 -59
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/domain/catalog/models/types/product-review.type.d.ts +10 -8
- package/esm2015/domain/catalog/models/types/product-review.type.js +1 -1
- package/esm2015/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.js +6 -2
- package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +169 -34
- package/esm2015/infra/hasura-graphql/types/graphql.repository.type.js +1 -1
- package/fesm2015/infrab4a-connect.js +173 -34
- package/fesm2015/infrab4a-connect.js.map +1 -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 +10 -1
- package/infra/hasura-graphql/types/graphql.repository.type.d.ts +2 -2
- package/package.json +1 -1
|
@@ -2934,11 +2934,11 @@
|
|
|
2934
2934
|
CreateHasuraGraphQLMixin.prototype.create = function (data) {
|
|
2935
2935
|
return __awaiter(this, void 0, void 0, function () {
|
|
2936
2936
|
var newData;
|
|
2937
|
-
return __generator(this, function (
|
|
2938
|
-
switch (
|
|
2937
|
+
return __generator(this, function (_b) {
|
|
2938
|
+
switch (_b.label) {
|
|
2939
2939
|
case 0: return [4 /*yield*/, this.save(this.model.toInstance(data))];
|
|
2940
2940
|
case 1:
|
|
2941
|
-
newData =
|
|
2941
|
+
newData = _b.sent();
|
|
2942
2942
|
return [2 /*return*/, this.model.toInstance(newData)];
|
|
2943
2943
|
}
|
|
2944
2944
|
});
|
|
@@ -2948,19 +2948,23 @@
|
|
|
2948
2948
|
return __awaiter(this, void 0, void 0, function () {
|
|
2949
2949
|
var primaryKeyColumns, foreignKeyColumns, result;
|
|
2950
2950
|
var _this = this;
|
|
2951
|
-
return __generator(this, function (
|
|
2952
|
-
switch (
|
|
2951
|
+
return __generator(this, function (_b) {
|
|
2952
|
+
switch (_b.label) {
|
|
2953
2953
|
case 0:
|
|
2954
2954
|
primaryKeyColumns = this.model.identifiersFields.map(function (field) { return AttributeOptionHelper.FindByAttribute(field, _this.fields).columnName; });
|
|
2955
2955
|
foreignKeyColumns = this.fields
|
|
2956
2956
|
.map(function (field) {
|
|
2957
|
-
var
|
|
2957
|
+
var _b;
|
|
2958
2958
|
var columnOptions = Object.values(field).shift();
|
|
2959
2959
|
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
2960
2960
|
columnOptions.foreignKeyColumn && __spreadArray(__spreadArray([], __read(Object.values(columnOptions.foreignKeyColumn))), [
|
|
2961
|
-
(
|
|
2962
|
-
|
|
2963
|
-
|
|
2961
|
+
(_b = {},
|
|
2962
|
+
_b[columnOptions.columnName] = Object.keys(columnOptions.foreignKeyColumn).map(function (foreignKeyField) {
|
|
2963
|
+
var _a;
|
|
2964
|
+
return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) ||
|
|
2965
|
+
foreignKeyField;
|
|
2966
|
+
}),
|
|
2967
|
+
_b),
|
|
2964
2968
|
]));
|
|
2965
2969
|
})
|
|
2966
2970
|
.filter(Boolean)
|
|
@@ -2969,7 +2973,7 @@
|
|
|
2969
2973
|
object: { type: this.insertGraphQLObjectType, required: true, value: this.convertDataToHasura(data) },
|
|
2970
2974
|
})];
|
|
2971
2975
|
case 1:
|
|
2972
|
-
result =
|
|
2976
|
+
result = _b.sent();
|
|
2973
2977
|
return [2 /*return*/, Object.assign(Object.assign({}, data.toPlain()), this.convertDataFromHasura(result[this.insertGraphQLOperation]).toPlain())];
|
|
2974
2978
|
}
|
|
2975
2979
|
});
|
|
@@ -3613,7 +3617,15 @@
|
|
|
3613
3617
|
var ProductHasuraGraphQLRepository = /** @class */ (function (_super_1) {
|
|
3614
3618
|
__extends(ProductHasuraGraphQLRepository, _super_1);
|
|
3615
3619
|
function ProductHasuraGraphQLRepository(endpoint, authOptions) {
|
|
3616
|
-
var _this = this
|
|
3620
|
+
var _this = _super_1.call(this, {
|
|
3621
|
+
tableName: 'product',
|
|
3622
|
+
model: ProductHasuraGraphQL,
|
|
3623
|
+
endpoint: endpoint,
|
|
3624
|
+
authOptions: authOptions,
|
|
3625
|
+
fields: [],
|
|
3626
|
+
}) || this;
|
|
3627
|
+
_this.bindReviewToModel = function (plain) { return (Object.assign(Object.assign({}, lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])), { createdAt: plain.created_at, updatedAt: plain.updated_at, personId: plain.person_id, orderId: plain.order_id })); };
|
|
3628
|
+
_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
3629
|
var commonFields = [
|
|
3618
3630
|
{ id: { columnName: 'id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
|
|
3619
3631
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -3694,58 +3706,111 @@
|
|
|
3694
3706
|
{ createdAt: { columnName: 'created_at' } },
|
|
3695
3707
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
3696
3708
|
];
|
|
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
|
-
},
|
|
3709
|
+
_this.fields = __spreadArray(__spreadArray([], __read(commonFields)), [
|
|
3710
|
+
{
|
|
3711
|
+
categories: {
|
|
3712
|
+
columnName: 'categories',
|
|
3713
|
+
fields: ['category_id'],
|
|
3714
|
+
bindPersistData: function (value) { return ({
|
|
3715
|
+
categories: { data: value.map(function (category) { return ({ category_id: +category }); }) },
|
|
3716
|
+
}); },
|
|
3717
|
+
to: function (categories) { return categories.map(function (categoryId) { return +categoryId; }); },
|
|
3718
|
+
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
3719
|
},
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3720
|
+
},
|
|
3721
|
+
{
|
|
3722
|
+
kitProducts: {
|
|
3723
|
+
columnName: 'kit_products',
|
|
3724
|
+
foreignKeyColumn: { productId: 'id' },
|
|
3725
|
+
fields: [
|
|
3726
|
+
{ productId: { columnName: 'product_id' } },
|
|
3727
|
+
{ kitProductId: { columnName: 'kit_product_id' } },
|
|
3728
|
+
'quantity',
|
|
3729
|
+
{ product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
|
|
3730
|
+
],
|
|
3725
3731
|
},
|
|
3726
|
-
|
|
3727
|
-
|
|
3732
|
+
},
|
|
3733
|
+
]);
|
|
3728
3734
|
return _this;
|
|
3729
3735
|
}
|
|
3736
|
+
Object.defineProperty(ProductHasuraGraphQLRepository.prototype, "reviewsFields", {
|
|
3737
|
+
get: function () {
|
|
3738
|
+
return [
|
|
3739
|
+
'id',
|
|
3740
|
+
'shop',
|
|
3741
|
+
'rate',
|
|
3742
|
+
'author',
|
|
3743
|
+
'email',
|
|
3744
|
+
'location',
|
|
3745
|
+
'review',
|
|
3746
|
+
'status',
|
|
3747
|
+
'title',
|
|
3748
|
+
'person_id',
|
|
3749
|
+
'points',
|
|
3750
|
+
'order_id',
|
|
3751
|
+
'created_at',
|
|
3752
|
+
'updated_at',
|
|
3753
|
+
];
|
|
3754
|
+
},
|
|
3755
|
+
enumerable: false,
|
|
3756
|
+
configurable: true
|
|
3757
|
+
});
|
|
3758
|
+
ProductHasuraGraphQLRepository.prototype.create = function (data) {
|
|
3759
|
+
var _super = Object.create(null, {
|
|
3760
|
+
create: { get: function () { return _super_1.prototype.create; } }
|
|
3761
|
+
});
|
|
3762
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3763
|
+
var product, _c, error_1;
|
|
3764
|
+
return __generator(this, function (_d) {
|
|
3765
|
+
switch (_d.label) {
|
|
3766
|
+
case 0: return [4 /*yield*/, _super.create.call(this, lodash.omit(data, ['reviews']))];
|
|
3767
|
+
case 1:
|
|
3768
|
+
product = _d.sent();
|
|
3769
|
+
_d.label = 2;
|
|
3770
|
+
case 2:
|
|
3771
|
+
_d.trys.push([2, 4, , 6]);
|
|
3772
|
+
_c = product;
|
|
3773
|
+
return [4 /*yield*/, this.updateReviews(+product.id, data)];
|
|
3774
|
+
case 3:
|
|
3775
|
+
_c.reviews = _d.sent();
|
|
3776
|
+
return [3 /*break*/, 6];
|
|
3777
|
+
case 4:
|
|
3778
|
+
error_1 = _d.sent();
|
|
3779
|
+
return [4 /*yield*/, this.delete({ id: product.id })];
|
|
3780
|
+
case 5:
|
|
3781
|
+
_d.sent();
|
|
3782
|
+
throw error_1;
|
|
3783
|
+
case 6: return [2 /*return*/, product];
|
|
3784
|
+
}
|
|
3785
|
+
});
|
|
3786
|
+
});
|
|
3787
|
+
};
|
|
3730
3788
|
ProductHasuraGraphQLRepository.prototype.get = function (identifiers) {
|
|
3731
3789
|
var _super = Object.create(null, {
|
|
3732
3790
|
get: { get: function () { return _super_1.prototype.get; } }
|
|
3733
3791
|
});
|
|
3734
3792
|
var _a;
|
|
3735
3793
|
return __awaiter(this, void 0, void 0, function () {
|
|
3736
|
-
var _c;
|
|
3737
|
-
return __generator(this, function (
|
|
3738
|
-
switch (
|
|
3794
|
+
var product, _c, _d;
|
|
3795
|
+
return __generator(this, function (_e) {
|
|
3796
|
+
switch (_e.label) {
|
|
3739
3797
|
case 0:
|
|
3740
3798
|
if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
|
|
3741
3799
|
return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
|
|
3742
3800
|
case 1:
|
|
3743
|
-
_c = (_a = (
|
|
3744
|
-
return [3 /*break*/,
|
|
3745
|
-
case 2:
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3801
|
+
_c = (_a = (_e.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
|
|
3802
|
+
return [3 /*break*/, 4];
|
|
3803
|
+
case 2: return [4 /*yield*/, _super.get.call(this, identifiers)];
|
|
3804
|
+
case 3:
|
|
3805
|
+
_c = _e.sent();
|
|
3806
|
+
_e.label = 4;
|
|
3807
|
+
case 4:
|
|
3808
|
+
product = _c;
|
|
3809
|
+
_d = product;
|
|
3810
|
+
return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
|
|
3811
|
+
case 5:
|
|
3812
|
+
_d.reviews = _e.sent();
|
|
3813
|
+
return [2 /*return*/, product];
|
|
3749
3814
|
}
|
|
3750
3815
|
});
|
|
3751
3816
|
});
|
|
@@ -3774,25 +3839,25 @@
|
|
|
3774
3839
|
update: { get: function () { return _super_1.prototype.update; } }
|
|
3775
3840
|
});
|
|
3776
3841
|
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 (
|
|
3842
|
+
var categories, kitProducts, reviews, checkId, data, plainData, id, product, _c, _d, _e, _f, _g, _h;
|
|
3843
|
+
return __generator(this, function (_j) {
|
|
3844
|
+
switch (_j.label) {
|
|
3780
3845
|
case 0:
|
|
3781
|
-
categories = params.categories, kitProducts = params.kitProducts, checkId = params.id, data = __rest(params, ["categories", "kitProducts", "id"]);
|
|
3846
|
+
categories = params.categories, kitProducts = params.kitProducts, reviews = params.reviews, checkId = params.id, data = __rest(params, ["categories", "kitProducts", "reviews", "id"]);
|
|
3782
3847
|
plainData = this.paramsToPlain({ id: checkId });
|
|
3783
3848
|
return [4 /*yield*/, this.getId(plainData.id)];
|
|
3784
3849
|
case 1:
|
|
3785
|
-
id =
|
|
3850
|
+
id = _j.sent();
|
|
3786
3851
|
return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
|
|
3787
3852
|
case 2:
|
|
3788
|
-
product =
|
|
3853
|
+
product = _j.sent();
|
|
3789
3854
|
_c = product;
|
|
3790
3855
|
_d = categories;
|
|
3791
3856
|
if (!_d) return [3 /*break*/, 4];
|
|
3792
3857
|
return [4 /*yield*/, this.updateCategories(+id, { categories: categories })];
|
|
3793
3858
|
case 3:
|
|
3794
|
-
_d = (
|
|
3795
|
-
|
|
3859
|
+
_d = (_j.sent());
|
|
3860
|
+
_j.label = 4;
|
|
3796
3861
|
case 4:
|
|
3797
3862
|
_c.categories = _d;
|
|
3798
3863
|
_e = product;
|
|
@@ -3800,10 +3865,19 @@
|
|
|
3800
3865
|
if (!_f) return [3 /*break*/, 6];
|
|
3801
3866
|
return [4 /*yield*/, this.updateKitProducts(+id, { kitProducts: kitProducts })];
|
|
3802
3867
|
case 5:
|
|
3803
|
-
_f = (
|
|
3804
|
-
|
|
3868
|
+
_f = (_j.sent());
|
|
3869
|
+
_j.label = 6;
|
|
3805
3870
|
case 6:
|
|
3806
3871
|
_e.kitProducts = _f;
|
|
3872
|
+
_g = product;
|
|
3873
|
+
_h = reviews;
|
|
3874
|
+
if (!_h) return [3 /*break*/, 8];
|
|
3875
|
+
return [4 /*yield*/, this.updateReviews(+id, { reviews: reviews })];
|
|
3876
|
+
case 7:
|
|
3877
|
+
_h = (_j.sent());
|
|
3878
|
+
_j.label = 8;
|
|
3879
|
+
case 8:
|
|
3880
|
+
_g.reviews = _h;
|
|
3807
3881
|
return [2 /*return*/, product];
|
|
3808
3882
|
}
|
|
3809
3883
|
});
|
|
@@ -3875,6 +3949,75 @@
|
|
|
3875
3949
|
});
|
|
3876
3950
|
});
|
|
3877
3951
|
};
|
|
3952
|
+
ProductHasuraGraphQLRepository.prototype.updateReviews = function (productId, _c) {
|
|
3953
|
+
var reviews = _c.reviews;
|
|
3954
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3955
|
+
var reviewIds_1, plainData;
|
|
3956
|
+
var _this = this;
|
|
3957
|
+
return __generator(this, function (_c) {
|
|
3958
|
+
switch (_c.label) {
|
|
3959
|
+
case 0:
|
|
3960
|
+
if (!('action' in reviews && reviews.action === 'remove')) return [3 /*break*/, 3];
|
|
3961
|
+
return [4 /*yield*/, Promise.all(reviews.value.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
|
|
3962
|
+
var review;
|
|
3963
|
+
return __generator(this, function (_c) {
|
|
3964
|
+
switch (_c.label) {
|
|
3965
|
+
case 0: return [4 /*yield*/, this.findReview(reviewData, productId)];
|
|
3966
|
+
case 1:
|
|
3967
|
+
review = _c.sent();
|
|
3968
|
+
return [2 /*return*/, review === null || review === void 0 ? void 0 : review.id];
|
|
3969
|
+
}
|
|
3970
|
+
});
|
|
3971
|
+
}); }))];
|
|
3972
|
+
case 1:
|
|
3973
|
+
reviewIds_1 = _c.sent();
|
|
3974
|
+
return [4 /*yield*/, this.mutation('delete_product_review', ['affected_rows'], {
|
|
3975
|
+
where: { value: { id: { _in: reviewIds_1.filter(Boolean) } }, type: 'product_review_bool_exp', required: true },
|
|
3976
|
+
})];
|
|
3977
|
+
case 2:
|
|
3978
|
+
_c.sent();
|
|
3979
|
+
return [2 /*return*/, reviews.value.map(function (review, index) { return !reviewIds_1[index] && review; }).filter(Boolean)];
|
|
3980
|
+
case 3:
|
|
3981
|
+
plainData = this.paramsToPlain({ reviews: reviews });
|
|
3982
|
+
return [2 /*return*/, Promise.all(plainData.reviews.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
|
|
3983
|
+
var review, _c, _d;
|
|
3984
|
+
return __generator(this, function (_e) {
|
|
3985
|
+
switch (_e.label) {
|
|
3986
|
+
case 0: return [4 /*yield*/, this.findReview(reviewData, productId)];
|
|
3987
|
+
case 1:
|
|
3988
|
+
review = _e.sent();
|
|
3989
|
+
if (!review) return [3 /*break*/, 3];
|
|
3990
|
+
_c = this.bindReviewToModel;
|
|
3991
|
+
return [4 /*yield*/, this.mutation('update_product_review_by_pk', this.reviewsFields, {
|
|
3992
|
+
pk_columns: {
|
|
3993
|
+
value: { id: review.id },
|
|
3994
|
+
type: 'product_review_pk_columns_input',
|
|
3995
|
+
required: true,
|
|
3996
|
+
},
|
|
3997
|
+
_set: {
|
|
3998
|
+
value: lodash.omit(this.bindReviewToHasura(reviewData), ['id', 'product_id']),
|
|
3999
|
+
type: 'product_review_set_input',
|
|
4000
|
+
required: true,
|
|
4001
|
+
},
|
|
4002
|
+
})];
|
|
4003
|
+
case 2: return [2 /*return*/, _c.apply(this, [(_e.sent()).update_product_review_by_pk])];
|
|
4004
|
+
case 3:
|
|
4005
|
+
_d = this.bindReviewToModel;
|
|
4006
|
+
return [4 /*yield*/, this.mutation('insert_product_review_one', this.reviewsFields, {
|
|
4007
|
+
object: {
|
|
4008
|
+
value: lodash.omit(Object.assign(Object.assign({}, this.bindReviewToHasura(reviewData)), { product_id: productId }), ['id']),
|
|
4009
|
+
type: 'product_review_insert_input',
|
|
4010
|
+
required: true,
|
|
4011
|
+
},
|
|
4012
|
+
})];
|
|
4013
|
+
case 4: return [2 /*return*/, _d.apply(this, [(_e.sent()).insert_product_review_one])];
|
|
4014
|
+
}
|
|
4015
|
+
});
|
|
4016
|
+
}); }))];
|
|
4017
|
+
}
|
|
4018
|
+
});
|
|
4019
|
+
});
|
|
4020
|
+
};
|
|
3878
4021
|
ProductHasuraGraphQLRepository.prototype.getId = function (id) {
|
|
3879
4022
|
var _a, _b;
|
|
3880
4023
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3894,6 +4037,97 @@
|
|
|
3894
4037
|
});
|
|
3895
4038
|
});
|
|
3896
4039
|
};
|
|
4040
|
+
ProductHasuraGraphQLRepository.prototype.findReviewsByProduct = function (productId) {
|
|
4041
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4042
|
+
var data;
|
|
4043
|
+
var _this = this;
|
|
4044
|
+
return __generator(this, function (_c) {
|
|
4045
|
+
switch (_c.label) {
|
|
4046
|
+
case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
|
|
4047
|
+
where: {
|
|
4048
|
+
value: {
|
|
4049
|
+
product_id: { _eq: productId },
|
|
4050
|
+
},
|
|
4051
|
+
type: 'product_review_bool_exp',
|
|
4052
|
+
required: true,
|
|
4053
|
+
},
|
|
4054
|
+
})];
|
|
4055
|
+
case 1:
|
|
4056
|
+
data = (_c.sent()).product_review;
|
|
4057
|
+
return [2 /*return*/, data && data.map(function (review) { return _this.bindReviewToModel(review); })];
|
|
4058
|
+
}
|
|
4059
|
+
});
|
|
4060
|
+
});
|
|
4061
|
+
};
|
|
4062
|
+
ProductHasuraGraphQLRepository.prototype.findReview = function (review, productId) {
|
|
4063
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4064
|
+
var loadedReview;
|
|
4065
|
+
return __generator(this, function (_c) {
|
|
4066
|
+
switch (_c.label) {
|
|
4067
|
+
case 0:
|
|
4068
|
+
if (review.id)
|
|
4069
|
+
return [2 /*return*/, review];
|
|
4070
|
+
if (!review.personId) return [3 /*break*/, 2];
|
|
4071
|
+
return [4 /*yield*/, this.getReviewByPersonId(review.personId, productId)];
|
|
4072
|
+
case 1:
|
|
4073
|
+
loadedReview = _c.sent();
|
|
4074
|
+
_c.label = 2;
|
|
4075
|
+
case 2:
|
|
4076
|
+
if (!(!loadedReview && review.author && review.email)) return [3 /*break*/, 4];
|
|
4077
|
+
return [4 /*yield*/, this.getReviewByAuthorAndEmail(review.author, review.email, productId)];
|
|
4078
|
+
case 3:
|
|
4079
|
+
loadedReview = _c.sent();
|
|
4080
|
+
_c.label = 4;
|
|
4081
|
+
case 4: return [2 /*return*/, loadedReview || review];
|
|
4082
|
+
}
|
|
4083
|
+
});
|
|
4084
|
+
});
|
|
4085
|
+
};
|
|
4086
|
+
ProductHasuraGraphQLRepository.prototype.getReviewByPersonId = function (personId, productId) {
|
|
4087
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4088
|
+
var data;
|
|
4089
|
+
return __generator(this, function (_c) {
|
|
4090
|
+
switch (_c.label) {
|
|
4091
|
+
case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
|
|
4092
|
+
where: {
|
|
4093
|
+
value: {
|
|
4094
|
+
product_id: { _eq: productId },
|
|
4095
|
+
person_id: { _eq: personId },
|
|
4096
|
+
},
|
|
4097
|
+
type: "product_review_bool_exp",
|
|
4098
|
+
required: true,
|
|
4099
|
+
},
|
|
4100
|
+
})];
|
|
4101
|
+
case 1:
|
|
4102
|
+
data = (_c.sent()).product_review;
|
|
4103
|
+
return [2 /*return*/, data && data[0] && this.bindReviewToModel(data[0])];
|
|
4104
|
+
}
|
|
4105
|
+
});
|
|
4106
|
+
});
|
|
4107
|
+
};
|
|
4108
|
+
ProductHasuraGraphQLRepository.prototype.getReviewByAuthorAndEmail = function (author, email, productId) {
|
|
4109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4110
|
+
var data;
|
|
4111
|
+
return __generator(this, function (_c) {
|
|
4112
|
+
switch (_c.label) {
|
|
4113
|
+
case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
|
|
4114
|
+
where: {
|
|
4115
|
+
value: {
|
|
4116
|
+
product_id: { _eq: productId },
|
|
4117
|
+
author: { _eq: author },
|
|
4118
|
+
email: { _eq: email },
|
|
4119
|
+
},
|
|
4120
|
+
type: "product_review_bool_exp",
|
|
4121
|
+
required: true,
|
|
4122
|
+
},
|
|
4123
|
+
})];
|
|
4124
|
+
case 1:
|
|
4125
|
+
data = (_c.sent()).product_review;
|
|
4126
|
+
return [2 /*return*/, data && data[0] && this.bindReviewToModel(data[0])];
|
|
4127
|
+
}
|
|
4128
|
+
});
|
|
4129
|
+
});
|
|
4130
|
+
};
|
|
3897
4131
|
return ProductHasuraGraphQLRepository;
|
|
3898
4132
|
}(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
|
|
3899
4133
|
|