@infrab4a/connect 1.0.0-beta.18 → 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 +360 -108
- 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/helpers/graphql-field.helper.js +4 -6
- package/esm2015/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.js +20 -2
- package/esm2015/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.js +4 -3
- package/esm2015/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.js +3 -3
- package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +4 -3
- package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +178 -41
- package/esm2015/infra/hasura-graphql/types/graphql.repository.type.js +1 -1
- package/fesm2015/infrab4a-connect.js +206 -51
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.d.ts +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 +4 -4
- 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
|
@@ -3,7 +3,7 @@ import { plainToInstance, instanceToPlain, Expose, Type } from 'class-transforme
|
|
|
3
3
|
import { __decorate, __metadata, __awaiter, __rest } from 'tslib';
|
|
4
4
|
import { parseISO } from 'date-fns';
|
|
5
5
|
export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
|
|
6
|
-
import { isString, isNil, isNumber, isDate, set, isObject, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1 } from 'lodash';
|
|
6
|
+
import { isString, isNil, isNumber, isDate, set, isObject, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1, omit } from 'lodash';
|
|
7
7
|
export { chunk, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set } from 'lodash';
|
|
8
8
|
import { Md5 } from 'ts-md5';
|
|
9
9
|
import axios from 'axios';
|
|
@@ -1897,9 +1897,7 @@ GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).r
|
|
|
1897
1897
|
GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
1898
1898
|
var _a;
|
|
1899
1899
|
const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
1900
|
-
return Object.keys(data)
|
|
1901
|
-
.filter((key) => !isNil(data[key]))
|
|
1902
|
-
.reduce((result, attributeName) => {
|
|
1900
|
+
return Object.keys(data).reduce((result, attributeName) => {
|
|
1903
1901
|
const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
|
|
1904
1902
|
if (bindPersistData)
|
|
1905
1903
|
return Object.assign(Object.assign({}, result), bindPersistData(data[attributeName], instance));
|
|
@@ -1907,8 +1905,8 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
1907
1905
|
return result;
|
|
1908
1906
|
if (!!foreignKeyColumn &&
|
|
1909
1907
|
!isEmpty(foreignKeyColumn) &&
|
|
1910
|
-
!Object.keys(foreignKeyColumn).filter((key) => !data[attributeName][key]).length)
|
|
1911
|
-
return Object.keys(foreignKeyColumn).reduce((object, current) => (Object.assign(Object.assign({}, object), { [foreignKeyColumn[current]]: data[attributeName][current] })), Object.assign({}, result));
|
|
1908
|
+
!Object.keys(foreignKeyColumn).filter((key) => { var _a; return !((_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[key]); }).length)
|
|
1909
|
+
return Object.keys(foreignKeyColumn).reduce((object, current) => { var _a; return (Object.assign(Object.assign({}, object), { [foreignKeyColumn[current]]: (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current] })); }, Object.assign({}, result));
|
|
1912
1910
|
if (update && isObject(data[attributeName]) && !isNil(attributeFields) && !isDate(data[attributeName]))
|
|
1913
1911
|
return result;
|
|
1914
1912
|
if (!!columnName && Array.isArray(attributeFields) && isObject(data[attributeName])) {
|
|
@@ -1961,7 +1959,25 @@ const withCreateHasuraGraphQL = (MixinBase) => {
|
|
|
1961
1959
|
}
|
|
1962
1960
|
save(data) {
|
|
1963
1961
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1964
|
-
const
|
|
1962
|
+
const primaryKeyColumns = this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName);
|
|
1963
|
+
const foreignKeyColumns = this.fields
|
|
1964
|
+
.map((field) => {
|
|
1965
|
+
const columnOptions = Object.values(field).shift();
|
|
1966
|
+
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
1967
|
+
columnOptions.foreignKeyColumn && [
|
|
1968
|
+
...Object.values(columnOptions.foreignKeyColumn),
|
|
1969
|
+
{
|
|
1970
|
+
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => {
|
|
1971
|
+
var _a;
|
|
1972
|
+
return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) ||
|
|
1973
|
+
foreignKeyField;
|
|
1974
|
+
}),
|
|
1975
|
+
},
|
|
1976
|
+
]);
|
|
1977
|
+
})
|
|
1978
|
+
.filter(Boolean)
|
|
1979
|
+
.reduce((keys, current) => [...keys, ...current], []);
|
|
1980
|
+
const result = yield this.mutation(this.insertGraphQLOperation, [...primaryKeyColumns, ...foreignKeyColumns], {
|
|
1965
1981
|
object: { type: this.insertGraphQLObjectType, required: true, value: this.convertDataToHasura(data) },
|
|
1966
1982
|
});
|
|
1967
1983
|
return Object.assign(Object.assign({}, data.toPlain()), this.convertDataFromHasura(result[this.insertGraphQLOperation]).toPlain());
|
|
@@ -2091,7 +2107,7 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
2091
2107
|
return options.toPlain();
|
|
2092
2108
|
if (isNil(options.action))
|
|
2093
2109
|
return options;
|
|
2094
|
-
if (
|
|
2110
|
+
if ([UpdateOptionActions.REMOVE_FIELD.toString(), UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
2095
2111
|
return null;
|
|
2096
2112
|
return options.value;
|
|
2097
2113
|
};
|
|
@@ -2121,7 +2137,7 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
2121
2137
|
const model = this.model;
|
|
2122
2138
|
if (model.isModel(params))
|
|
2123
2139
|
return params.toPlain();
|
|
2124
|
-
return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), (params[currentKey] && { [currentKey]: getValueByAction(params[currentKey]) }))), {});
|
|
2140
|
+
return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), (params[currentKey] !== undefined && { [currentKey]: getValueByAction(params[currentKey]) }))), {});
|
|
2125
2141
|
}
|
|
2126
2142
|
getUpdateModelKeys(data) {
|
|
2127
2143
|
const instance = this.model.toInstance(data);
|
|
@@ -2148,10 +2164,11 @@ const withGetHasuraGraphQL = (MixinBase) => {
|
|
|
2148
2164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2149
2165
|
const instance = this.model.toInstance(identifiers);
|
|
2150
2166
|
const result = yield this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce((ids, identifier) => {
|
|
2167
|
+
var _a;
|
|
2151
2168
|
if (isNil(instance[identifier]))
|
|
2152
2169
|
return ids;
|
|
2153
2170
|
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
|
|
2154
|
-
const value = columnOption.to(identifiers[identifier.toString()], instance);
|
|
2171
|
+
const value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, identifiers[identifier.toString()], instance)) || identifiers[identifier.toString()];
|
|
2155
2172
|
return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: {
|
|
2156
2173
|
type: this.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
2157
2174
|
value,
|
|
@@ -2335,11 +2352,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2335
2352
|
conditions: {
|
|
2336
2353
|
columnName: 'tag_condition',
|
|
2337
2354
|
type: HasuraGraphQLColumnType.Jsonb,
|
|
2338
|
-
from: (tags, row) => ({ brand: row.brand_condition, tags }),
|
|
2355
|
+
from: (tags, row) => ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }),
|
|
2339
2356
|
bindPersistData: (value) => {
|
|
2357
|
+
var _a, _b;
|
|
2340
2358
|
return {
|
|
2341
2359
|
brand_condition: value.brand,
|
|
2342
|
-
tag_condition: `{"${value.tags.join('","')}"}`,
|
|
2360
|
+
tag_condition: `{"${((_b = (_a = value === null || value === void 0 ? void 0 : value.tags) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '","')) || ''}"}`,
|
|
2343
2361
|
};
|
|
2344
2362
|
},
|
|
2345
2363
|
bindFindFilter: (sentence) => {
|
|
@@ -2418,6 +2436,15 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2418
2436
|
|
|
2419
2437
|
class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
2420
2438
|
constructor(endpoint, authOptions) {
|
|
2439
|
+
super({
|
|
2440
|
+
tableName: 'product',
|
|
2441
|
+
model: ProductHasuraGraphQL,
|
|
2442
|
+
endpoint,
|
|
2443
|
+
authOptions,
|
|
2444
|
+
fields: [],
|
|
2445
|
+
});
|
|
2446
|
+
this.bindReviewToModel = (plain) => (Object.assign(Object.assign({}, 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 }));
|
|
2447
|
+
this.bindReviewToHasura = (review) => (Object.assign(Object.assign({}, omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])), { person_id: review.personId, order_id: review.orderId }));
|
|
2421
2448
|
const commonFields = [
|
|
2422
2449
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
2423
2450
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -2434,8 +2461,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2434
2461
|
},
|
|
2435
2462
|
},
|
|
2436
2463
|
{ hasVariants: { columnName: 'has_variants' } },
|
|
2437
|
-
{ images: { columnName: 'images', to: (value) => `{"${value.join(`","`)}"}
|
|
2438
|
-
{ miniatures: { columnName: 'miniatures', to: (value) => `{"${value.join(`","`)}"}
|
|
2464
|
+
{ images: { columnName: 'images', to: (value) => { var _a; return `{"${((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, `","`)) || ''}"}`; } } },
|
|
2465
|
+
{ miniatures: { columnName: 'miniatures', to: (value) => { var _a; return `{"${((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, `","`)) || ''}"}`; } } },
|
|
2439
2466
|
'name',
|
|
2440
2467
|
{
|
|
2441
2468
|
price: {
|
|
@@ -2448,15 +2475,17 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2448
2475
|
} })), {}),
|
|
2449
2476
|
bindFindFilter: (sentence) => {
|
|
2450
2477
|
const filters = Object.values(sentence).shift();
|
|
2451
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, ((filters === null || filters === void 0 ? void 0 : filters.price) && { price: filters.price })), (filters.fullPrice && { full_price: filters.fullPrice })), (filters.subscriberDiscountPercentage && {
|
|
2478
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, (((filters === null || filters === void 0 ? void 0 : filters.price) || (filters === null || filters === void 0 ? void 0 : filters.price) === 0) && { price: filters.price })), ((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice })), ((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
2452
2479
|
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
2453
|
-
})), (filters.subscriberPrice
|
|
2480
|
+
})), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
2481
|
+
subscriber_price: filters.subscriberPrice,
|
|
2482
|
+
}));
|
|
2454
2483
|
},
|
|
2455
2484
|
bindPersistData: (value) => {
|
|
2456
2485
|
const priceData = Object.values(value).shift();
|
|
2457
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) && { price: priceData.price })), (priceData.fullPrice && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage && {
|
|
2486
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) >= 0 && { price: priceData.price })), (priceData.fullPrice >= 0 && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage >= 0 && {
|
|
2458
2487
|
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
2459
|
-
})), (priceData.subscriberPrice && { subscriber_price: priceData.subscriberPrice }));
|
|
2488
|
+
})), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }));
|
|
2460
2489
|
},
|
|
2461
2490
|
},
|
|
2462
2491
|
},
|
|
@@ -2490,37 +2519,65 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2490
2519
|
{ createdAt: { columnName: 'created_at' } },
|
|
2491
2520
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
2492
2521
|
];
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
bindPersistData: (value) => ({
|
|
2505
|
-
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
2506
|
-
}),
|
|
2507
|
-
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
2508
|
-
from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || [],
|
|
2509
|
-
},
|
|
2522
|
+
this.fields = [
|
|
2523
|
+
...commonFields,
|
|
2524
|
+
{
|
|
2525
|
+
categories: {
|
|
2526
|
+
columnName: 'categories',
|
|
2527
|
+
fields: ['category_id'],
|
|
2528
|
+
bindPersistData: (value) => ({
|
|
2529
|
+
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
2530
|
+
}),
|
|
2531
|
+
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
2532
|
+
from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || [],
|
|
2510
2533
|
},
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2534
|
+
},
|
|
2535
|
+
{
|
|
2536
|
+
kitProducts: {
|
|
2537
|
+
columnName: 'kit_products',
|
|
2538
|
+
foreignKeyColumn: { productId: 'id' },
|
|
2539
|
+
fields: [
|
|
2540
|
+
{ productId: { columnName: 'product_id' } },
|
|
2541
|
+
{ kitProductId: { columnName: 'kit_product_id' } },
|
|
2542
|
+
'quantity',
|
|
2543
|
+
{ product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
|
|
2544
|
+
],
|
|
2522
2545
|
},
|
|
2523
|
-
|
|
2546
|
+
},
|
|
2547
|
+
];
|
|
2548
|
+
}
|
|
2549
|
+
get reviewsFields() {
|
|
2550
|
+
return [
|
|
2551
|
+
'id',
|
|
2552
|
+
'shop',
|
|
2553
|
+
'rate',
|
|
2554
|
+
'author',
|
|
2555
|
+
'email',
|
|
2556
|
+
'location',
|
|
2557
|
+
'review',
|
|
2558
|
+
'status',
|
|
2559
|
+
'title',
|
|
2560
|
+
'person_id',
|
|
2561
|
+
'points',
|
|
2562
|
+
'order_id',
|
|
2563
|
+
'created_at',
|
|
2564
|
+
'updated_at',
|
|
2565
|
+
];
|
|
2566
|
+
}
|
|
2567
|
+
create(data) {
|
|
2568
|
+
const _super = Object.create(null, {
|
|
2569
|
+
create: { get: () => super.create }
|
|
2570
|
+
});
|
|
2571
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2572
|
+
const product = yield _super.create.call(this, omit(data, ['reviews']));
|
|
2573
|
+
try {
|
|
2574
|
+
product.reviews = yield this.updateReviews(+product.id, data);
|
|
2575
|
+
}
|
|
2576
|
+
catch (error) {
|
|
2577
|
+
yield this.delete({ id: product.id });
|
|
2578
|
+
throw error;
|
|
2579
|
+
}
|
|
2580
|
+
return product;
|
|
2524
2581
|
});
|
|
2525
2582
|
}
|
|
2526
2583
|
get(identifiers) {
|
|
@@ -2529,9 +2586,11 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2529
2586
|
});
|
|
2530
2587
|
var _a;
|
|
2531
2588
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2532
|
-
|
|
2589
|
+
const product = Number.isNaN(+identifiers.id)
|
|
2533
2590
|
? (_a = (yield this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
|
|
2534
|
-
: _super.get.call(this, identifiers);
|
|
2591
|
+
: yield _super.get.call(this, identifiers);
|
|
2592
|
+
product.reviews = yield this.findReviewsByProduct(+product.id);
|
|
2593
|
+
return product;
|
|
2535
2594
|
});
|
|
2536
2595
|
}
|
|
2537
2596
|
getBySlug(slug, shop) {
|
|
@@ -2551,12 +2610,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2551
2610
|
update: { get: () => super.update }
|
|
2552
2611
|
});
|
|
2553
2612
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2554
|
-
const { categories, kitProducts, id: checkId } = params, data = __rest(params, ["categories", "kitProducts", "id"]);
|
|
2613
|
+
const { categories, kitProducts, reviews, id: checkId } = params, data = __rest(params, ["categories", "kitProducts", "reviews", "id"]);
|
|
2555
2614
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
2556
2615
|
const id = yield this.getId(plainData.id);
|
|
2557
2616
|
const product = yield _super.update.call(this, Object.assign({ id }, data));
|
|
2558
2617
|
product.categories = categories && (yield this.updateCategories(+id, { categories }));
|
|
2559
2618
|
product.kitProducts = kitProducts && (yield this.updateKitProducts(+id, { kitProducts }));
|
|
2619
|
+
product.reviews = reviews && (yield this.updateReviews(+id, { reviews }));
|
|
2560
2620
|
return product;
|
|
2561
2621
|
});
|
|
2562
2622
|
}
|
|
@@ -2595,7 +2655,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2595
2655
|
type: '[product_kit_insert_input!]',
|
|
2596
2656
|
required: true,
|
|
2597
2657
|
value: plainData.kitProducts.map((kitProduct) => ({
|
|
2598
|
-
kit_product_id: kitProduct.
|
|
2658
|
+
kit_product_id: kitProduct.productId || kitProduct.product.id,
|
|
2599
2659
|
product_id: productId,
|
|
2600
2660
|
quantity: kitProduct.quantity,
|
|
2601
2661
|
})),
|
|
@@ -2604,6 +2664,44 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2604
2664
|
return plainData.kitProducts;
|
|
2605
2665
|
});
|
|
2606
2666
|
}
|
|
2667
|
+
updateReviews(productId, { reviews }) {
|
|
2668
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2669
|
+
if ('action' in reviews && reviews.action === 'remove') {
|
|
2670
|
+
const reviewIds = yield Promise.all(reviews.value.map((reviewData) => __awaiter(this, void 0, void 0, function* () {
|
|
2671
|
+
const review = yield this.findReview(reviewData, productId);
|
|
2672
|
+
return review === null || review === void 0 ? void 0 : review.id;
|
|
2673
|
+
})));
|
|
2674
|
+
yield this.mutation('delete_product_review', ['affected_rows'], {
|
|
2675
|
+
where: { value: { id: { _in: reviewIds.filter(Boolean) } }, type: 'product_review_bool_exp', required: true },
|
|
2676
|
+
});
|
|
2677
|
+
return reviews.value.map((review, index) => !reviewIds[index] && review).filter(Boolean);
|
|
2678
|
+
}
|
|
2679
|
+
const plainData = this.paramsToPlain({ reviews });
|
|
2680
|
+
return Promise.all(plainData.reviews.map((reviewData) => __awaiter(this, void 0, void 0, function* () {
|
|
2681
|
+
const review = yield this.findReview(reviewData, productId);
|
|
2682
|
+
if (review)
|
|
2683
|
+
return this.bindReviewToModel((yield this.mutation('update_product_review_by_pk', this.reviewsFields, {
|
|
2684
|
+
pk_columns: {
|
|
2685
|
+
value: { id: review.id },
|
|
2686
|
+
type: 'product_review_pk_columns_input',
|
|
2687
|
+
required: true,
|
|
2688
|
+
},
|
|
2689
|
+
_set: {
|
|
2690
|
+
value: omit(this.bindReviewToHasura(reviewData), ['id', 'product_id']),
|
|
2691
|
+
type: 'product_review_set_input',
|
|
2692
|
+
required: true,
|
|
2693
|
+
},
|
|
2694
|
+
})).update_product_review_by_pk);
|
|
2695
|
+
return this.bindReviewToModel((yield this.mutation('insert_product_review_one', this.reviewsFields, {
|
|
2696
|
+
object: {
|
|
2697
|
+
value: omit(Object.assign(Object.assign({}, this.bindReviewToHasura(reviewData)), { product_id: productId }), ['id']),
|
|
2698
|
+
type: 'product_review_insert_input',
|
|
2699
|
+
required: true,
|
|
2700
|
+
},
|
|
2701
|
+
})).insert_product_review_one);
|
|
2702
|
+
})));
|
|
2703
|
+
});
|
|
2704
|
+
}
|
|
2607
2705
|
getId(id) {
|
|
2608
2706
|
var _a, _b;
|
|
2609
2707
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2615,6 +2713,63 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2615
2713
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
2616
2714
|
});
|
|
2617
2715
|
}
|
|
2716
|
+
findReviewsByProduct(productId) {
|
|
2717
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2718
|
+
const { product_review: data } = yield this.query('product_review', this.reviewsFields, {
|
|
2719
|
+
where: {
|
|
2720
|
+
value: {
|
|
2721
|
+
product_id: { _eq: productId },
|
|
2722
|
+
},
|
|
2723
|
+
type: 'product_review_bool_exp',
|
|
2724
|
+
required: true,
|
|
2725
|
+
},
|
|
2726
|
+
});
|
|
2727
|
+
return data && data.map((review) => this.bindReviewToModel(review));
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
findReview(review, productId) {
|
|
2731
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2732
|
+
if (review.id)
|
|
2733
|
+
return review;
|
|
2734
|
+
let loadedReview;
|
|
2735
|
+
if (review.personId)
|
|
2736
|
+
loadedReview = yield this.getReviewByPersonId(review.personId, productId);
|
|
2737
|
+
if (!loadedReview && review.author && review.email)
|
|
2738
|
+
loadedReview = yield this.getReviewByAuthorAndEmail(review.author, review.email, productId);
|
|
2739
|
+
return loadedReview || review;
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
getReviewByPersonId(personId, productId) {
|
|
2743
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2744
|
+
const { product_review: data } = yield this.query('product_review', this.reviewsFields, {
|
|
2745
|
+
where: {
|
|
2746
|
+
value: {
|
|
2747
|
+
product_id: { _eq: productId },
|
|
2748
|
+
person_id: { _eq: personId },
|
|
2749
|
+
},
|
|
2750
|
+
type: `product_review_bool_exp`,
|
|
2751
|
+
required: true,
|
|
2752
|
+
},
|
|
2753
|
+
});
|
|
2754
|
+
return data && data[0] && this.bindReviewToModel(data[0]);
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
getReviewByAuthorAndEmail(author, email, productId) {
|
|
2758
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2759
|
+
const { product_review: data } = yield this.query('product_review', this.reviewsFields, {
|
|
2760
|
+
where: {
|
|
2761
|
+
value: {
|
|
2762
|
+
product_id: { _eq: productId },
|
|
2763
|
+
author: { _eq: author },
|
|
2764
|
+
email: { _eq: email },
|
|
2765
|
+
},
|
|
2766
|
+
type: `product_review_bool_exp`,
|
|
2767
|
+
required: true,
|
|
2768
|
+
},
|
|
2769
|
+
});
|
|
2770
|
+
return data && data[0] && this.bindReviewToModel(data[0]);
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2618
2773
|
}
|
|
2619
2774
|
|
|
2620
2775
|
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|