@infrab4a/connect 1.0.0-beta.9 → 1.0.0
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 +1260 -320
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/domain/catalog/models/category.d.ts +2 -2
- package/domain/catalog/models/index.d.ts +3 -2
- package/domain/catalog/models/kit-product.d.ts +12 -0
- package/domain/catalog/models/product.d.ts +6 -2
- package/domain/catalog/models/types/product-review.type.d.ts +10 -8
- package/domain/catalog/models/variant.d.ts +3 -1
- package/domain/catalog/repositories/product.repository.d.ts +9 -2
- package/domain/generic/model/base.model.d.ts +1 -1
- package/domain/generic/model/types/base-model-builder.type.d.ts +1 -1
- package/domain/generic/model/types/non-function-property-name.type.d.ts +1 -1
- package/domain/generic/repository/create.repository.d.ts +2 -2
- package/domain/generic/repository/delete.repository.d.ts +3 -1
- package/domain/generic/repository/find.repository.d.ts +2 -1
- package/domain/generic/repository/types/repository-find-filters.type.d.ts +4 -4
- package/domain/generic/repository/types/repository-update-params.type.d.ts +4 -4
- package/domain/users/errors/unauthorized.error.d.ts +2 -1
- package/domain/users/errors/user-already-registered.error.d.ts +2 -1
- package/domain/users/errors/weak-password.error.d.ts +2 -1
- package/domain/users/models/user.d.ts +2 -0
- package/errors/duplicated-results.error.d.ts +2 -1
- package/errors/invalid-argument.error.d.ts +2 -1
- package/errors/not-found.error.d.ts +2 -1
- package/errors/required-argument.error.d.ts +2 -1
- package/esm2015/domain/catalog/models/category.js +1 -1
- package/esm2015/domain/catalog/models/index.js +4 -3
- package/esm2015/domain/catalog/models/kit-product.js +18 -0
- package/esm2015/domain/catalog/models/product.js +8 -1
- package/esm2015/domain/catalog/models/types/product-review.type.js +1 -1
- package/esm2015/domain/catalog/models/variant.js +1 -1
- package/esm2015/domain/catalog/repositories/product.repository.js +1 -1
- package/esm2015/domain/generic/model/base.model.js +4 -4
- package/esm2015/domain/generic/model/types/base-model-builder.type.js +1 -1
- package/esm2015/domain/generic/model/types/non-function-property-name.type.js +1 -1
- package/esm2015/domain/generic/repository/create.repository.js +1 -1
- package/esm2015/domain/generic/repository/delete.repository.js +1 -1
- package/esm2015/domain/generic/repository/find.repository.js +1 -1
- package/esm2015/domain/generic/repository/types/repository-find-filters.type.js +1 -1
- package/esm2015/domain/generic/repository/types/repository-update-params.type.js +1 -1
- package/esm2015/domain/users/errors/unauthorized.error.js +3 -2
- package/esm2015/domain/users/errors/user-already-registered.error.js +3 -2
- package/esm2015/domain/users/errors/weak-password.error.js +3 -2
- package/esm2015/domain/users/models/user.js +1 -1
- package/esm2015/errors/duplicated-results.error.js +3 -2
- package/esm2015/errors/invalid-argument.error.js +3 -2
- package/esm2015/errors/not-found.error.js +3 -2
- package/esm2015/errors/required-argument.error.js +3 -2
- package/esm2015/infra/elasticsearch/adapters/axios.adapter.js +36 -1
- package/esm2015/infra/elasticsearch/adapters/elastic-search.adapter.js +1 -1
- package/esm2015/infra/elasticsearch/indexes/products-index.js +35 -1
- package/esm2015/infra/firebase/auth/authentication-firebase-auth.service.js +2 -2
- package/esm2015/infra/firebase/auth/register-firebase-auth.service.js +1 -1
- package/esm2015/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +5 -5
- package/esm2015/infra/firebase/firestore/mixins/with-firestore.mixin.js +2 -3
- package/esm2015/infra/firebase/firestore/mixins/with-helpers.mixin.js +1 -1
- package/esm2015/infra/firebase/firestore/repositories/catalog/category-firestore.repository.js +4 -2
- package/esm2015/infra/firebase/firestore/repositories/catalog/product-firestore.repository.js +32 -5
- package/esm2015/infra/hasura-graphql/index.js +3 -2
- package/esm2015/infra/hasura-graphql/mixins/helpers/attribute-option.helper.js +18 -2
- package/esm2015/infra/hasura-graphql/mixins/helpers/filter-option.helper.js +18 -0
- package/esm2015/infra/hasura-graphql/mixins/helpers/graphql-field.helper.js +72 -0
- package/esm2015/infra/hasura-graphql/mixins/helpers/index.js +3 -1
- package/esm2015/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.js +21 -2
- package/esm2015/infra/hasura-graphql/mixins/with-delete-hasura-graphql.mixin.js +14 -6
- package/esm2015/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.js +24 -26
- package/esm2015/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.js +14 -10
- package/esm2015/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.js +10 -84
- package/esm2015/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.js +18 -7
- package/esm2015/infra/hasura-graphql/models/category-hasura-graphql.js +1 -1
- package/esm2015/infra/hasura-graphql/models/index.js +4 -1
- package/esm2015/infra/hasura-graphql/models/kit-product-hasura-graphql.js +15 -0
- package/esm2015/infra/hasura-graphql/models/product-hasura-graphql.js +11 -0
- package/esm2015/infra/hasura-graphql/models/variant-hasura-graphql.js +9 -0
- package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +47 -15
- package/esm2015/infra/hasura-graphql/repositories/catalog/index.js +2 -1
- package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +352 -63
- package/esm2015/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.js +107 -0
- 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/esm2015/infra/hasura-graphql/types/hasura-graphql-headers.type.js +2 -0
- package/esm2015/infra/hasura-graphql/types/index.js +2 -1
- package/fesm2015/infrab4a-connect.js +843 -219
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/elasticsearch/adapters/axios.adapter.d.ts +3 -0
- package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +3 -0
- package/infra/elasticsearch/indexes/products-index.d.ts +5 -1
- package/infra/firebase/auth/authentication-firebase-auth.service.d.ts +1 -1
- package/infra/firebase/auth/register-firebase-auth.service.d.ts +1 -1
- package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +1 -1
- package/infra/firebase/firestore/mixins/with-firestore.mixin.d.ts +1 -1
- package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +4 -2
- package/infra/hasura-graphql/index.d.ts +2 -1
- package/infra/hasura-graphql/mixins/helpers/attribute-option.helper.d.ts +9 -6
- package/infra/hasura-graphql/mixins/helpers/filter-option.helper.d.ts +6 -0
- package/infra/hasura-graphql/mixins/helpers/graphql-field.helper.d.ts +8 -0
- package/infra/hasura-graphql/mixins/helpers/index.d.ts +2 -0
- 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 +8 -7
- package/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +5 -5
- package/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.d.ts +3 -3
- package/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.d.ts +1 -1
- package/infra/hasura-graphql/models/category-hasura-graphql.d.ts +3 -1
- package/infra/hasura-graphql/models/index.d.ts +3 -0
- package/infra/hasura-graphql/models/kit-product-hasura-graphql.d.ts +6 -0
- package/infra/hasura-graphql/models/product-hasura-graphql.d.ts +9 -0
- package/infra/hasura-graphql/models/variant-hasura-graphql.d.ts +9 -0
- package/infra/hasura-graphql/repositories/catalog/index.d.ts +1 -0
- package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +21 -5
- package/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +13 -0
- package/infra/hasura-graphql/types/graphql.repository.type.d.ts +5 -5
- package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +15 -19
- package/infra/hasura-graphql/types/hasura-graphql-headers.type.d.ts +7 -0
- package/infra/hasura-graphql/types/index.d.ts +1 -0
- package/package.json +4 -3
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('ts-
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'ts-
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global
|
|
5
|
-
})(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, tsMd5, axios, firebase,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('ts-custom-error'), require('ts-md5'), require('axios'), require('firebase'), require('gql-query-builder'), require('node-fetch')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'ts-custom-error', 'ts-md5', 'axios', 'firebase', 'gql-query-builder', 'node-fetch'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global["ts-custom-error"], global["ts-md5"], global.axios, global.firebase, global["gql-query-builder"], global["node-fetch"]));
|
|
5
|
+
})(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, tsCustomError, tsMd5, axios, firebase, gqlQueryBuilder, fetch) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
10
10
|
var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
|
|
11
|
-
var firebase__default$1 = /*#__PURE__*/_interopDefaultLegacy(firebase$1);
|
|
12
11
|
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
13
12
|
|
|
14
13
|
var BaseModel = /** @class */ (function () {
|
|
@@ -35,13 +34,13 @@
|
|
|
35
34
|
configurable: true
|
|
36
35
|
});
|
|
37
36
|
BaseModel.toInstance = function (data) {
|
|
38
|
-
return classTransformer.
|
|
37
|
+
return classTransformer.plainToInstance(this, data || {});
|
|
39
38
|
};
|
|
40
39
|
BaseModel.isModel = function (value) {
|
|
41
40
|
return value instanceof this;
|
|
42
41
|
};
|
|
43
42
|
BaseModel.prototype.toPlain = function () {
|
|
44
|
-
return classTransformer.
|
|
43
|
+
return classTransformer.instanceToPlain(this);
|
|
45
44
|
};
|
|
46
45
|
return BaseModel;
|
|
47
46
|
}());
|
|
@@ -1048,7 +1047,7 @@
|
|
|
1048
1047
|
return _this;
|
|
1049
1048
|
}
|
|
1050
1049
|
return UnauthorizedError;
|
|
1051
|
-
}(
|
|
1050
|
+
}(tsCustomError.CustomError));
|
|
1052
1051
|
|
|
1053
1052
|
exports.SignInMethods = void 0;
|
|
1054
1053
|
(function (SignInMethods) {
|
|
@@ -1107,7 +1106,7 @@
|
|
|
1107
1106
|
return _this;
|
|
1108
1107
|
}
|
|
1109
1108
|
return UserAlreadyRegisteredError;
|
|
1110
|
-
}(
|
|
1109
|
+
}(tsCustomError.CustomError));
|
|
1111
1110
|
|
|
1112
1111
|
var WeakPasswordError = /** @class */ (function (_super) {
|
|
1113
1112
|
__extends(WeakPasswordError, _super);
|
|
@@ -1118,7 +1117,7 @@
|
|
|
1118
1117
|
return _this;
|
|
1119
1118
|
}
|
|
1120
1119
|
return WeakPasswordError;
|
|
1121
|
-
}(
|
|
1120
|
+
}(tsCustomError.CustomError));
|
|
1122
1121
|
|
|
1123
1122
|
var Register = /** @class */ (function () {
|
|
1124
1123
|
function Register(registerService, userRepository) {
|
|
@@ -1204,13 +1203,6 @@
|
|
|
1204
1203
|
return RecoveryPassword;
|
|
1205
1204
|
}());
|
|
1206
1205
|
|
|
1207
|
-
exports.Shops = void 0;
|
|
1208
|
-
(function (Shops) {
|
|
1209
|
-
Shops["MENSMARKET"] = "mensmarket";
|
|
1210
|
-
Shops["GLAMSHOP"] = "Glamshop";
|
|
1211
|
-
Shops["GLAMPOINTS"] = "Glampoints";
|
|
1212
|
-
})(exports.Shops || (exports.Shops = {}));
|
|
1213
|
-
|
|
1214
1206
|
var Category = /** @class */ (function (_super) {
|
|
1215
1207
|
__extends(Category, _super);
|
|
1216
1208
|
function Category() {
|
|
@@ -1229,6 +1221,13 @@
|
|
|
1229
1221
|
return Category;
|
|
1230
1222
|
}(BaseModel));
|
|
1231
1223
|
|
|
1224
|
+
exports.Shops = void 0;
|
|
1225
|
+
(function (Shops) {
|
|
1226
|
+
Shops["MENSMARKET"] = "mensmarket";
|
|
1227
|
+
Shops["GLAMSHOP"] = "Glamshop";
|
|
1228
|
+
Shops["GLAMPOINTS"] = "Glampoints";
|
|
1229
|
+
})(exports.Shops || (exports.Shops = {}));
|
|
1230
|
+
|
|
1232
1231
|
var Product = /** @class */ (function (_super) {
|
|
1233
1232
|
__extends(Product, _super);
|
|
1234
1233
|
function Product() {
|
|
@@ -1250,6 +1249,33 @@
|
|
|
1250
1249
|
});
|
|
1251
1250
|
return Product;
|
|
1252
1251
|
}(BaseModel));
|
|
1252
|
+
__decorate([
|
|
1253
|
+
classTransformer.Type(function () { return KitProduct; }),
|
|
1254
|
+
__metadata("design:type", Array)
|
|
1255
|
+
], Product.prototype, "kitProducts", void 0);
|
|
1256
|
+
|
|
1257
|
+
var KitProduct = /** @class */ (function (_super) {
|
|
1258
|
+
__extends(KitProduct, _super);
|
|
1259
|
+
function KitProduct() {
|
|
1260
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1261
|
+
}
|
|
1262
|
+
Object.defineProperty(KitProduct, "identifiersFields", {
|
|
1263
|
+
get: function () {
|
|
1264
|
+
return ['productId', 'kitProducId'];
|
|
1265
|
+
},
|
|
1266
|
+
enumerable: false,
|
|
1267
|
+
configurable: true
|
|
1268
|
+
});
|
|
1269
|
+
return KitProduct;
|
|
1270
|
+
}(BaseModel));
|
|
1271
|
+
__decorate([
|
|
1272
|
+
classTransformer.Type(function () { return Product; }),
|
|
1273
|
+
__metadata("design:type", Product)
|
|
1274
|
+
], KitProduct.prototype, "kit", void 0);
|
|
1275
|
+
__decorate([
|
|
1276
|
+
classTransformer.Type(function () { return Product; }),
|
|
1277
|
+
__metadata("design:type", Product)
|
|
1278
|
+
], KitProduct.prototype, "product", void 0);
|
|
1253
1279
|
|
|
1254
1280
|
var Variant = /** @class */ (function (_super) {
|
|
1255
1281
|
__extends(Variant, _super);
|
|
@@ -1586,7 +1612,7 @@
|
|
|
1586
1612
|
return _this;
|
|
1587
1613
|
}
|
|
1588
1614
|
return InvalidArgumentError;
|
|
1589
|
-
}(
|
|
1615
|
+
}(tsCustomError.CustomError));
|
|
1590
1616
|
|
|
1591
1617
|
var RequiredArgumentError = /** @class */ (function (_super) {
|
|
1592
1618
|
__extends(RequiredArgumentError, _super);
|
|
@@ -1597,7 +1623,7 @@
|
|
|
1597
1623
|
return _this;
|
|
1598
1624
|
}
|
|
1599
1625
|
return RequiredArgumentError;
|
|
1600
|
-
}(
|
|
1626
|
+
}(tsCustomError.CustomError));
|
|
1601
1627
|
|
|
1602
1628
|
var NotFoundError = /** @class */ (function (_super) {
|
|
1603
1629
|
__extends(NotFoundError, _super);
|
|
@@ -1607,7 +1633,7 @@
|
|
|
1607
1633
|
return _this;
|
|
1608
1634
|
}
|
|
1609
1635
|
return NotFoundError;
|
|
1610
|
-
}(
|
|
1636
|
+
}(tsCustomError.CustomError));
|
|
1611
1637
|
|
|
1612
1638
|
var DuplicatedResultsError = /** @class */ (function (_super) {
|
|
1613
1639
|
__extends(DuplicatedResultsError, _super);
|
|
@@ -1617,12 +1643,35 @@
|
|
|
1617
1643
|
return _this;
|
|
1618
1644
|
}
|
|
1619
1645
|
return DuplicatedResultsError;
|
|
1620
|
-
}(
|
|
1646
|
+
}(tsCustomError.CustomError));
|
|
1621
1647
|
|
|
1622
1648
|
var AxiosAdapter = /** @class */ (function () {
|
|
1623
1649
|
function AxiosAdapter(config) {
|
|
1624
1650
|
this.config = config;
|
|
1625
1651
|
}
|
|
1652
|
+
AxiosAdapter.prototype.get = function (index) {
|
|
1653
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1654
|
+
var data, error_1;
|
|
1655
|
+
return __generator(this, function (_a) {
|
|
1656
|
+
switch (_a.label) {
|
|
1657
|
+
case 0:
|
|
1658
|
+
_a.trys.push([0, 2, , 3]);
|
|
1659
|
+
return [4 /*yield*/, axios__default["default"]({
|
|
1660
|
+
url: this.config.url + "/" + index,
|
|
1661
|
+
method: 'GET',
|
|
1662
|
+
headers: { Authorization: "Basic " + this.config.credential },
|
|
1663
|
+
})];
|
|
1664
|
+
case 1:
|
|
1665
|
+
data = (_a.sent()).data;
|
|
1666
|
+
return [2 /*return*/, data._source];
|
|
1667
|
+
case 2:
|
|
1668
|
+
error_1 = _a.sent();
|
|
1669
|
+
throw new NotFoundError(error_1.message);
|
|
1670
|
+
case 3: return [2 /*return*/];
|
|
1671
|
+
}
|
|
1672
|
+
});
|
|
1673
|
+
});
|
|
1674
|
+
};
|
|
1626
1675
|
AxiosAdapter.prototype.query = function (index, query) {
|
|
1627
1676
|
return __awaiter(this, void 0, void 0, function () {
|
|
1628
1677
|
var data;
|
|
@@ -1644,6 +1693,39 @@
|
|
|
1644
1693
|
});
|
|
1645
1694
|
});
|
|
1646
1695
|
};
|
|
1696
|
+
AxiosAdapter.prototype.save = function (index, data) {
|
|
1697
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1698
|
+
return __generator(this, function (_a) {
|
|
1699
|
+
switch (_a.label) {
|
|
1700
|
+
case 0: return [4 /*yield*/, axios__default["default"]({
|
|
1701
|
+
url: this.config.url + "/" + index,
|
|
1702
|
+
method: 'PUT',
|
|
1703
|
+
headers: { Authorization: "Basic " + this.config.credential },
|
|
1704
|
+
data: data,
|
|
1705
|
+
})];
|
|
1706
|
+
case 1:
|
|
1707
|
+
_a.sent();
|
|
1708
|
+
return [2 /*return*/];
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
});
|
|
1712
|
+
};
|
|
1713
|
+
AxiosAdapter.prototype.delete = function (index) {
|
|
1714
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1715
|
+
return __generator(this, function (_a) {
|
|
1716
|
+
switch (_a.label) {
|
|
1717
|
+
case 0: return [4 /*yield*/, axios__default["default"]({
|
|
1718
|
+
url: this.config.url + "/" + index,
|
|
1719
|
+
method: 'DELETE',
|
|
1720
|
+
headers: { Authorization: "Basic " + this.config.credential },
|
|
1721
|
+
})];
|
|
1722
|
+
case 1:
|
|
1723
|
+
_a.sent();
|
|
1724
|
+
return [2 /*return*/];
|
|
1725
|
+
}
|
|
1726
|
+
});
|
|
1727
|
+
});
|
|
1728
|
+
};
|
|
1647
1729
|
return AxiosAdapter;
|
|
1648
1730
|
}());
|
|
1649
1731
|
|
|
@@ -1651,6 +1733,19 @@
|
|
|
1651
1733
|
function ProductsIndex(adapter) {
|
|
1652
1734
|
this.adapter = adapter;
|
|
1653
1735
|
}
|
|
1736
|
+
ProductsIndex.prototype.get = function (id) {
|
|
1737
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1738
|
+
var data;
|
|
1739
|
+
return __generator(this, function (_a) {
|
|
1740
|
+
switch (_a.label) {
|
|
1741
|
+
case 0: return [4 /*yield*/, this.adapter.get("products/_doc/" + id)];
|
|
1742
|
+
case 1:
|
|
1743
|
+
data = _a.sent();
|
|
1744
|
+
return [2 /*return*/, Product.toInstance(data)];
|
|
1745
|
+
}
|
|
1746
|
+
});
|
|
1747
|
+
});
|
|
1748
|
+
};
|
|
1654
1749
|
ProductsIndex.prototype.findById = function (ids, options) {
|
|
1655
1750
|
return __awaiter(this, void 0, void 0, function () {
|
|
1656
1751
|
var publishedField, fields, hits;
|
|
@@ -1710,6 +1805,64 @@
|
|
|
1710
1805
|
});
|
|
1711
1806
|
});
|
|
1712
1807
|
};
|
|
1808
|
+
ProductsIndex.prototype.save = function (product) {
|
|
1809
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1810
|
+
var error_1;
|
|
1811
|
+
return __generator(this, function (_a) {
|
|
1812
|
+
switch (_a.label) {
|
|
1813
|
+
case 0:
|
|
1814
|
+
delete product.createdAt;
|
|
1815
|
+
delete product.updatedAt;
|
|
1816
|
+
delete product.kitProducts;
|
|
1817
|
+
_a.label = 1;
|
|
1818
|
+
case 1:
|
|
1819
|
+
_a.trys.push([1, 4, , 6]);
|
|
1820
|
+
if (!product.firestoreId)
|
|
1821
|
+
throw new Error('Is not a product from firestore');
|
|
1822
|
+
return [4 /*yield*/, this.get(product.firestoreId)];
|
|
1823
|
+
case 2:
|
|
1824
|
+
_a.sent();
|
|
1825
|
+
return [4 /*yield*/, this.adapter.save("products/_doc/" + product.firestoreId, product.toPlain())];
|
|
1826
|
+
case 3:
|
|
1827
|
+
_a.sent();
|
|
1828
|
+
return [3 /*break*/, 6];
|
|
1829
|
+
case 4:
|
|
1830
|
+
error_1 = _a.sent();
|
|
1831
|
+
console.info(error_1.message);
|
|
1832
|
+
return [4 /*yield*/, this.adapter.save("products/_doc/" + product.id, product.toPlain())];
|
|
1833
|
+
case 5:
|
|
1834
|
+
_a.sent();
|
|
1835
|
+
return [3 /*break*/, 6];
|
|
1836
|
+
case 6: return [2 /*return*/];
|
|
1837
|
+
}
|
|
1838
|
+
});
|
|
1839
|
+
});
|
|
1840
|
+
};
|
|
1841
|
+
ProductsIndex.prototype.delete = function (product) {
|
|
1842
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1843
|
+
var error_2;
|
|
1844
|
+
return __generator(this, function (_a) {
|
|
1845
|
+
switch (_a.label) {
|
|
1846
|
+
case 0:
|
|
1847
|
+
_a.trys.push([0, 3, , 5]);
|
|
1848
|
+
return [4 /*yield*/, this.get(product.firestoreId)];
|
|
1849
|
+
case 1:
|
|
1850
|
+
_a.sent();
|
|
1851
|
+
return [4 /*yield*/, this.adapter.delete("products/_doc/" + product.firestoreId)];
|
|
1852
|
+
case 2:
|
|
1853
|
+
_a.sent();
|
|
1854
|
+
return [3 /*break*/, 5];
|
|
1855
|
+
case 3:
|
|
1856
|
+
error_2 = _a.sent();
|
|
1857
|
+
return [4 /*yield*/, this.adapter.delete("products/_doc/" + product.id)];
|
|
1858
|
+
case 4:
|
|
1859
|
+
_a.sent();
|
|
1860
|
+
return [3 /*break*/, 5];
|
|
1861
|
+
case 5: return [2 /*return*/];
|
|
1862
|
+
}
|
|
1863
|
+
});
|
|
1864
|
+
});
|
|
1865
|
+
};
|
|
1713
1866
|
return ProductsIndex;
|
|
1714
1867
|
}());
|
|
1715
1868
|
|
|
@@ -1729,7 +1882,7 @@
|
|
|
1729
1882
|
fromFirestore: function (snap) {
|
|
1730
1883
|
var data = snap.data();
|
|
1731
1884
|
Object.keys(data).forEach(function (key) {
|
|
1732
|
-
if (data[key]
|
|
1885
|
+
if (data[key] && typeof data[key] === 'object' && '_seconds' in data[key]) {
|
|
1733
1886
|
data[key] = data[key].toDate();
|
|
1734
1887
|
}
|
|
1735
1888
|
});
|
|
@@ -1835,15 +1988,15 @@
|
|
|
1835
1988
|
return _this;
|
|
1836
1989
|
}
|
|
1837
1990
|
FindFirestore.prototype.find = function (_a) {
|
|
1838
|
-
var filters =
|
|
1991
|
+
var _b = _a === void 0 ? {} : _a, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
|
|
1839
1992
|
return __awaiter(this, void 0, void 0, function () {
|
|
1840
1993
|
var query, docs, data;
|
|
1841
1994
|
return __generator(this, function (_a) {
|
|
1842
1995
|
switch (_a.label) {
|
|
1843
1996
|
case 0:
|
|
1844
|
-
query = this.collection(this.buildCollectionPathForFind(filters));
|
|
1845
|
-
query = this.makeFirestoreWhere(query, filters);
|
|
1846
|
-
Object.keys(orderBy).forEach(function (fieldName) { return (query = query.orderBy(fieldName, orderBy[fieldName])); });
|
|
1997
|
+
query = this.collection(this.buildCollectionPathForFind(filters || {}));
|
|
1998
|
+
query = this.makeFirestoreWhere(query, filters || {});
|
|
1999
|
+
Object.keys(orderBy || {}).forEach(function (fieldName) { return (query = query.orderBy(fieldName, orderBy[fieldName])); });
|
|
1847
2000
|
return [4 /*yield*/, this.defineLimits(query, filters, limits)];
|
|
1848
2001
|
case 1:
|
|
1849
2002
|
query = _a.sent();
|
|
@@ -2378,7 +2531,9 @@
|
|
|
2378
2531
|
productIds = chunks_1_1.value;
|
|
2379
2532
|
if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
|
|
2380
2533
|
return [3 /*break*/, 6];
|
|
2381
|
-
return [4 /*yield*/, this.collection('
|
|
2534
|
+
return [4 /*yield*/, this.collection('productsErpVitrine')
|
|
2535
|
+
.where(publishedField, '==', true)
|
|
2536
|
+
.where('id', 'in', productIds)];
|
|
2382
2537
|
case 3:
|
|
2383
2538
|
query = _b.sent();
|
|
2384
2539
|
if (options === null || options === void 0 ? void 0 : options.hasStock)
|
|
@@ -2419,11 +2574,12 @@
|
|
|
2419
2574
|
function ProductFirestoreRepository(firestore) {
|
|
2420
2575
|
var _this = _super.call(this) || this;
|
|
2421
2576
|
_this.firestore = firestore;
|
|
2422
|
-
_this.
|
|
2577
|
+
_this.reviews = {};
|
|
2578
|
+
_this.collectionName = 'productsErpVitrine';
|
|
2423
2579
|
_this.model = Product;
|
|
2424
2580
|
return _this;
|
|
2425
2581
|
}
|
|
2426
|
-
ProductFirestoreRepository.prototype.getBySlug = function (slug
|
|
2582
|
+
ProductFirestoreRepository.prototype.getBySlug = function (slug) {
|
|
2427
2583
|
var _a;
|
|
2428
2584
|
return __awaiter(this, void 0, void 0, function () {
|
|
2429
2585
|
var result;
|
|
@@ -2432,7 +2588,6 @@
|
|
|
2432
2588
|
case 0: return [4 /*yield*/, this.find({
|
|
2433
2589
|
filters: {
|
|
2434
2590
|
slug: { operator: exports.Where.EQUALS, value: slug },
|
|
2435
|
-
shopAvailability: { operator: exports.Where.IN, value: [shop] },
|
|
2436
2591
|
},
|
|
2437
2592
|
})];
|
|
2438
2593
|
case 1:
|
|
@@ -2442,6 +2597,41 @@
|
|
|
2442
2597
|
});
|
|
2443
2598
|
});
|
|
2444
2599
|
};
|
|
2600
|
+
ProductFirestoreRepository.prototype.fetchReviews = function (status) {
|
|
2601
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2602
|
+
var products;
|
|
2603
|
+
var _this = this;
|
|
2604
|
+
return __generator(this, function (_b) {
|
|
2605
|
+
switch (_b.label) {
|
|
2606
|
+
case 0: return [4 /*yield*/, this.find()];
|
|
2607
|
+
case 1:
|
|
2608
|
+
products = (_b.sent()).data;
|
|
2609
|
+
products.forEach(function (product) {
|
|
2610
|
+
var _a;
|
|
2611
|
+
if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
|
|
2612
|
+
return;
|
|
2613
|
+
var productInfo = {
|
|
2614
|
+
productId: product.id,
|
|
2615
|
+
productName: product.name,
|
|
2616
|
+
productSku: product.sku,
|
|
2617
|
+
};
|
|
2618
|
+
_this.reviews.pending = [];
|
|
2619
|
+
_this.reviews.approved = [];
|
|
2620
|
+
_this.reviews.rejected = [];
|
|
2621
|
+
product.reviews.forEach(function (review) {
|
|
2622
|
+
if ([null, undefined].includes(review.status))
|
|
2623
|
+
return _this.reviews.pending.push(Object.assign(Object.assign({}, review), productInfo));
|
|
2624
|
+
if (review.status === false)
|
|
2625
|
+
return _this.reviews.rejected.push(Object.assign(Object.assign({}, review), productInfo));
|
|
2626
|
+
if (!!review.status)
|
|
2627
|
+
return _this.reviews.approved.push(Object.assign(Object.assign({}, review), productInfo));
|
|
2628
|
+
});
|
|
2629
|
+
});
|
|
2630
|
+
return [2 /*return*/, this.reviews[status]];
|
|
2631
|
+
}
|
|
2632
|
+
});
|
|
2633
|
+
});
|
|
2634
|
+
};
|
|
2445
2635
|
return ProductFirestoreRepository;
|
|
2446
2636
|
}(withCrudFirestore(withHelpers(withFirestore(Base)))));
|
|
2447
2637
|
|
|
@@ -2680,7 +2870,7 @@
|
|
|
2680
2870
|
var credentials, user;
|
|
2681
2871
|
return __generator(this, function (_a) {
|
|
2682
2872
|
switch (_a.label) {
|
|
2683
|
-
case 0: return [4 /*yield*/, this.firebaseAuth.signInWithPopup(new firebase__default
|
|
2873
|
+
case 0: return [4 /*yield*/, this.firebaseAuth.signInWithPopup(new firebase__default["default"].auth.GoogleAuthProvider())];
|
|
2684
2874
|
case 1:
|
|
2685
2875
|
credentials = _a.sent();
|
|
2686
2876
|
user = credentials.user;
|
|
@@ -2761,6 +2951,137 @@
|
|
|
2761
2951
|
return RegisterFirebaseAuthService;
|
|
2762
2952
|
}());
|
|
2763
2953
|
|
|
2954
|
+
var AttributeOptionHelper = /** @class */ (function () {
|
|
2955
|
+
function AttributeOptionHelper() {
|
|
2956
|
+
}
|
|
2957
|
+
return AttributeOptionHelper;
|
|
2958
|
+
}());
|
|
2959
|
+
AttributeOptionHelper.FindByAttribute = function (attributeName, fields) {
|
|
2960
|
+
if (fields.includes(attributeName))
|
|
2961
|
+
return { columnName: attributeName.toString(), attributeName: attributeName };
|
|
2962
|
+
var field = fields.find(function (columnOption) { return lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()); });
|
|
2963
|
+
var fieldOption = field === null || field === void 0 ? void 0 : field[attributeName.toString()];
|
|
2964
|
+
if (lodash.isNil(fieldOption))
|
|
2965
|
+
return { columnName: attributeName.toString(), attributeName: attributeName };
|
|
2966
|
+
if (Array.isArray(fieldOption))
|
|
2967
|
+
return { columnName: attributeName.toString(), attributeName: attributeName, fields: fieldOption };
|
|
2968
|
+
return Object.assign({ attributeName: attributeName, columnName: attributeName.toString() }, fieldOption);
|
|
2969
|
+
};
|
|
2970
|
+
AttributeOptionHelper.CheckIsColumnOption = function (fieldValue) { return !!fieldValue.columnName; };
|
|
2971
|
+
AttributeOptionHelper.FindColumnOptionFromList = function (columnName, fields) {
|
|
2972
|
+
if (fields.includes(columnName))
|
|
2973
|
+
return { columnName: columnName, attributeName: columnName };
|
|
2974
|
+
var field = fields.find(function (columnOption) {
|
|
2975
|
+
var _a;
|
|
2976
|
+
return lodash.isObject(columnOption) &&
|
|
2977
|
+
((_a = Object.values(columnOption).find(function (option) { return AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName; })) === null || _a === void 0 ? void 0 : _a.columnName) === columnName;
|
|
2978
|
+
}) || {};
|
|
2979
|
+
var attributeName = Object.keys(field).find(function (fieldOptionFromList) { return AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) ||
|
|
2980
|
+
Array.isArray(field[fieldOptionFromList]); });
|
|
2981
|
+
var fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
|
|
2982
|
+
if (Array.isArray(fieldOption))
|
|
2983
|
+
return { attributeName: attributeName, fields: fieldOption };
|
|
2984
|
+
return Object.assign({ attributeName: attributeName || columnName, columnName: columnName }, fieldOption);
|
|
2985
|
+
};
|
|
2986
|
+
|
|
2987
|
+
var GraphQLFieldHelper = /** @class */ (function () {
|
|
2988
|
+
function GraphQLFieldHelper() {
|
|
2989
|
+
}
|
|
2990
|
+
return GraphQLFieldHelper;
|
|
2991
|
+
}());
|
|
2992
|
+
GraphQLFieldHelper.CheckIsGraphQLParams = function (params) { return !lodash.isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation; };
|
|
2993
|
+
GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = function (fields) {
|
|
2994
|
+
return fields === null || fields === void 0 ? void 0 : fields.map(function (field) {
|
|
2995
|
+
var _b, _c;
|
|
2996
|
+
if (lodash.isString(field))
|
|
2997
|
+
return field.toString();
|
|
2998
|
+
var fieldName = Object.keys(field).shift();
|
|
2999
|
+
var fieldValue = field[fieldName];
|
|
3000
|
+
if (Array.isArray(fieldValue))
|
|
3001
|
+
return _b = {}, _b[fieldName] = GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue), _b;
|
|
3002
|
+
if (!AttributeOptionHelper.CheckIsColumnOption(fieldValue))
|
|
3003
|
+
return;
|
|
3004
|
+
if (fieldValue.fields)
|
|
3005
|
+
return _c = {},
|
|
3006
|
+
_c[fieldValue.columnName || fieldName] = GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
3007
|
+
_c;
|
|
3008
|
+
return fieldValue.columnName;
|
|
3009
|
+
}).filter(function (field) { return !!field; });
|
|
3010
|
+
};
|
|
3011
|
+
GraphQLFieldHelper.ConvertFieldValueFrom = function (data, fields) { return Object.keys(data).reduce(function (result, columnName) {
|
|
3012
|
+
var _b, _c, _d, _e;
|
|
3013
|
+
var _f = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields), attributeName = _f.attributeName, attributeFields = _f.fields, from = _f.from;
|
|
3014
|
+
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
3015
|
+
if (Array.isArray(data[columnName]))
|
|
3016
|
+
return Object.assign(Object.assign({}, result), (_b = {}, _b[attributeName] = from
|
|
3017
|
+
? from(data[columnName], data)
|
|
3018
|
+
: data[columnName].map(function (value) { return GraphQLFieldHelper.ConvertFieldValueFrom(value, attributeFields); }), _b));
|
|
3019
|
+
if (lodash.isObject(data[columnName]))
|
|
3020
|
+
return Object.assign(Object.assign({}, result), (_c = {}, _c[attributeName] = !!from
|
|
3021
|
+
? from(data[columnName])
|
|
3022
|
+
: GraphQLFieldHelper.ConvertFieldValueFrom(data[columnName], attributeFields), _c));
|
|
3023
|
+
}
|
|
3024
|
+
if (!!from)
|
|
3025
|
+
return Object.assign(Object.assign({}, result), (_d = {}, _d[attributeName] = from(data[columnName], data), _d));
|
|
3026
|
+
return Object.assign(Object.assign({}, result), (_e = {}, _e[attributeName] = parseDateTime(data[columnName]), _e));
|
|
3027
|
+
}, {}); };
|
|
3028
|
+
GraphQLFieldHelper.ConvertFieldValueTo = function (instance, fields, update) {
|
|
3029
|
+
if (update === void 0) { update = false; }
|
|
3030
|
+
var _a;
|
|
3031
|
+
var data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
3032
|
+
return Object.keys(data).reduce(function (result, attributeName) {
|
|
3033
|
+
var _b, _c, _d;
|
|
3034
|
+
var _e = AttributeOptionHelper.FindByAttribute(attributeName, fields), columnName = _e.columnName, attributeFields = _e.fields, foreignKeyColumn = _e.foreignKeyColumn, to = _e.to, bindPersistData = _e.bindPersistData;
|
|
3035
|
+
if (bindPersistData)
|
|
3036
|
+
return Object.assign(Object.assign({}, result), bindPersistData(data[attributeName], instance));
|
|
3037
|
+
if (lodash.isNil(columnName))
|
|
3038
|
+
return result;
|
|
3039
|
+
if (!!foreignKeyColumn &&
|
|
3040
|
+
!lodash.isEmpty(foreignKeyColumn) &&
|
|
3041
|
+
!Object.keys(foreignKeyColumn).filter(function (key) { var _a; return !((_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[key]); }).length)
|
|
3042
|
+
return Object.keys(foreignKeyColumn).reduce(function (object, current) {
|
|
3043
|
+
var _b;
|
|
3044
|
+
var _a;
|
|
3045
|
+
return (Object.assign(Object.assign({}, object), (_b = {}, _b[foreignKeyColumn[current]] = (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current], _b)));
|
|
3046
|
+
}, Object.assign({}, result));
|
|
3047
|
+
if (update && lodash.isObject(data[attributeName]) && !lodash.isNil(attributeFields) && !lodash.isDate(data[attributeName]))
|
|
3048
|
+
return result;
|
|
3049
|
+
if (!!columnName && Array.isArray(attributeFields) && lodash.isObject(data[attributeName])) {
|
|
3050
|
+
var converted = !lodash.isNil(columnName) && to ? to(instance[attributeName], instance) : data[attributeName];
|
|
3051
|
+
return Object.assign(Object.assign({}, result), (converted !== undefined
|
|
3052
|
+
? (_b = {},
|
|
3053
|
+
_b[columnName] = {
|
|
3054
|
+
data: instance[attributeName] instanceof BaseModel
|
|
3055
|
+
? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
|
|
3056
|
+
: converted,
|
|
3057
|
+
},
|
|
3058
|
+
_b) : {}));
|
|
3059
|
+
}
|
|
3060
|
+
if (!!to)
|
|
3061
|
+
return Object.assign(Object.assign({}, result), (_c = {}, _c[columnName] = to(instance[attributeName], instance), _c));
|
|
3062
|
+
return Object.assign(Object.assign({}, result), (_d = {}, _d[columnName] = data[attributeName], _d));
|
|
3063
|
+
}, {});
|
|
3064
|
+
};
|
|
3065
|
+
|
|
3066
|
+
var FilterOptionHelper = /** @class */ (function () {
|
|
3067
|
+
function FilterOptionHelper() {
|
|
3068
|
+
}
|
|
3069
|
+
return FilterOptionHelper;
|
|
3070
|
+
}());
|
|
3071
|
+
FilterOptionHelper.CheckIfIsFilterOption = function (filter) { return !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator); };
|
|
3072
|
+
FilterOptionHelper.GetValueFromFilter = function (filter, fieldOption) {
|
|
3073
|
+
if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
|
|
3074
|
+
return filter;
|
|
3075
|
+
if (filter.operator === exports.Where.ISNULL)
|
|
3076
|
+
return true;
|
|
3077
|
+
if (filter.operator === exports.Where.ISNOTNULL)
|
|
3078
|
+
return false;
|
|
3079
|
+
var converter = fieldOption.to ? fieldOption.to : function (value) { return value; };
|
|
3080
|
+
return Array.isArray(filter.value) && !fieldOption.fields && [exports.Where.IN, exports.Where.NOTIN].includes(filter.operator)
|
|
3081
|
+
? filter.value.map(function (fieldValue) { return converter(fieldValue); })
|
|
3082
|
+
: converter(filter.value);
|
|
3083
|
+
};
|
|
3084
|
+
|
|
2764
3085
|
var withCreateHasuraGraphQL = function (MixinBase) {
|
|
2765
3086
|
return /** @class */ (function (_super) {
|
|
2766
3087
|
__extends(CreateHasuraGraphQLMixin, _super);
|
|
@@ -2779,11 +3100,11 @@
|
|
|
2779
3100
|
CreateHasuraGraphQLMixin.prototype.create = function (data) {
|
|
2780
3101
|
return __awaiter(this, void 0, void 0, function () {
|
|
2781
3102
|
var newData;
|
|
2782
|
-
return __generator(this, function (
|
|
2783
|
-
switch (
|
|
3103
|
+
return __generator(this, function (_b) {
|
|
3104
|
+
switch (_b.label) {
|
|
2784
3105
|
case 0: return [4 /*yield*/, this.save(this.model.toInstance(data))];
|
|
2785
3106
|
case 1:
|
|
2786
|
-
newData =
|
|
3107
|
+
newData = _b.sent();
|
|
2787
3108
|
return [2 /*return*/, this.model.toInstance(newData)];
|
|
2788
3109
|
}
|
|
2789
3110
|
});
|
|
@@ -2791,14 +3112,34 @@
|
|
|
2791
3112
|
};
|
|
2792
3113
|
CreateHasuraGraphQLMixin.prototype.save = function (data) {
|
|
2793
3114
|
return __awaiter(this, void 0, void 0, function () {
|
|
2794
|
-
var result;
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
})
|
|
3115
|
+
var primaryKeyColumns, foreignKeyColumns, result;
|
|
3116
|
+
var _this = this;
|
|
3117
|
+
return __generator(this, function (_b) {
|
|
3118
|
+
switch (_b.label) {
|
|
3119
|
+
case 0:
|
|
3120
|
+
primaryKeyColumns = this.model.identifiersFields.map(function (field) { return AttributeOptionHelper.FindByAttribute(field, _this.fields).columnName; });
|
|
3121
|
+
foreignKeyColumns = this.fields
|
|
3122
|
+
.map(function (field) {
|
|
3123
|
+
var _b;
|
|
3124
|
+
var columnOptions = Object.values(field).shift();
|
|
3125
|
+
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
3126
|
+
columnOptions.foreignKeyColumn && __spreadArray(__spreadArray([], __read(Object.values(columnOptions.foreignKeyColumn))), [
|
|
3127
|
+
(_b = {},
|
|
3128
|
+
_b[columnOptions.columnName] = Object.keys(columnOptions.foreignKeyColumn).map(function (foreignKeyField) {
|
|
3129
|
+
var _a;
|
|
3130
|
+
return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) ||
|
|
3131
|
+
foreignKeyField;
|
|
3132
|
+
}),
|
|
3133
|
+
_b),
|
|
3134
|
+
]));
|
|
3135
|
+
})
|
|
3136
|
+
.filter(Boolean)
|
|
3137
|
+
.reduce(function (keys, current) { return __spreadArray(__spreadArray([], __read(keys)), __read(current)); }, []);
|
|
3138
|
+
return [4 /*yield*/, this.mutation(this.insertGraphQLOperation, __spreadArray(__spreadArray([], __read(primaryKeyColumns)), __read(foreignKeyColumns)), {
|
|
3139
|
+
object: { type: this.insertGraphQLObjectType, required: true, value: this.convertDataToHasura(data) },
|
|
3140
|
+
})];
|
|
2800
3141
|
case 1:
|
|
2801
|
-
result =
|
|
3142
|
+
result = _b.sent();
|
|
2802
3143
|
return [2 /*return*/, Object.assign(Object.assign({}, data.toPlain()), this.convertDataFromHasura(result[this.insertGraphQLOperation]).toPlain())];
|
|
2803
3144
|
}
|
|
2804
3145
|
});
|
|
@@ -2830,13 +3171,17 @@
|
|
|
2830
3171
|
switch (_a.label) {
|
|
2831
3172
|
case 0:
|
|
2832
3173
|
instance = this.model.toInstance(identifiers);
|
|
2833
|
-
return [4 /*yield*/, this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields
|
|
3174
|
+
return [4 /*yield*/, this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields.map(function (field) { return AttributeOptionHelper.FindByAttribute(field, _this.fields).columnName; }), this.model.identifiersFields.reduce(function (ids, identifier) {
|
|
2834
3175
|
var _a;
|
|
2835
|
-
|
|
2836
|
-
|
|
3176
|
+
if (lodash.isNil(instance[identifier]))
|
|
3177
|
+
return ids;
|
|
3178
|
+
var columnOption = AttributeOptionHelper.FindByAttribute(identifier, _this.fields);
|
|
3179
|
+
var value = columnOption.to(identifiers[identifier.toString()], instance);
|
|
3180
|
+
return Object.assign(Object.assign({}, ids), (_a = {}, _a[columnOption.columnName] = {
|
|
3181
|
+
type: _this.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3182
|
+
value: value,
|
|
2837
3183
|
required: true,
|
|
2838
|
-
|
|
2839
|
-
}, _a)));
|
|
3184
|
+
}, _a));
|
|
2840
3185
|
}, {}))];
|
|
2841
3186
|
case 1:
|
|
2842
3187
|
_a.sent();
|
|
@@ -2849,104 +3194,7 @@
|
|
|
2849
3194
|
}(MixinBase));
|
|
2850
3195
|
};
|
|
2851
3196
|
|
|
2852
|
-
var AttributeOptionHelper = /** @class */ (function () {
|
|
2853
|
-
function AttributeOptionHelper() {
|
|
2854
|
-
}
|
|
2855
|
-
return AttributeOptionHelper;
|
|
2856
|
-
}());
|
|
2857
|
-
AttributeOptionHelper.findByAttribute = function (attributeName, fields) {
|
|
2858
|
-
if (fields.includes(attributeName))
|
|
2859
|
-
return { columnName: attributeName.toString(), attributeName: attributeName };
|
|
2860
|
-
var field = fields.find(function (columnOption) { return lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()); });
|
|
2861
|
-
var fieldOption = field === null || field === void 0 ? void 0 : field[attributeName.toString()];
|
|
2862
|
-
if (lodash.isNil(fieldOption))
|
|
2863
|
-
return { columnName: attributeName.toString(), attributeName: attributeName };
|
|
2864
|
-
if (Array.isArray(fieldOption))
|
|
2865
|
-
return { columnName: attributeName.toString(), attributeName: attributeName, fields: fieldOption };
|
|
2866
|
-
return Object.assign({ attributeName: attributeName, columnName: attributeName.toString() }, fieldOption);
|
|
2867
|
-
};
|
|
2868
|
-
|
|
2869
3197
|
var withHasuraGraphQL = function (MixinBase) {
|
|
2870
|
-
var checkIsGraphQLParams = function (params) { return !lodash.isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation; };
|
|
2871
|
-
var checkIsColumnModelOption = function (fieldValue) { return !!fieldValue.columnName && !!fieldValue.fields; };
|
|
2872
|
-
var checkIsColumnOption = function (fieldValue) { return checkIsColumnModelOption(fieldValue) || !!fieldValue.columnName; };
|
|
2873
|
-
var convertModelFieldsToGraphQLFields = function (fields) {
|
|
2874
|
-
return fields
|
|
2875
|
-
.map(function (field) {
|
|
2876
|
-
var _b, _c;
|
|
2877
|
-
if (lodash.isString(field))
|
|
2878
|
-
return field.toString();
|
|
2879
|
-
var fieldName = Object.keys(field).shift();
|
|
2880
|
-
var fieldValue = field[fieldName];
|
|
2881
|
-
if (Array.isArray(fieldValue))
|
|
2882
|
-
return _b = {}, _b[fieldName] = convertModelFieldsToGraphQLFields(fieldValue), _b;
|
|
2883
|
-
if (checkIsColumnModelOption(fieldValue))
|
|
2884
|
-
return _c = {}, _c[fieldValue.columnName || fieldName] = convertModelFieldsToGraphQLFields(fieldValue.fields), _c;
|
|
2885
|
-
if (checkIsColumnOption(fieldValue))
|
|
2886
|
-
return fieldValue.columnName;
|
|
2887
|
-
return;
|
|
2888
|
-
})
|
|
2889
|
-
.filter(function (field) { return !!field; });
|
|
2890
|
-
};
|
|
2891
|
-
var findColumnOptionFromList = function (columnName, fields) {
|
|
2892
|
-
if (fields.includes(columnName))
|
|
2893
|
-
return { columnName: columnName, attributeName: columnName };
|
|
2894
|
-
var field = fields.find(function (columnOption) {
|
|
2895
|
-
var _a;
|
|
2896
|
-
return lodash.isObject(columnOption) &&
|
|
2897
|
-
((_a = Object.values(columnOption).find(function (option) { return checkIsColumnOption(option) && option.columnName === columnName; })) === null || _a === void 0 ? void 0 : _a.columnName) === columnName;
|
|
2898
|
-
}) || {};
|
|
2899
|
-
var attributeName = Object.keys(field).find(function (fieldOption) { return checkIsColumnOption(field[fieldOption]) || Array.isArray(field[fieldOption]); });
|
|
2900
|
-
var fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
|
|
2901
|
-
if (Array.isArray(fieldOption))
|
|
2902
|
-
return { attributeName: attributeName, fields: fieldOption };
|
|
2903
|
-
return Object.assign({ attributeName: attributeName || columnName, columnName: columnName }, fieldOption);
|
|
2904
|
-
};
|
|
2905
|
-
var convertFieldValueFrom = function (data, fields) { return Object.keys(data).reduce(function (result, columnName) {
|
|
2906
|
-
var _b, _c, _d, _e;
|
|
2907
|
-
var _f = findColumnOptionFromList(columnName, fields), attributeName = _f.attributeName, attributeFields = _f.fields, from = _f.from;
|
|
2908
|
-
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
2909
|
-
if (Array.isArray(data[columnName]))
|
|
2910
|
-
return Object.assign(Object.assign({}, result), (_b = {}, _b[attributeName] = from
|
|
2911
|
-
? from(data[columnName], data)
|
|
2912
|
-
: data[columnName].map(function (value) { return convertFieldValueFrom(value, attributeFields); }), _b));
|
|
2913
|
-
if (lodash.isObject(data[columnName]))
|
|
2914
|
-
return Object.assign(Object.assign({}, result), (_c = {}, _c[attributeName] = convertFieldValueFrom(data[columnName], attributeFields), _c));
|
|
2915
|
-
}
|
|
2916
|
-
if (!!from)
|
|
2917
|
-
return Object.assign(Object.assign({}, result), (_d = {}, _d[attributeName] = from(data[columnName], data), _d));
|
|
2918
|
-
return Object.assign(Object.assign({}, result), (_e = {}, _e[attributeName] = parseDateTime(data[columnName]), _e));
|
|
2919
|
-
}, {}); };
|
|
2920
|
-
var convertFieldValueTo = function (instance, fields, update) {
|
|
2921
|
-
if (update === void 0) { update = false; }
|
|
2922
|
-
var _a;
|
|
2923
|
-
var data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
2924
|
-
return Object.keys(data)
|
|
2925
|
-
.filter(function (key) { return !lodash.isNil(data[key]); })
|
|
2926
|
-
.reduce(function (result, attributeName) {
|
|
2927
|
-
var _b, _c, _d;
|
|
2928
|
-
var _e = AttributeOptionHelper.findByAttribute(attributeName, fields), columnName = _e.columnName, attributeFields = _e.fields, foreignKeyColumn = _e.foreignKeyColumn, to = _e.to;
|
|
2929
|
-
if (lodash.isNil(columnName))
|
|
2930
|
-
return result;
|
|
2931
|
-
if (!!foreignKeyColumn &&
|
|
2932
|
-
!lodash.isEmpty(foreignKeyColumn) &&
|
|
2933
|
-
!Object.keys(foreignKeyColumn).filter(function (key) { return !data[attributeName][key]; }).length)
|
|
2934
|
-
return Object.keys(foreignKeyColumn).reduce(function (object, current) {
|
|
2935
|
-
var _b;
|
|
2936
|
-
return (Object.assign(Object.assign({}, object), (_b = {}, _b[foreignKeyColumn[current]] = data[attributeName][current], _b)));
|
|
2937
|
-
}, Object.assign({}, result));
|
|
2938
|
-
if (update && lodash.isObject(data[attributeName]) && !lodash.isDate(data[attributeName]))
|
|
2939
|
-
return result;
|
|
2940
|
-
if (!!columnName && Array.isArray(attributeFields) && lodash.isObject(data[attributeName])) {
|
|
2941
|
-
var converted = !lodash.isNil(columnName) ? to(instance[attributeName], instance) : data[attributeName];
|
|
2942
|
-
return Object.assign(Object.assign({}, result), (converted !== undefined
|
|
2943
|
-
? (_b = {}, _b[columnName] = { data: convertFieldValueTo(data[attributeName], attributeFields) }, _b) : {}));
|
|
2944
|
-
}
|
|
2945
|
-
if (!!to)
|
|
2946
|
-
return Object.assign(Object.assign({}, result), (_c = {}, _c[columnName] = to(instance[attributeName], instance), _c));
|
|
2947
|
-
return Object.assign(Object.assign({}, result), (_d = {}, _d[columnName] = data[attributeName], _d));
|
|
2948
|
-
}, {});
|
|
2949
|
-
};
|
|
2950
3198
|
return /** @class */ (function (_super) {
|
|
2951
3199
|
__extends(HasuraGraphQLMixin, _super);
|
|
2952
3200
|
function HasuraGraphQLMixin() {
|
|
@@ -2976,11 +3224,11 @@
|
|
|
2976
3224
|
HasuraGraphQLMixin.prototype.mutation = function (operation, fields, variables) {
|
|
2977
3225
|
return __awaiter(this, void 0, void 0, function () {
|
|
2978
3226
|
var resultQuery;
|
|
2979
|
-
return __generator(this, function (
|
|
3227
|
+
return __generator(this, function (_a) {
|
|
2980
3228
|
resultQuery = gqlQueryBuilder.mutation({
|
|
2981
3229
|
operation: operation,
|
|
2982
3230
|
variables: variables,
|
|
2983
|
-
fields:
|
|
3231
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
|
|
2984
3232
|
});
|
|
2985
3233
|
return [2 /*return*/, this.fetch(resultQuery)];
|
|
2986
3234
|
});
|
|
@@ -2989,17 +3237,17 @@
|
|
|
2989
3237
|
HasuraGraphQLMixin.prototype.query = function (operation, fields, variables) {
|
|
2990
3238
|
return __awaiter(this, void 0, void 0, function () {
|
|
2991
3239
|
var resultQuery;
|
|
2992
|
-
return __generator(this, function (
|
|
2993
|
-
resultQuery =
|
|
3240
|
+
return __generator(this, function (_a) {
|
|
3241
|
+
resultQuery = GraphQLFieldHelper.CheckIsGraphQLParams(operation)
|
|
2994
3242
|
? gqlQueryBuilder.query(operation.map(function (option) { return ({
|
|
2995
3243
|
operation: option.operation,
|
|
2996
3244
|
variables: option.variables,
|
|
2997
|
-
fields:
|
|
3245
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(option.fields),
|
|
2998
3246
|
}); }))
|
|
2999
3247
|
: gqlQueryBuilder.query({
|
|
3000
3248
|
operation: operation,
|
|
3001
3249
|
variables: variables,
|
|
3002
|
-
fields:
|
|
3250
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
|
|
3003
3251
|
});
|
|
3004
3252
|
return [2 /*return*/, this.fetch(resultQuery)];
|
|
3005
3253
|
});
|
|
@@ -3008,8 +3256,8 @@
|
|
|
3008
3256
|
HasuraGraphQLMixin.prototype.fetch = function (params) {
|
|
3009
3257
|
return __awaiter(this, void 0, void 0, function () {
|
|
3010
3258
|
var headers, response, result;
|
|
3011
|
-
return __generator(this, function (
|
|
3012
|
-
switch (
|
|
3259
|
+
return __generator(this, function (_a) {
|
|
3260
|
+
switch (_a.label) {
|
|
3013
3261
|
case 0:
|
|
3014
3262
|
headers = this.headers;
|
|
3015
3263
|
return [4 /*yield*/, fetch__default["default"]("" + this.endpoint, {
|
|
@@ -3018,10 +3266,10 @@
|
|
|
3018
3266
|
headers: headers,
|
|
3019
3267
|
})];
|
|
3020
3268
|
case 1:
|
|
3021
|
-
response =
|
|
3269
|
+
response = _a.sent();
|
|
3022
3270
|
return [4 /*yield*/, response.json()];
|
|
3023
3271
|
case 2:
|
|
3024
|
-
result =
|
|
3272
|
+
result = _a.sent();
|
|
3025
3273
|
if (!lodash.isNil(result.errors))
|
|
3026
3274
|
throw new Error(JSON.stringify(result.errors));
|
|
3027
3275
|
return [2 /*return*/, result.data];
|
|
@@ -3053,12 +3301,12 @@
|
|
|
3053
3301
|
return date;
|
|
3054
3302
|
};
|
|
3055
3303
|
HasuraGraphQLMixin.prototype.convertDataFromHasura = function (data) {
|
|
3056
|
-
var plain =
|
|
3304
|
+
var plain = GraphQLFieldHelper.ConvertFieldValueFrom(data, this.fields);
|
|
3057
3305
|
return this.model.toInstance(plain);
|
|
3058
3306
|
};
|
|
3059
3307
|
HasuraGraphQLMixin.prototype.convertDataToHasura = function (instance, update) {
|
|
3060
3308
|
if (update === void 0) { update = false; }
|
|
3061
|
-
return
|
|
3309
|
+
return GraphQLFieldHelper.ConvertFieldValueTo(instance, this.fields, update);
|
|
3062
3310
|
};
|
|
3063
3311
|
return HasuraGraphQLMixin;
|
|
3064
3312
|
}(MixinBase));
|
|
@@ -3066,9 +3314,11 @@
|
|
|
3066
3314
|
|
|
3067
3315
|
var withUpdateHasuraGraphQL = function (MixinBase) {
|
|
3068
3316
|
var getValueByAction = function (options) {
|
|
3069
|
-
if (
|
|
3317
|
+
if (options instanceof BaseModel)
|
|
3318
|
+
return options.toPlain();
|
|
3319
|
+
if (lodash.isNil(options === null || options === void 0 ? void 0 : options.action))
|
|
3070
3320
|
return options;
|
|
3071
|
-
if (
|
|
3321
|
+
if ([exports.UpdateOptionActions.REMOVE_FIELD.toString(), exports.UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
3072
3322
|
return null;
|
|
3073
3323
|
return options.value;
|
|
3074
3324
|
};
|
|
@@ -3090,11 +3340,12 @@
|
|
|
3090
3340
|
UpdateHasuraGraphQLMixin.prototype.update = function (data) {
|
|
3091
3341
|
return __awaiter(this, void 0, void 0, function () {
|
|
3092
3342
|
var plainData;
|
|
3093
|
-
|
|
3094
|
-
|
|
3343
|
+
var _this = this;
|
|
3344
|
+
return __generator(this, function (_b) {
|
|
3345
|
+
switch (_b.label) {
|
|
3095
3346
|
case 0:
|
|
3096
3347
|
plainData = this.paramsToPlain(data);
|
|
3097
|
-
return [4 /*yield*/, this.mutation(this.updateGraphQLOperation, this.model.identifiersFields, {
|
|
3348
|
+
return [4 /*yield*/, this.mutation(this.updateGraphQLOperation, this.model.identifiersFields.map(function (field) { return AttributeOptionHelper.FindByAttribute(field, _this.fields).columnName; }), {
|
|
3098
3349
|
_set: {
|
|
3099
3350
|
type: this.updateGraphQLObjectType,
|
|
3100
3351
|
value: this.convertDataToHasura(this.model.toInstance(plainData), true),
|
|
@@ -3103,7 +3354,7 @@
|
|
|
3103
3354
|
pk_columns: { type: this.updateGraphQLPKType, value: this.getUpdateModelKeys(plainData), required: true },
|
|
3104
3355
|
})];
|
|
3105
3356
|
case 1:
|
|
3106
|
-
|
|
3357
|
+
_b.sent();
|
|
3107
3358
|
return [2 /*return*/, this.model.toInstance(plainData)];
|
|
3108
3359
|
}
|
|
3109
3360
|
});
|
|
@@ -3114,14 +3365,21 @@
|
|
|
3114
3365
|
if (model.isModel(params))
|
|
3115
3366
|
return params.toPlain();
|
|
3116
3367
|
return Object.keys(params).reduce(function (data, currentKey) {
|
|
3117
|
-
var
|
|
3118
|
-
return (Object.assign(Object.assign({}, data), (
|
|
3368
|
+
var _b;
|
|
3369
|
+
return (Object.assign(Object.assign({}, data), (params[currentKey] !== undefined && (_b = {}, _b[currentKey] = getValueByAction(params[currentKey]), _b))));
|
|
3119
3370
|
}, {});
|
|
3120
3371
|
};
|
|
3121
3372
|
UpdateHasuraGraphQLMixin.prototype.getUpdateModelKeys = function (data) {
|
|
3122
|
-
|
|
3373
|
+
var _this = this;
|
|
3374
|
+
var instance = this.model.toInstance(data);
|
|
3375
|
+
return this.model.identifiersFields.reduce(function (ids, identifier) {
|
|
3376
|
+
var _b;
|
|
3123
3377
|
var _a;
|
|
3124
|
-
|
|
3378
|
+
if (lodash.isNil(instance[identifier]))
|
|
3379
|
+
return ids;
|
|
3380
|
+
var columnOption = AttributeOptionHelper.FindByAttribute(identifier, _this.fields);
|
|
3381
|
+
var value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, data[identifier.toString()], instance)) || data[columnOption.attributeName];
|
|
3382
|
+
return Object.assign(Object.assign({}, ids), (_b = {}, _b[columnOption.columnName] = value, _b));
|
|
3125
3383
|
}, {});
|
|
3126
3384
|
};
|
|
3127
3385
|
return UpdateHasuraGraphQLMixin;
|
|
@@ -3146,24 +3404,25 @@
|
|
|
3146
3404
|
return __awaiter(this, void 0, void 0, function () {
|
|
3147
3405
|
var instance, result, data;
|
|
3148
3406
|
var _this = this;
|
|
3149
|
-
return __generator(this, function (
|
|
3150
|
-
switch (
|
|
3407
|
+
return __generator(this, function (_b) {
|
|
3408
|
+
switch (_b.label) {
|
|
3151
3409
|
case 0:
|
|
3152
3410
|
instance = this.model.toInstance(identifiers);
|
|
3153
3411
|
return [4 /*yield*/, this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce(function (ids, identifier) {
|
|
3412
|
+
var _b;
|
|
3154
3413
|
var _a;
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3414
|
+
if (lodash.isNil(instance[identifier]))
|
|
3415
|
+
return ids;
|
|
3416
|
+
var columnOption = AttributeOptionHelper.FindByAttribute(identifier, _this.fields);
|
|
3417
|
+
var 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()];
|
|
3418
|
+
return Object.assign(Object.assign({}, ids), (_b = {}, _b[columnOption.columnName] = {
|
|
3419
|
+
type: _this.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3420
|
+
value: value,
|
|
3421
|
+
required: true,
|
|
3422
|
+
}, _b));
|
|
3164
3423
|
}, {}))];
|
|
3165
3424
|
case 1:
|
|
3166
|
-
result =
|
|
3425
|
+
result = _b.sent();
|
|
3167
3426
|
data = result[this.getGraphQLOperation];
|
|
3168
3427
|
if (lodash.isNil(data))
|
|
3169
3428
|
throw new NotFoundError(instance.constructor.name + " not found");
|
|
@@ -3205,60 +3464,53 @@
|
|
|
3205
3464
|
})(HasuraGraphQLColumnType || (HasuraGraphQLColumnType = {}));
|
|
3206
3465
|
|
|
3207
3466
|
var withFindHasuraGraphQL = function (MixinBase) {
|
|
3208
|
-
var checkIfIsFilterOption = function (filter) { return !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator); };
|
|
3209
|
-
var getValueFromFilter = function (filter, fieldOption) {
|
|
3210
|
-
if (!checkIfIsFilterOption(filter))
|
|
3211
|
-
return filter;
|
|
3212
|
-
if (filter.operator === exports.Where.ISNULL)
|
|
3213
|
-
return true;
|
|
3214
|
-
if (filter.operator === exports.Where.ISNOTNULL)
|
|
3215
|
-
return false;
|
|
3216
|
-
var converter = fieldOption.to ? fieldOption.to : function (value) { return value; };
|
|
3217
|
-
return Array.isArray(filter.value) && [exports.Where.IN, exports.Where.NOTIN].includes(filter.operator)
|
|
3218
|
-
? filter.value.map(function (fieldValue) { return converter(fieldValue); })
|
|
3219
|
-
: converter(filter.value);
|
|
3220
|
-
};
|
|
3221
3467
|
return /** @class */ (function (_super) {
|
|
3222
3468
|
__extends(FindHasuraGraphQLMixin, _super);
|
|
3223
3469
|
function FindHasuraGraphQLMixin() {
|
|
3224
3470
|
var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
|
|
3225
3471
|
_this.makeGraphQLWhere = function (filter, fields) { return Object.keys(filter).reduce(function (variables, fieldName) {
|
|
3226
|
-
var
|
|
3227
|
-
|
|
3228
|
-
|
|
3472
|
+
var _b;
|
|
3473
|
+
var columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
|
|
3474
|
+
if (!columnOption.bindFindFilter)
|
|
3475
|
+
return Object.assign(Object.assign({}, variables), (_b = {}, _b[columnOption.columnName] = _this.buildWhereSentence(fieldName, filter[fieldName], fields), _b));
|
|
3476
|
+
var builtFilter = columnOption.bindFindFilter(filter[fieldName]);
|
|
3477
|
+
return Object.assign(Object.assign({}, variables), Object.keys(builtFilter).reduce(function (variablesList, columnName) {
|
|
3478
|
+
var _b;
|
|
3479
|
+
return (Object.assign(Object.assign({}, variablesList), (_b = {}, _b[columnName] = _this.buildWhereSentence(fieldName, builtFilter[columnName], fields), _b)));
|
|
3480
|
+
}, {}));
|
|
3229
3481
|
}, {}); };
|
|
3230
3482
|
_this.buildWhereSentence = function (field, options, fields) {
|
|
3231
|
-
var
|
|
3232
|
-
var fieldSentenceOptions = AttributeOptionHelper.
|
|
3483
|
+
var _b;
|
|
3484
|
+
var fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
3233
3485
|
if (!Array.isArray(options) &&
|
|
3234
3486
|
lodash.isObject(options) &&
|
|
3235
3487
|
lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) &&
|
|
3236
3488
|
lodash.isNil(options === null || options === void 0 ? void 0 : options.value) &&
|
|
3237
3489
|
lodash.isNil(fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.to))
|
|
3238
3490
|
return Object.keys(options).reduce(function (variables, key) {
|
|
3239
|
-
var
|
|
3240
|
-
var fieldOptions = AttributeOptionHelper.
|
|
3491
|
+
var _b;
|
|
3492
|
+
var fieldOptions = AttributeOptionHelper.FindByAttribute(key, (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || fields);
|
|
3241
3493
|
var columnName = fieldOptions.columnName;
|
|
3242
3494
|
var columnFields = fieldOptions.fields;
|
|
3243
|
-
return Object.assign(Object.assign({}, variables), (
|
|
3495
|
+
return Object.assign(Object.assign({}, variables), (_b = {}, _b[columnName] = _this.buildWhereSentence(key, options[key], columnFields || []), _b));
|
|
3244
3496
|
}, {});
|
|
3245
3497
|
if (!Array.isArray(options) && !lodash.isNil(fieldSentenceOptions.fields))
|
|
3246
|
-
return
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
if (lodash.isObject(options) && !
|
|
3498
|
+
return _b = {},
|
|
3499
|
+
_b[fieldSentenceOptions.fields[0]] = _this.buildOperatorSentence(options, fieldSentenceOptions),
|
|
3500
|
+
_b;
|
|
3501
|
+
if (lodash.isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
3250
3502
|
options = Object.values(options)[0];
|
|
3251
3503
|
return Array.isArray(options)
|
|
3252
3504
|
? options.reduce(function (whereSentence, option) { return (Object.assign(Object.assign({}, whereSentence), _this.buildOperatorSentence(option, fieldSentenceOptions))); }, {})
|
|
3253
3505
|
: _this.buildOperatorSentence(options, fieldSentenceOptions);
|
|
3254
3506
|
};
|
|
3255
3507
|
_this.buildOperatorSentence = function (options, fieldOption) {
|
|
3256
|
-
var
|
|
3257
|
-
return (
|
|
3258
|
-
|
|
3259
|
-
|
|
3508
|
+
var _b;
|
|
3509
|
+
return (_b = {},
|
|
3510
|
+
_b[_this.getHasuraOperator(options, fieldOption)] = FilterOptionHelper.GetValueFromFilter(options, fieldOption),
|
|
3511
|
+
_b);
|
|
3260
3512
|
};
|
|
3261
|
-
_this.getHasuraOperator = function (options, fieldOption) { return
|
|
3513
|
+
_this.getHasuraOperator = function (options, fieldOption) { return FilterOptionHelper.CheckIfIsFilterOption(options)
|
|
3262
3514
|
? fieldOption.type === HasuraGraphQLColumnType.Jsonb
|
|
3263
3515
|
? _this.getHasuraJsonbOperator(options)
|
|
3264
3516
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find(function (graphQLOperator) { return graphQLOperator === Object.keys(exports.Where).find(function (operator) { return exports.Where[operator] === (options === null || options === void 0 ? void 0 : options.operator); }); })]
|
|
@@ -3272,12 +3524,12 @@
|
|
|
3272
3524
|
}
|
|
3273
3525
|
FindHasuraGraphQLMixin.prototype.find = function (options) {
|
|
3274
3526
|
return __awaiter(this, void 0, void 0, function () {
|
|
3275
|
-
var
|
|
3527
|
+
var _b, filters, limits, orderBy, variablesCount, variables, result, data, count;
|
|
3276
3528
|
var _this = this;
|
|
3277
|
-
return __generator(this, function (
|
|
3278
|
-
switch (
|
|
3529
|
+
return __generator(this, function (_c) {
|
|
3530
|
+
switch (_c.label) {
|
|
3279
3531
|
case 0:
|
|
3280
|
-
|
|
3532
|
+
_b = options || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
|
|
3281
3533
|
variablesCount = Object.assign(Object.assign({}, (lodash.isNil(orderBy) ? {} : { order_by: { type: this.tableName + "_order_by!", list: true, value: orderBy } })), (lodash.isNil(filters)
|
|
3282
3534
|
? {}
|
|
3283
3535
|
: {
|
|
@@ -3288,11 +3540,17 @@
|
|
|
3288
3540
|
},
|
|
3289
3541
|
}));
|
|
3290
3542
|
variables = Object.assign(Object.assign({}, (lodash.isNil(limits) ? {} : limits)), variablesCount);
|
|
3291
|
-
console.log(JSON.stringify(variables));
|
|
3292
3543
|
return [4 /*yield*/, this.query([
|
|
3293
3544
|
{
|
|
3294
3545
|
operation: this.tableName,
|
|
3295
|
-
fields:
|
|
3546
|
+
fields: options.fields
|
|
3547
|
+
? options.fields
|
|
3548
|
+
.map(function (fieldName) {
|
|
3549
|
+
var _a;
|
|
3550
|
+
return (_a = _this.fields.find(function (fieldOption) { return fieldOption === fieldName; })) !== null && _a !== void 0 ? _a : _this.fields.find(function (fieldOption) { return Object.keys(fieldOption).shift() === fieldName; });
|
|
3551
|
+
})
|
|
3552
|
+
.filter(Boolean)
|
|
3553
|
+
: this.fields,
|
|
3296
3554
|
variables: variables,
|
|
3297
3555
|
},
|
|
3298
3556
|
{
|
|
@@ -3302,8 +3560,8 @@
|
|
|
3302
3560
|
},
|
|
3303
3561
|
])];
|
|
3304
3562
|
case 1:
|
|
3305
|
-
result =
|
|
3306
|
-
data = result[this.tableName].map(function (
|
|
3563
|
+
result = _c.sent();
|
|
3564
|
+
data = result[this.tableName].map(function (row) { return _this.convertDataFromHasura(row); });
|
|
3307
3565
|
count = result[this.tableName + "_aggregate"].aggregate.count;
|
|
3308
3566
|
return [2 /*return*/, { count: count, data: data }];
|
|
3309
3567
|
}
|
|
@@ -3324,32 +3582,90 @@
|
|
|
3324
3582
|
}(withUpdateHasuraGraphQL(withGetHasuraGraphQL(withFindHasuraGraphQL(withDeleteHasuraGraphQL(withCreateHasuraGraphQL(MixinBase)))))));
|
|
3325
3583
|
};
|
|
3326
3584
|
|
|
3327
|
-
var
|
|
3328
|
-
__extends(
|
|
3329
|
-
function
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3585
|
+
var CategoryHasuraGraphQL = /** @class */ (function (_super) {
|
|
3586
|
+
__extends(CategoryHasuraGraphQL, _super);
|
|
3587
|
+
function CategoryHasuraGraphQL() {
|
|
3588
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
3589
|
+
}
|
|
3590
|
+
return CategoryHasuraGraphQL;
|
|
3591
|
+
}(Category));
|
|
3592
|
+
|
|
3593
|
+
var ProductHasuraGraphQL = /** @class */ (function (_super) {
|
|
3594
|
+
__extends(ProductHasuraGraphQL, _super);
|
|
3595
|
+
function ProductHasuraGraphQL() {
|
|
3596
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
3597
|
+
}
|
|
3598
|
+
return ProductHasuraGraphQL;
|
|
3599
|
+
}(Product));
|
|
3600
|
+
__decorate([
|
|
3601
|
+
classTransformer.Type(function () { return KitProductHasuraGraphQL; }),
|
|
3602
|
+
__metadata("design:type", Array)
|
|
3603
|
+
], ProductHasuraGraphQL.prototype, "kitProducts", void 0);
|
|
3604
|
+
|
|
3605
|
+
var KitProductHasuraGraphQL = /** @class */ (function (_super) {
|
|
3606
|
+
__extends(KitProductHasuraGraphQL, _super);
|
|
3607
|
+
function KitProductHasuraGraphQL() {
|
|
3608
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
3609
|
+
}
|
|
3610
|
+
return KitProductHasuraGraphQL;
|
|
3611
|
+
}(KitProduct));
|
|
3612
|
+
__decorate([
|
|
3613
|
+
classTransformer.Type(function () { return ProductHasuraGraphQL; }),
|
|
3614
|
+
__metadata("design:type", ProductHasuraGraphQL)
|
|
3615
|
+
], KitProductHasuraGraphQL.prototype, "kit", void 0);
|
|
3616
|
+
__decorate([
|
|
3617
|
+
classTransformer.Type(function () { return ProductHasuraGraphQL; }),
|
|
3618
|
+
__metadata("design:type", ProductHasuraGraphQL)
|
|
3619
|
+
], KitProductHasuraGraphQL.prototype, "product", void 0);
|
|
3620
|
+
|
|
3621
|
+
var VariantHasuraGraphQL = /** @class */ (function (_super) {
|
|
3622
|
+
__extends(VariantHasuraGraphQL, _super);
|
|
3623
|
+
function VariantHasuraGraphQL() {
|
|
3624
|
+
var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
|
|
3625
|
+
_this.name = '';
|
|
3626
|
+
_this.hasVariants = false;
|
|
3627
|
+
return _this;
|
|
3628
|
+
}
|
|
3629
|
+
return VariantHasuraGraphQL;
|
|
3630
|
+
}(Variant));
|
|
3631
|
+
|
|
3632
|
+
var CategoryHasuraGraphQLRepository = /** @class */ (function (_super_1) {
|
|
3633
|
+
__extends(CategoryHasuraGraphQLRepository, _super_1);
|
|
3634
|
+
function CategoryHasuraGraphQLRepository(endpoint, authOptions, productRepository) {
|
|
3635
|
+
var _this = _super_1.call(this, {
|
|
3636
|
+
tableName: 'category',
|
|
3637
|
+
model: Category,
|
|
3638
|
+
endpoint: endpoint,
|
|
3639
|
+
authOptions: authOptions,
|
|
3640
|
+
fields: [
|
|
3641
|
+
{ id: { columnName: 'id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
|
|
3642
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
3643
|
+
'name',
|
|
3644
|
+
'description',
|
|
3645
|
+
'image',
|
|
3646
|
+
'published',
|
|
3647
|
+
'shop',
|
|
3648
|
+
'slug',
|
|
3344
3649
|
{ brandCategory: { columnName: 'brand_category' } },
|
|
3345
3650
|
{ brandCategoryBanner: { columnName: 'brand_banner' } },
|
|
3346
3651
|
{ brandCategoryBannerMobile: { columnName: 'brand_banner_mobile' } },
|
|
3347
3652
|
{ brandLogo: { columnName: 'brand_logo' } },
|
|
3348
|
-
{
|
|
3653
|
+
{ brandCondition: { columnName: 'brand_condition' } },
|
|
3349
3654
|
{
|
|
3350
3655
|
conditions: {
|
|
3351
3656
|
columnName: 'tag_condition',
|
|
3352
|
-
|
|
3657
|
+
type: HasuraGraphQLColumnType.Jsonb,
|
|
3658
|
+
from: function (tags, row) { return ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }); },
|
|
3659
|
+
bindPersistData: function (value) {
|
|
3660
|
+
var _a, _b;
|
|
3661
|
+
return {
|
|
3662
|
+
brand_condition: value.brand,
|
|
3663
|
+
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, '","')) || '') + "\"}",
|
|
3664
|
+
};
|
|
3665
|
+
},
|
|
3666
|
+
bindFindFilter: function (sentence) {
|
|
3667
|
+
return Object.assign(Object.assign({}, (sentence.brand ? { brand_condition: sentence.brand } : {})), (sentence.tags ? { tag_condition: sentence.tags } : {}));
|
|
3668
|
+
},
|
|
3353
3669
|
},
|
|
3354
3670
|
},
|
|
3355
3671
|
'filters',
|
|
@@ -3360,6 +3676,9 @@
|
|
|
3360
3676
|
columnName: 'products',
|
|
3361
3677
|
fields: ['product_id'],
|
|
3362
3678
|
from: function (value) { return value.map(function (product) { return product.product_id.toString(); }); },
|
|
3679
|
+
to: function (productIds) { return productIds.map(function (productId) { return ({
|
|
3680
|
+
product_id: +productId,
|
|
3681
|
+
}); }); },
|
|
3363
3682
|
},
|
|
3364
3683
|
},
|
|
3365
3684
|
],
|
|
@@ -3373,34 +3692,34 @@
|
|
|
3373
3692
|
});
|
|
3374
3693
|
var _a;
|
|
3375
3694
|
return __awaiter(this, void 0, void 0, function () {
|
|
3376
|
-
var
|
|
3377
|
-
return __generator(this, function (
|
|
3378
|
-
switch (
|
|
3695
|
+
var _c;
|
|
3696
|
+
return __generator(this, function (_d) {
|
|
3697
|
+
switch (_d.label) {
|
|
3379
3698
|
case 0:
|
|
3380
3699
|
if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
|
|
3381
|
-
return [4 /*yield*/, this.find({ filters: {
|
|
3700
|
+
return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
|
|
3382
3701
|
case 1:
|
|
3383
|
-
|
|
3702
|
+
_c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
|
|
3384
3703
|
return [3 /*break*/, 3];
|
|
3385
3704
|
case 2:
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
case 3: return [2 /*return*/,
|
|
3705
|
+
_c = _super.get.call(this, identifiers);
|
|
3706
|
+
_d.label = 3;
|
|
3707
|
+
case 3: return [2 /*return*/, _c];
|
|
3389
3708
|
}
|
|
3390
3709
|
});
|
|
3391
3710
|
});
|
|
3392
3711
|
};
|
|
3393
3712
|
CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
|
|
3394
3713
|
return __awaiter(this, void 0, void 0, function () {
|
|
3395
|
-
var
|
|
3396
|
-
return __generator(this, function (
|
|
3397
|
-
switch (
|
|
3714
|
+
var _c, data, count;
|
|
3715
|
+
return __generator(this, function (_d) {
|
|
3716
|
+
switch (_d.label) {
|
|
3398
3717
|
case 0:
|
|
3399
3718
|
if (!slug)
|
|
3400
3719
|
return [2 /*return*/];
|
|
3401
3720
|
return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
|
|
3402
3721
|
case 1:
|
|
3403
|
-
|
|
3722
|
+
_c = _d.sent(), data = _c.data, count = _c.count;
|
|
3404
3723
|
if (count > 1)
|
|
3405
3724
|
throw new DuplicatedResultsError('Query returned duplicated values');
|
|
3406
3725
|
if (!count)
|
|
@@ -3413,33 +3732,33 @@
|
|
|
3413
3732
|
CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
|
|
3414
3733
|
if (limit === void 0) { limit = 4; }
|
|
3415
3734
|
return __awaiter(this, void 0, void 0, function () {
|
|
3416
|
-
var
|
|
3735
|
+
var _c, categories, count, homeSections;
|
|
3417
3736
|
var _this = this;
|
|
3418
|
-
return __generator(this, function (
|
|
3419
|
-
switch (
|
|
3737
|
+
return __generator(this, function (_d) {
|
|
3738
|
+
switch (_d.label) {
|
|
3420
3739
|
case 0: return [4 /*yield*/, this.find({
|
|
3421
|
-
filters: {
|
|
3740
|
+
filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
|
|
3422
3741
|
})];
|
|
3423
3742
|
case 1:
|
|
3424
|
-
|
|
3743
|
+
_c = _d.sent(), categories = _c.data, count = _c.count;
|
|
3425
3744
|
if (!count)
|
|
3426
3745
|
throw new NotFoundError('Categories not found');
|
|
3427
3746
|
return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
3428
|
-
var
|
|
3429
|
-
return __generator(this, function (
|
|
3430
|
-
switch (
|
|
3747
|
+
var _c;
|
|
3748
|
+
return __generator(this, function (_d) {
|
|
3749
|
+
switch (_d.label) {
|
|
3431
3750
|
case 0:
|
|
3432
|
-
|
|
3751
|
+
_c = {
|
|
3433
3752
|
category: category
|
|
3434
3753
|
};
|
|
3435
3754
|
return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
|
|
3436
|
-
case 1: return [2 /*return*/, (
|
|
3437
|
-
|
|
3755
|
+
case 1: return [2 /*return*/, (_c.products = _d.sent(),
|
|
3756
|
+
_c)];
|
|
3438
3757
|
}
|
|
3439
3758
|
});
|
|
3440
3759
|
}); }))];
|
|
3441
3760
|
case 2:
|
|
3442
|
-
homeSections =
|
|
3761
|
+
homeSections = _d.sent();
|
|
3443
3762
|
return [2 /*return*/, homeSections];
|
|
3444
3763
|
}
|
|
3445
3764
|
});
|
|
@@ -3448,23 +3767,40 @@
|
|
|
3448
3767
|
CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
|
|
3449
3768
|
return __awaiter(this, void 0, void 0, function () {
|
|
3450
3769
|
var products, publishedField, productsData;
|
|
3451
|
-
var
|
|
3452
|
-
return __generator(this, function (
|
|
3453
|
-
switch (
|
|
3770
|
+
var _c;
|
|
3771
|
+
return __generator(this, function (_d) {
|
|
3772
|
+
switch (_d.label) {
|
|
3454
3773
|
case 0:
|
|
3455
3774
|
if (!category.products)
|
|
3456
3775
|
throw new RequiredArgumentError(['Category products is empty']);
|
|
3457
|
-
console.log(category);
|
|
3458
|
-
console.log(category.products);
|
|
3459
3776
|
products = [];
|
|
3460
3777
|
publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
|
|
3461
|
-
return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: (
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3778
|
+
return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign((_c = { id: { operator: exports.Where.IN, value: category.products } }, _c[publishedField] = true, _c), ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
|
|
3779
|
+
'id',
|
|
3780
|
+
'name',
|
|
3781
|
+
'slug',
|
|
3782
|
+
'images',
|
|
3783
|
+
'miniatures',
|
|
3784
|
+
'price',
|
|
3785
|
+
'fullPrice',
|
|
3786
|
+
'subscriberDiscountPercentage',
|
|
3787
|
+
'subscriberPrice',
|
|
3788
|
+
'stock',
|
|
3789
|
+
'published',
|
|
3790
|
+
'publishedGlam',
|
|
3791
|
+
'CEST',
|
|
3792
|
+
'EAN',
|
|
3793
|
+
'NCM',
|
|
3794
|
+
'brand',
|
|
3795
|
+
'costPrice',
|
|
3796
|
+
'hasVariants',
|
|
3797
|
+
'isKit',
|
|
3798
|
+
'shopAvailability',
|
|
3799
|
+
'sku',
|
|
3800
|
+
'rate',
|
|
3801
|
+
] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
|
|
3466
3802
|
case 1:
|
|
3467
|
-
productsData = (
|
|
3803
|
+
productsData = (_d.sent()).data;
|
|
3468
3804
|
products.push.apply(products, __spreadArray([], __read(productsData)));
|
|
3469
3805
|
return [2 /*return*/, products];
|
|
3470
3806
|
}
|
|
@@ -3474,97 +3810,695 @@
|
|
|
3474
3810
|
return CategoryHasuraGraphQLRepository;
|
|
3475
3811
|
}(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
|
|
3476
3812
|
|
|
3477
|
-
var ProductHasuraGraphQLRepository = /** @class */ (function (
|
|
3478
|
-
__extends(ProductHasuraGraphQLRepository,
|
|
3813
|
+
var ProductHasuraGraphQLRepository = /** @class */ (function (_super_1) {
|
|
3814
|
+
__extends(ProductHasuraGraphQLRepository, _super_1);
|
|
3479
3815
|
function ProductHasuraGraphQLRepository(endpoint, authOptions) {
|
|
3480
|
-
|
|
3816
|
+
var _this = _super_1.call(this, {
|
|
3481
3817
|
tableName: 'product',
|
|
3482
|
-
model:
|
|
3818
|
+
model: ProductHasuraGraphQL,
|
|
3819
|
+
endpoint: endpoint,
|
|
3820
|
+
authOptions: authOptions,
|
|
3821
|
+
fields: [],
|
|
3822
|
+
}) || this;
|
|
3823
|
+
_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 })); };
|
|
3824
|
+
_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 })); };
|
|
3825
|
+
var commonFields = [
|
|
3826
|
+
{ id: { columnName: 'id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
|
|
3827
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
3828
|
+
{ CEST: { columnName: 'cest' } },
|
|
3829
|
+
{ EAN: { columnName: 'ean' } },
|
|
3830
|
+
{ NCM: { columnName: 'ncm' } },
|
|
3831
|
+
'brand',
|
|
3832
|
+
{ costPrice: { columnName: 'cost_price' } },
|
|
3833
|
+
{
|
|
3834
|
+
description: {
|
|
3835
|
+
columnName: 'description',
|
|
3836
|
+
from: function (description) { return Object.values(exports.Shops).reduce(function (shops, shop) {
|
|
3837
|
+
var _c;
|
|
3838
|
+
return (Object.assign(Object.assign({}, shops), (_c = {}, _c[shop] = { description: description }, _c)));
|
|
3839
|
+
}, {}); },
|
|
3840
|
+
to: function (value) { return Object.values(value).shift().description; },
|
|
3841
|
+
},
|
|
3842
|
+
},
|
|
3843
|
+
{ hasVariants: { columnName: 'has_variants' } },
|
|
3844
|
+
{ images: { columnName: 'images', to: function (value) { var _a; return "{\"" + (((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, "\",\"")) || '') + "\"}"; } } },
|
|
3845
|
+
{ miniatures: { columnName: 'miniatures', to: function (value) { var _a; return "{\"" + (((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, "\",\"")) || '') + "\"}"; } } },
|
|
3846
|
+
'name',
|
|
3847
|
+
{
|
|
3848
|
+
price: {
|
|
3849
|
+
columnName: 'price',
|
|
3850
|
+
from: function (price, data) { return Object.values(exports.Shops).reduce(function (prices, shop) {
|
|
3851
|
+
var _c;
|
|
3852
|
+
return (Object.assign(Object.assign({}, prices), (_c = {}, _c[shop] = {
|
|
3853
|
+
price: price,
|
|
3854
|
+
fullPrice: data.full_price,
|
|
3855
|
+
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
3856
|
+
subscriberPrice: data.subscriber_price,
|
|
3857
|
+
}, _c)));
|
|
3858
|
+
}, {}); },
|
|
3859
|
+
bindFindFilter: function (sentence) {
|
|
3860
|
+
var filters = Object.values(sentence).shift();
|
|
3861
|
+
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) && {
|
|
3862
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
3863
|
+
})), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
3864
|
+
subscriber_price: filters.subscriberPrice,
|
|
3865
|
+
}));
|
|
3866
|
+
},
|
|
3867
|
+
bindPersistData: function (value) {
|
|
3868
|
+
var priceData = Object.values(value).shift();
|
|
3869
|
+
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 && {
|
|
3870
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
3871
|
+
})), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }));
|
|
3872
|
+
},
|
|
3873
|
+
},
|
|
3874
|
+
},
|
|
3875
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
3876
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
3877
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
3878
|
+
'published',
|
|
3879
|
+
{ publishedGlam: { columnName: 'published_glam' } },
|
|
3880
|
+
'sku',
|
|
3881
|
+
{
|
|
3882
|
+
stock: {
|
|
3883
|
+
columnName: 'stock',
|
|
3884
|
+
from: function (quantity) { return ({ quantity: quantity }); },
|
|
3885
|
+
to: function (value) { return (lodash.isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity); },
|
|
3886
|
+
},
|
|
3887
|
+
},
|
|
3888
|
+
'slug',
|
|
3889
|
+
'type',
|
|
3890
|
+
'video',
|
|
3891
|
+
'weight',
|
|
3892
|
+
{
|
|
3893
|
+
shopAvailability: {
|
|
3894
|
+
columnName: 'shop_availabilities',
|
|
3895
|
+
fields: ['shop'],
|
|
3896
|
+
from: function (shop) { return (Array.isArray(shop) ? shop.map(function (row) { return row.shop; }) : []); },
|
|
3897
|
+
bindPersistData: function (shops) { return ({ shop_availabilities: { data: shops.map(function (shop) { return ({ shop: shop }); }) } }); },
|
|
3898
|
+
},
|
|
3899
|
+
},
|
|
3900
|
+
{ tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
3901
|
+
{ isKit: { columnName: 'is_kit' } },
|
|
3902
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
3903
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
3904
|
+
{
|
|
3905
|
+
rate: {
|
|
3906
|
+
columnName: 'reviews_aggregate',
|
|
3907
|
+
fields: [{ aggregate: [{ avg: ['rate'] }] }],
|
|
3908
|
+
from: function (value) { return value.aggregate.avg.rate; },
|
|
3909
|
+
},
|
|
3910
|
+
},
|
|
3911
|
+
];
|
|
3912
|
+
_this.fields = __spreadArray(__spreadArray([], __read(commonFields)), [
|
|
3913
|
+
{
|
|
3914
|
+
categories: {
|
|
3915
|
+
columnName: 'categories',
|
|
3916
|
+
fields: ['category_id'],
|
|
3917
|
+
bindPersistData: function (value) { return ({
|
|
3918
|
+
categories: { data: value.map(function (category) { return ({ category_id: +category }); }) },
|
|
3919
|
+
}); },
|
|
3920
|
+
to: function (categories) { return categories.map(function (categoryId) { return +categoryId; }); },
|
|
3921
|
+
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(); })) || []; },
|
|
3922
|
+
},
|
|
3923
|
+
},
|
|
3924
|
+
{
|
|
3925
|
+
kitProducts: {
|
|
3926
|
+
columnName: 'kit_products',
|
|
3927
|
+
foreignKeyColumn: { productId: 'id' },
|
|
3928
|
+
fields: [
|
|
3929
|
+
{ productId: { columnName: 'product_id' } },
|
|
3930
|
+
{ kitProductId: { columnName: 'kit_product_id' } },
|
|
3931
|
+
'quantity',
|
|
3932
|
+
{ product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
|
|
3933
|
+
],
|
|
3934
|
+
},
|
|
3935
|
+
},
|
|
3936
|
+
]);
|
|
3937
|
+
return _this;
|
|
3938
|
+
}
|
|
3939
|
+
Object.defineProperty(ProductHasuraGraphQLRepository.prototype, "reviewsFields", {
|
|
3940
|
+
get: function () {
|
|
3941
|
+
return [
|
|
3942
|
+
'id',
|
|
3943
|
+
'shop',
|
|
3944
|
+
'rate',
|
|
3945
|
+
'author',
|
|
3946
|
+
'email',
|
|
3947
|
+
'location',
|
|
3948
|
+
'review',
|
|
3949
|
+
'status',
|
|
3950
|
+
'title',
|
|
3951
|
+
'person_id',
|
|
3952
|
+
'points',
|
|
3953
|
+
'order_id',
|
|
3954
|
+
'created_at',
|
|
3955
|
+
'updated_at',
|
|
3956
|
+
];
|
|
3957
|
+
},
|
|
3958
|
+
enumerable: false,
|
|
3959
|
+
configurable: true
|
|
3960
|
+
});
|
|
3961
|
+
ProductHasuraGraphQLRepository.prototype.create = function (data) {
|
|
3962
|
+
var _super = Object.create(null, {
|
|
3963
|
+
create: { get: function () { return _super_1.prototype.create; } }
|
|
3964
|
+
});
|
|
3965
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3966
|
+
var product, _c, error_1;
|
|
3967
|
+
return __generator(this, function (_d) {
|
|
3968
|
+
switch (_d.label) {
|
|
3969
|
+
case 0: return [4 /*yield*/, _super.create.call(this, lodash.omit(data, ['reviews']))];
|
|
3970
|
+
case 1:
|
|
3971
|
+
product = _d.sent();
|
|
3972
|
+
_d.label = 2;
|
|
3973
|
+
case 2:
|
|
3974
|
+
_d.trys.push([2, 4, , 6]);
|
|
3975
|
+
_c = product;
|
|
3976
|
+
return [4 /*yield*/, this.updateReviews(+product.id, data)];
|
|
3977
|
+
case 3:
|
|
3978
|
+
_c.reviews = _d.sent();
|
|
3979
|
+
return [3 /*break*/, 6];
|
|
3980
|
+
case 4:
|
|
3981
|
+
error_1 = _d.sent();
|
|
3982
|
+
return [4 /*yield*/, this.delete({ id: product.id })];
|
|
3983
|
+
case 5:
|
|
3984
|
+
_d.sent();
|
|
3985
|
+
throw error_1;
|
|
3986
|
+
case 6: return [2 /*return*/, product];
|
|
3987
|
+
}
|
|
3988
|
+
});
|
|
3989
|
+
});
|
|
3990
|
+
};
|
|
3991
|
+
ProductHasuraGraphQLRepository.prototype.get = function (identifiers) {
|
|
3992
|
+
var _super = Object.create(null, {
|
|
3993
|
+
get: { get: function () { return _super_1.prototype.get; } }
|
|
3994
|
+
});
|
|
3995
|
+
var _a;
|
|
3996
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3997
|
+
var product, _c, _d;
|
|
3998
|
+
return __generator(this, function (_e) {
|
|
3999
|
+
switch (_e.label) {
|
|
4000
|
+
case 0:
|
|
4001
|
+
if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
|
|
4002
|
+
return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
|
|
4003
|
+
case 1:
|
|
4004
|
+
_c = (_a = (_e.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
|
|
4005
|
+
return [3 /*break*/, 4];
|
|
4006
|
+
case 2: return [4 /*yield*/, _super.get.call(this, identifiers)];
|
|
4007
|
+
case 3:
|
|
4008
|
+
_c = _e.sent();
|
|
4009
|
+
_e.label = 4;
|
|
4010
|
+
case 4:
|
|
4011
|
+
product = _c;
|
|
4012
|
+
_d = product;
|
|
4013
|
+
return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
|
|
4014
|
+
case 5:
|
|
4015
|
+
_d.reviews = _e.sent();
|
|
4016
|
+
return [2 /*return*/, product];
|
|
4017
|
+
}
|
|
4018
|
+
});
|
|
4019
|
+
});
|
|
4020
|
+
};
|
|
4021
|
+
ProductHasuraGraphQLRepository.prototype.getBySlug = function (slug) {
|
|
4022
|
+
var _a;
|
|
4023
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4024
|
+
var result, product, _c;
|
|
4025
|
+
return __generator(this, function (_d) {
|
|
4026
|
+
switch (_d.label) {
|
|
4027
|
+
case 0: return [4 /*yield*/, this.find({
|
|
4028
|
+
filters: {
|
|
4029
|
+
slug: slug,
|
|
4030
|
+
},
|
|
4031
|
+
})];
|
|
4032
|
+
case 1:
|
|
4033
|
+
result = _d.sent();
|
|
4034
|
+
product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
|
|
4035
|
+
_c = product;
|
|
4036
|
+
return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
|
|
4037
|
+
case 2:
|
|
4038
|
+
_c.reviews = _d.sent();
|
|
4039
|
+
return [2 /*return*/, product];
|
|
4040
|
+
}
|
|
4041
|
+
});
|
|
4042
|
+
});
|
|
4043
|
+
};
|
|
4044
|
+
ProductHasuraGraphQLRepository.prototype.update = function (params) {
|
|
4045
|
+
var _super = Object.create(null, {
|
|
4046
|
+
update: { get: function () { return _super_1.prototype.update; } }
|
|
4047
|
+
});
|
|
4048
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4049
|
+
var categories, kitProducts, reviews, checkId, shopAvailability, rate, data, plainData, id, product, _c, _d, _e, _f, _g, _h;
|
|
4050
|
+
return __generator(this, function (_j) {
|
|
4051
|
+
switch (_j.label) {
|
|
4052
|
+
case 0:
|
|
4053
|
+
categories = params.categories, kitProducts = params.kitProducts, reviews = params.reviews, checkId = params.id, shopAvailability = params.shopAvailability, rate = params.rate, data = __rest(params, ["categories", "kitProducts", "reviews", "id", "shopAvailability", "rate"]);
|
|
4054
|
+
plainData = this.paramsToPlain({ id: checkId });
|
|
4055
|
+
return [4 /*yield*/, this.getId(plainData.id)];
|
|
4056
|
+
case 1:
|
|
4057
|
+
id = _j.sent();
|
|
4058
|
+
return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
|
|
4059
|
+
case 2:
|
|
4060
|
+
product = _j.sent();
|
|
4061
|
+
_c = product;
|
|
4062
|
+
_d = categories;
|
|
4063
|
+
if (!_d) return [3 /*break*/, 4];
|
|
4064
|
+
return [4 /*yield*/, this.updateCategories(+id, { categories: categories })];
|
|
4065
|
+
case 3:
|
|
4066
|
+
_d = (_j.sent());
|
|
4067
|
+
_j.label = 4;
|
|
4068
|
+
case 4:
|
|
4069
|
+
_c.categories = _d;
|
|
4070
|
+
_e = product;
|
|
4071
|
+
_f = kitProducts;
|
|
4072
|
+
if (!_f) return [3 /*break*/, 6];
|
|
4073
|
+
return [4 /*yield*/, this.updateKitProducts(+id, { kitProducts: kitProducts })];
|
|
4074
|
+
case 5:
|
|
4075
|
+
_f = (_j.sent());
|
|
4076
|
+
_j.label = 6;
|
|
4077
|
+
case 6:
|
|
4078
|
+
_e.kitProducts = _f;
|
|
4079
|
+
_g = product;
|
|
4080
|
+
_h = reviews;
|
|
4081
|
+
if (!_h) return [3 /*break*/, 8];
|
|
4082
|
+
return [4 /*yield*/, this.updateReviews(+id, { reviews: reviews })];
|
|
4083
|
+
case 7:
|
|
4084
|
+
_h = (_j.sent());
|
|
4085
|
+
_j.label = 8;
|
|
4086
|
+
case 8:
|
|
4087
|
+
_g.reviews = _h;
|
|
4088
|
+
return [2 /*return*/, product];
|
|
4089
|
+
}
|
|
4090
|
+
});
|
|
4091
|
+
});
|
|
4092
|
+
};
|
|
4093
|
+
ProductHasuraGraphQLRepository.prototype.fetchReviews = function (status) {
|
|
4094
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4095
|
+
var reviews, data;
|
|
4096
|
+
var _c, _d;
|
|
4097
|
+
var _this = this;
|
|
4098
|
+
return __generator(this, function (_e) {
|
|
4099
|
+
switch (_e.label) {
|
|
4100
|
+
case 0:
|
|
4101
|
+
reviews = {
|
|
4102
|
+
status: status === 'pending'
|
|
4103
|
+
? (_c = {}, _c[HasuraGraphQLWhere.ISNULL] = true, _c) : (_d = {}, _d[HasuraGraphQLWhere.EQUALS] = status === 'approved', _d),
|
|
4104
|
+
};
|
|
4105
|
+
return [4 /*yield*/, this.query('product', ['id', 'name', 'sku', { reviews: { columnName: 'reviews', fields: this.reviewsFields } }], {
|
|
4106
|
+
where: { value: { reviews: reviews }, type: 'product_bool_exp', required: true },
|
|
4107
|
+
})];
|
|
4108
|
+
case 1:
|
|
4109
|
+
data = (_e.sent()).product;
|
|
4110
|
+
return [2 /*return*/, data.reduce(function (reviews, product) { return __spreadArray(__spreadArray([], __read(reviews)), __read(product.reviews
|
|
4111
|
+
.filter(function (review) { return (status === 'pending' && [undefined, null].includes(review.status)) ||
|
|
4112
|
+
(status === 'approved' && review.status === true) ||
|
|
4113
|
+
(status === 'rejected' && review.status === false); })
|
|
4114
|
+
.map(function (review) { return (Object.assign(Object.assign({}, _this.bindReviewToModel(review)), { productId: product.id, productName: product.name, productSku: product.sku })); }))); }, [])];
|
|
4115
|
+
}
|
|
4116
|
+
});
|
|
4117
|
+
});
|
|
4118
|
+
};
|
|
4119
|
+
ProductHasuraGraphQLRepository.prototype.updateCategories = function (productId, _c) {
|
|
4120
|
+
var categories = _c.categories;
|
|
4121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4122
|
+
var plainData;
|
|
4123
|
+
return __generator(this, function (_c) {
|
|
4124
|
+
switch (_c.label) {
|
|
4125
|
+
case 0:
|
|
4126
|
+
plainData = this.paramsToPlain({ categories: categories });
|
|
4127
|
+
return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
|
|
4128
|
+
where: {
|
|
4129
|
+
type: 'category_product_bool_exp',
|
|
4130
|
+
required: true,
|
|
4131
|
+
value: { product_id: { _eq: productId } },
|
|
4132
|
+
},
|
|
4133
|
+
})];
|
|
4134
|
+
case 1:
|
|
4135
|
+
_c.sent();
|
|
4136
|
+
return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
|
|
4137
|
+
objects: {
|
|
4138
|
+
type: '[category_product_insert_input!]',
|
|
4139
|
+
required: true,
|
|
4140
|
+
value: plainData.categories.map(function (categoryId) { return ({ category_id: categoryId, product_id: productId }); }),
|
|
4141
|
+
},
|
|
4142
|
+
})];
|
|
4143
|
+
case 2:
|
|
4144
|
+
_c.sent();
|
|
4145
|
+
return [2 /*return*/, plainData.categories];
|
|
4146
|
+
}
|
|
4147
|
+
});
|
|
4148
|
+
});
|
|
4149
|
+
};
|
|
4150
|
+
ProductHasuraGraphQLRepository.prototype.updateKitProducts = function (productId, _c) {
|
|
4151
|
+
var kitProducts = _c.kitProducts;
|
|
4152
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4153
|
+
var plainData;
|
|
4154
|
+
return __generator(this, function (_c) {
|
|
4155
|
+
switch (_c.label) {
|
|
4156
|
+
case 0:
|
|
4157
|
+
plainData = this.paramsToPlain({ kitProducts: kitProducts });
|
|
4158
|
+
return [4 /*yield*/, this.mutation('delete_product_kit', ['affected_rows'], {
|
|
4159
|
+
where: {
|
|
4160
|
+
type: 'product_kit_bool_exp',
|
|
4161
|
+
required: true,
|
|
4162
|
+
value: { product_id: { _eq: productId } },
|
|
4163
|
+
},
|
|
4164
|
+
})];
|
|
4165
|
+
case 1:
|
|
4166
|
+
_c.sent();
|
|
4167
|
+
return [4 /*yield*/, this.mutation('insert_product_kit', ['affected_rows'], {
|
|
4168
|
+
objects: {
|
|
4169
|
+
type: '[product_kit_insert_input!]',
|
|
4170
|
+
required: true,
|
|
4171
|
+
value: plainData.kitProducts.map(function (kitProduct) { return ({
|
|
4172
|
+
kit_product_id: kitProduct.productId || kitProduct.product.id,
|
|
4173
|
+
product_id: productId,
|
|
4174
|
+
quantity: kitProduct.quantity,
|
|
4175
|
+
}); }),
|
|
4176
|
+
},
|
|
4177
|
+
})];
|
|
4178
|
+
case 2:
|
|
4179
|
+
_c.sent();
|
|
4180
|
+
return [2 /*return*/, plainData.kitProducts];
|
|
4181
|
+
}
|
|
4182
|
+
});
|
|
4183
|
+
});
|
|
4184
|
+
};
|
|
4185
|
+
ProductHasuraGraphQLRepository.prototype.updateReviews = function (productId, _c) {
|
|
4186
|
+
var reviews = _c.reviews;
|
|
4187
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4188
|
+
var reviewIds_1, plainData;
|
|
4189
|
+
var _this = this;
|
|
4190
|
+
return __generator(this, function (_c) {
|
|
4191
|
+
switch (_c.label) {
|
|
4192
|
+
case 0:
|
|
4193
|
+
if (!reviews)
|
|
4194
|
+
return [2 /*return*/, []];
|
|
4195
|
+
if (!('action' in reviews && reviews.action === 'remove')) return [3 /*break*/, 3];
|
|
4196
|
+
return [4 /*yield*/, Promise.all(reviews.value.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
|
|
4197
|
+
var review;
|
|
4198
|
+
return __generator(this, function (_c) {
|
|
4199
|
+
switch (_c.label) {
|
|
4200
|
+
case 0: return [4 /*yield*/, this.findReview(reviewData, productId)];
|
|
4201
|
+
case 1:
|
|
4202
|
+
review = _c.sent();
|
|
4203
|
+
return [2 /*return*/, review === null || review === void 0 ? void 0 : review.id];
|
|
4204
|
+
}
|
|
4205
|
+
});
|
|
4206
|
+
}); }))];
|
|
4207
|
+
case 1:
|
|
4208
|
+
reviewIds_1 = _c.sent();
|
|
4209
|
+
return [4 /*yield*/, this.mutation('delete_product_review', ['affected_rows'], {
|
|
4210
|
+
where: { value: { id: { _in: reviewIds_1.filter(Boolean) } }, type: 'product_review_bool_exp', required: true },
|
|
4211
|
+
})];
|
|
4212
|
+
case 2:
|
|
4213
|
+
_c.sent();
|
|
4214
|
+
return [2 /*return*/, reviews.value.map(function (review, index) { return !reviewIds_1[index] && review; }).filter(Boolean)];
|
|
4215
|
+
case 3:
|
|
4216
|
+
plainData = this.paramsToPlain({ reviews: reviews });
|
|
4217
|
+
return [2 /*return*/, Promise.all(plainData.reviews.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
|
|
4218
|
+
var review, _c, _d;
|
|
4219
|
+
return __generator(this, function (_e) {
|
|
4220
|
+
switch (_e.label) {
|
|
4221
|
+
case 0: return [4 /*yield*/, this.findReview(reviewData, productId)];
|
|
4222
|
+
case 1:
|
|
4223
|
+
review = _e.sent();
|
|
4224
|
+
if (!review.id) return [3 /*break*/, 3];
|
|
4225
|
+
_c = this.bindReviewToModel;
|
|
4226
|
+
return [4 /*yield*/, this.mutation('update_product_review_by_pk', this.reviewsFields, {
|
|
4227
|
+
pk_columns: {
|
|
4228
|
+
value: { id: review.id },
|
|
4229
|
+
type: 'product_review_pk_columns_input',
|
|
4230
|
+
required: true,
|
|
4231
|
+
},
|
|
4232
|
+
_set: {
|
|
4233
|
+
value: lodash.omit(this.bindReviewToHasura(reviewData), ['id', 'product_id']),
|
|
4234
|
+
type: 'product_review_set_input',
|
|
4235
|
+
required: true,
|
|
4236
|
+
},
|
|
4237
|
+
})];
|
|
4238
|
+
case 2: return [2 /*return*/, _c.apply(this, [(_e.sent()).update_product_review_by_pk])];
|
|
4239
|
+
case 3:
|
|
4240
|
+
_d = this.bindReviewToModel;
|
|
4241
|
+
return [4 /*yield*/, this.mutation('insert_product_review_one', this.reviewsFields, {
|
|
4242
|
+
object: {
|
|
4243
|
+
value: lodash.omit(Object.assign(Object.assign({}, this.bindReviewToHasura(reviewData)), { product_id: productId }), ['id']),
|
|
4244
|
+
type: 'product_review_insert_input',
|
|
4245
|
+
required: true,
|
|
4246
|
+
},
|
|
4247
|
+
})];
|
|
4248
|
+
case 4: return [2 /*return*/, _d.apply(this, [(_e.sent()).insert_product_review_one])];
|
|
4249
|
+
}
|
|
4250
|
+
});
|
|
4251
|
+
}); }))];
|
|
4252
|
+
}
|
|
4253
|
+
});
|
|
4254
|
+
});
|
|
4255
|
+
};
|
|
4256
|
+
ProductHasuraGraphQLRepository.prototype.getId = function (id) {
|
|
4257
|
+
var _a, _b;
|
|
4258
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4259
|
+
var data;
|
|
4260
|
+
return __generator(this, function (_c) {
|
|
4261
|
+
switch (_c.label) {
|
|
4262
|
+
case 0:
|
|
4263
|
+
if (!Number.isNaN(+id))
|
|
4264
|
+
return [2 /*return*/, id];
|
|
4265
|
+
return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
|
|
4266
|
+
case 1:
|
|
4267
|
+
data = (_c.sent()).data;
|
|
4268
|
+
if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
|
|
4269
|
+
return [2 /*return*/, (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id];
|
|
4270
|
+
throw new NotFoundError("Product with id " + id + " not found");
|
|
4271
|
+
}
|
|
4272
|
+
});
|
|
4273
|
+
});
|
|
4274
|
+
};
|
|
4275
|
+
ProductHasuraGraphQLRepository.prototype.findReviewsByProduct = function (productId) {
|
|
4276
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4277
|
+
var data;
|
|
4278
|
+
var _this = this;
|
|
4279
|
+
return __generator(this, function (_c) {
|
|
4280
|
+
switch (_c.label) {
|
|
4281
|
+
case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
|
|
4282
|
+
where: {
|
|
4283
|
+
value: {
|
|
4284
|
+
product_id: { _eq: productId },
|
|
4285
|
+
},
|
|
4286
|
+
type: 'product_review_bool_exp',
|
|
4287
|
+
required: true,
|
|
4288
|
+
},
|
|
4289
|
+
})];
|
|
4290
|
+
case 1:
|
|
4291
|
+
data = (_c.sent()).product_review;
|
|
4292
|
+
return [2 /*return*/, data && data.map(function (review) { return _this.bindReviewToModel(review); })];
|
|
4293
|
+
}
|
|
4294
|
+
});
|
|
4295
|
+
});
|
|
4296
|
+
};
|
|
4297
|
+
ProductHasuraGraphQLRepository.prototype.findReview = function (review, productId) {
|
|
4298
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4299
|
+
var loadedReview;
|
|
4300
|
+
return __generator(this, function (_c) {
|
|
4301
|
+
switch (_c.label) {
|
|
4302
|
+
case 0:
|
|
4303
|
+
if (review.id)
|
|
4304
|
+
return [2 /*return*/, review];
|
|
4305
|
+
if (!review.personId) return [3 /*break*/, 2];
|
|
4306
|
+
return [4 /*yield*/, this.getReviewByPersonId(review.personId, productId)];
|
|
4307
|
+
case 1:
|
|
4308
|
+
loadedReview = _c.sent();
|
|
4309
|
+
_c.label = 2;
|
|
4310
|
+
case 2:
|
|
4311
|
+
if (!(!loadedReview && review.author && review.email)) return [3 /*break*/, 4];
|
|
4312
|
+
return [4 /*yield*/, this.getReviewByAuthorAndEmail(review.author, review.email, productId)];
|
|
4313
|
+
case 3:
|
|
4314
|
+
loadedReview = _c.sent();
|
|
4315
|
+
_c.label = 4;
|
|
4316
|
+
case 4: return [2 /*return*/, loadedReview || review];
|
|
4317
|
+
}
|
|
4318
|
+
});
|
|
4319
|
+
});
|
|
4320
|
+
};
|
|
4321
|
+
ProductHasuraGraphQLRepository.prototype.getReviewByPersonId = function (personId, productId) {
|
|
4322
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4323
|
+
var data;
|
|
4324
|
+
return __generator(this, function (_c) {
|
|
4325
|
+
switch (_c.label) {
|
|
4326
|
+
case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
|
|
4327
|
+
where: {
|
|
4328
|
+
value: {
|
|
4329
|
+
product_id: { _eq: productId },
|
|
4330
|
+
person_id: { _eq: personId },
|
|
4331
|
+
},
|
|
4332
|
+
type: "product_review_bool_exp",
|
|
4333
|
+
required: true,
|
|
4334
|
+
},
|
|
4335
|
+
})];
|
|
4336
|
+
case 1:
|
|
4337
|
+
data = (_c.sent()).product_review;
|
|
4338
|
+
return [2 /*return*/, data && data[0] && this.bindReviewToModel(data[0])];
|
|
4339
|
+
}
|
|
4340
|
+
});
|
|
4341
|
+
});
|
|
4342
|
+
};
|
|
4343
|
+
ProductHasuraGraphQLRepository.prototype.getReviewByAuthorAndEmail = function (author, email, productId) {
|
|
4344
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4345
|
+
var data;
|
|
4346
|
+
return __generator(this, function (_c) {
|
|
4347
|
+
switch (_c.label) {
|
|
4348
|
+
case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
|
|
4349
|
+
where: {
|
|
4350
|
+
value: {
|
|
4351
|
+
product_id: { _eq: productId },
|
|
4352
|
+
author: { _eq: author },
|
|
4353
|
+
email: { _eq: email },
|
|
4354
|
+
},
|
|
4355
|
+
type: "product_review_bool_exp",
|
|
4356
|
+
required: true,
|
|
4357
|
+
},
|
|
4358
|
+
})];
|
|
4359
|
+
case 1:
|
|
4360
|
+
data = (_c.sent()).product_review;
|
|
4361
|
+
return [2 /*return*/, data && data[0] && this.bindReviewToModel(data[0])];
|
|
4362
|
+
}
|
|
4363
|
+
});
|
|
4364
|
+
});
|
|
4365
|
+
};
|
|
4366
|
+
return ProductHasuraGraphQLRepository;
|
|
4367
|
+
}(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
|
|
4368
|
+
|
|
4369
|
+
var VariantHasuraGraphQLRepository = /** @class */ (function (_super_1) {
|
|
4370
|
+
__extends(VariantHasuraGraphQLRepository, _super_1);
|
|
4371
|
+
function VariantHasuraGraphQLRepository(endpoint, authOptions) {
|
|
4372
|
+
return _super_1.call(this, {
|
|
4373
|
+
tableName: 'product',
|
|
4374
|
+
model: VariantHasuraGraphQL,
|
|
3483
4375
|
endpoint: endpoint,
|
|
3484
4376
|
authOptions: authOptions,
|
|
3485
4377
|
fields: [
|
|
3486
4378
|
{ id: { columnName: 'id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
|
|
3487
|
-
{
|
|
4379
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
4380
|
+
{ productId: { columnName: 'main_product_id', to: function (value) { return +value; }, from: function (value) { return value === null || value === void 0 ? void 0 : value.toString(); } } },
|
|
3488
4381
|
{ EAN: { columnName: 'ean' } },
|
|
3489
|
-
{ NCM: { columnName: 'ncm' } },
|
|
3490
|
-
'brand',
|
|
3491
4382
|
{ costPrice: { columnName: 'cost_price' } },
|
|
3492
|
-
'description',
|
|
3493
|
-
{ hasVariants: { columnName: 'has_variants' } },
|
|
3494
|
-
'images',
|
|
3495
|
-
'miniatures',
|
|
3496
|
-
'name',
|
|
3497
|
-
{ price: { columnName: 'full_price' } },
|
|
3498
|
-
{ price: { columnName: 'subscriber_discount_percentage' } },
|
|
3499
|
-
{ price: { columnName: 'subscriber_price' } },
|
|
3500
4383
|
{
|
|
3501
4384
|
price: {
|
|
3502
4385
|
columnName: 'price',
|
|
3503
4386
|
from: function (price, data) { return Object.values(exports.Shops).reduce(function (prices, shop) {
|
|
3504
|
-
var
|
|
3505
|
-
return (Object.assign(Object.assign({}, prices), (
|
|
4387
|
+
var _c;
|
|
4388
|
+
return (Object.assign(Object.assign({}, prices), (_c = {}, _c[shop] = {
|
|
3506
4389
|
price: price,
|
|
3507
4390
|
fullPrice: data.full_price,
|
|
3508
4391
|
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
3509
4392
|
subscriberPrice: data.subscriber_price,
|
|
3510
|
-
},
|
|
4393
|
+
}, _c)));
|
|
3511
4394
|
}, {}); },
|
|
4395
|
+
bindFindFilter: function (sentence) {
|
|
4396
|
+
var filters = Object.values(sentence).shift();
|
|
4397
|
+
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) && {
|
|
4398
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
4399
|
+
})), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
4400
|
+
subscriber_price: filters.subscriberPrice,
|
|
4401
|
+
}));
|
|
4402
|
+
},
|
|
4403
|
+
bindPersistData: function (value) {
|
|
4404
|
+
var priceData = Object.values(value).shift();
|
|
4405
|
+
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 && {
|
|
4406
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
4407
|
+
})), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }));
|
|
4408
|
+
},
|
|
3512
4409
|
},
|
|
3513
4410
|
},
|
|
3514
|
-
'
|
|
3515
|
-
{
|
|
4411
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
4412
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
4413
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
3516
4414
|
'sku',
|
|
3517
4415
|
{
|
|
3518
4416
|
stock: {
|
|
3519
4417
|
columnName: 'stock',
|
|
3520
4418
|
from: function (quantity) { return ({ quantity: quantity }); },
|
|
3521
|
-
to: function (value) { return (value === null || value === void 0 ? void 0 : value.quantity) || value; },
|
|
4419
|
+
to: function (value) { return (lodash.isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity); },
|
|
3522
4420
|
},
|
|
3523
4421
|
},
|
|
3524
|
-
'type',
|
|
3525
|
-
'video',
|
|
3526
4422
|
'weight',
|
|
4423
|
+
{ name: { to: function () { return ''; }, from: function () { return undefined; } } },
|
|
4424
|
+
{ hasVariants: { columnName: 'has_variants', to: function () { return false; }, from: function () { return undefined; } } },
|
|
4425
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
4426
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
3527
4427
|
{
|
|
3528
|
-
|
|
3529
|
-
columnName: '
|
|
3530
|
-
|
|
3531
|
-
to: function (category_id) { return +category_id; },
|
|
3532
|
-
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(); })) || []; },
|
|
3533
|
-
},
|
|
3534
|
-
},
|
|
3535
|
-
{
|
|
3536
|
-
shopAvailability: {
|
|
3537
|
-
columnName: 'shop_availabilities',
|
|
3538
|
-
fields: ['shop'],
|
|
3539
|
-
from: function (shop) { return (Array.isArray(shop) ? shop.map(function (row) { return row.shop; }) : []); },
|
|
4428
|
+
grade: {
|
|
4429
|
+
columnName: 'grade',
|
|
4430
|
+
type: HasuraGraphQLColumnType.Jsonb,
|
|
3540
4431
|
},
|
|
3541
4432
|
},
|
|
3542
|
-
{ tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
3543
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
3544
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
3545
4433
|
],
|
|
3546
4434
|
}) || this;
|
|
3547
4435
|
}
|
|
3548
|
-
|
|
4436
|
+
VariantHasuraGraphQLRepository.prototype.get = function (identifiers) {
|
|
4437
|
+
var _super = Object.create(null, {
|
|
4438
|
+
get: { get: function () { return _super_1.prototype.get; } }
|
|
4439
|
+
});
|
|
3549
4440
|
var _a;
|
|
3550
4441
|
return __awaiter(this, void 0, void 0, function () {
|
|
3551
|
-
var
|
|
3552
|
-
return __generator(this, function (
|
|
3553
|
-
switch (
|
|
3554
|
-
case 0:
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
shopAvailability: { operator: exports.Where.IN, value: [shop] },
|
|
3558
|
-
},
|
|
3559
|
-
})];
|
|
4442
|
+
var _c;
|
|
4443
|
+
return __generator(this, function (_d) {
|
|
4444
|
+
switch (_d.label) {
|
|
4445
|
+
case 0:
|
|
4446
|
+
if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
|
|
4447
|
+
return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
|
|
3560
4448
|
case 1:
|
|
3561
|
-
|
|
3562
|
-
return [
|
|
4449
|
+
_c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
|
|
4450
|
+
return [3 /*break*/, 3];
|
|
4451
|
+
case 2:
|
|
4452
|
+
_c = _super.get.call(this, identifiers);
|
|
4453
|
+
_d.label = 3;
|
|
4454
|
+
case 3: return [2 /*return*/, _c];
|
|
3563
4455
|
}
|
|
3564
4456
|
});
|
|
3565
4457
|
});
|
|
3566
4458
|
};
|
|
3567
|
-
|
|
4459
|
+
VariantHasuraGraphQLRepository.prototype.update = function (params) {
|
|
4460
|
+
var _super = Object.create(null, {
|
|
4461
|
+
update: { get: function () { return _super_1.prototype.update; } }
|
|
4462
|
+
});
|
|
4463
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4464
|
+
var productId, checkId, data, dataWithProductId, id, product;
|
|
4465
|
+
return __generator(this, function (_c) {
|
|
4466
|
+
switch (_c.label) {
|
|
4467
|
+
case 0:
|
|
4468
|
+
productId = params.productId, checkId = params.id, data = __rest(params, ["productId", "id"]);
|
|
4469
|
+
dataWithProductId = this.paramsToPlain({ id: checkId, productId: productId });
|
|
4470
|
+
return [4 /*yield*/, this.getId(dataWithProductId.id)];
|
|
4471
|
+
case 1:
|
|
4472
|
+
id = _c.sent();
|
|
4473
|
+
return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
|
|
4474
|
+
case 2:
|
|
4475
|
+
product = _c.sent();
|
|
4476
|
+
product.productId = dataWithProductId.productId;
|
|
4477
|
+
return [2 /*return*/, product];
|
|
4478
|
+
}
|
|
4479
|
+
});
|
|
4480
|
+
});
|
|
4481
|
+
};
|
|
4482
|
+
VariantHasuraGraphQLRepository.prototype.getId = function (id) {
|
|
4483
|
+
var _a, _b;
|
|
4484
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4485
|
+
var data;
|
|
4486
|
+
return __generator(this, function (_c) {
|
|
4487
|
+
switch (_c.label) {
|
|
4488
|
+
case 0:
|
|
4489
|
+
if (!Number.isNaN(+id))
|
|
4490
|
+
return [2 /*return*/, id];
|
|
4491
|
+
return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
|
|
4492
|
+
case 1:
|
|
4493
|
+
data = (_c.sent()).data;
|
|
4494
|
+
if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
|
|
4495
|
+
return [2 /*return*/, (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id];
|
|
4496
|
+
throw new NotFoundError("Product with id " + id + " not found");
|
|
4497
|
+
}
|
|
4498
|
+
});
|
|
4499
|
+
});
|
|
4500
|
+
};
|
|
4501
|
+
return VariantHasuraGraphQLRepository;
|
|
3568
4502
|
}(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
|
|
3569
4503
|
|
|
3570
4504
|
/**
|
|
@@ -3683,6 +4617,7 @@
|
|
|
3683
4617
|
exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
|
|
3684
4618
|
exports.Category = Category;
|
|
3685
4619
|
exports.CategoryFirestoreRepository = CategoryFirestoreRepository;
|
|
4620
|
+
exports.CategoryHasuraGraphQL = CategoryHasuraGraphQL;
|
|
3686
4621
|
exports.CategoryHasuraGraphQLRepository = CategoryHasuraGraphQLRepository;
|
|
3687
4622
|
exports.Checkout = Checkout;
|
|
3688
4623
|
exports.CheckoutFirestoreRepository = CheckoutFirestoreRepository;
|
|
@@ -3696,6 +4631,8 @@
|
|
|
3696
4631
|
exports.Home = Home;
|
|
3697
4632
|
exports.HomeFirestoreRepository = HomeFirestoreRepository;
|
|
3698
4633
|
exports.InvalidArgumentError = InvalidArgumentError;
|
|
4634
|
+
exports.KitProduct = KitProduct;
|
|
4635
|
+
exports.KitProductHasuraGraphQL = KitProductHasuraGraphQL;
|
|
3699
4636
|
exports.Lead = Lead;
|
|
3700
4637
|
exports.LeadFirestoreRepository = LeadFirestoreRepository;
|
|
3701
4638
|
exports.LegacyOrderFirestoreRepository = LegacyOrderFirestoreRepository;
|
|
@@ -3707,6 +4644,7 @@
|
|
|
3707
4644
|
exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|
|
3708
4645
|
exports.Product = Product;
|
|
3709
4646
|
exports.ProductFirestoreRepository = ProductFirestoreRepository;
|
|
4647
|
+
exports.ProductHasuraGraphQL = ProductHasuraGraphQL;
|
|
3710
4648
|
exports.ProductHasuraGraphQLRepository = ProductHasuraGraphQLRepository;
|
|
3711
4649
|
exports.ProductVariantFirestoreRepository = ProductVariantFirestoreRepository;
|
|
3712
4650
|
exports.ProductsIndex = ProductsIndex;
|
|
@@ -3737,6 +4675,8 @@
|
|
|
3737
4675
|
exports.UserPaymentMethodFirestoreRepository = UserPaymentMethodFirestoreRepository;
|
|
3738
4676
|
exports.UserSearchFirestoreRepository = UserSearchFirestoreRepository;
|
|
3739
4677
|
exports.Variant = Variant;
|
|
4678
|
+
exports.VariantHasuraGraphQL = VariantHasuraGraphQL;
|
|
4679
|
+
exports.VariantHasuraGraphQLRepository = VariantHasuraGraphQLRepository;
|
|
3740
4680
|
exports.WeakPasswordError = WeakPasswordError;
|
|
3741
4681
|
exports.isUUID = isUUID;
|
|
3742
4682
|
exports.parseDateTime = parseDateTime;
|