@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,14 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import {
|
|
3
|
-
import { __decorate, __metadata, __awaiter } from 'tslib';
|
|
2
|
+
import { plainToInstance, instanceToPlain, Expose, Type } from 'class-transformer';
|
|
3
|
+
import { __decorate, __metadata, __awaiter, __rest } from 'tslib';
|
|
4
4
|
import { parseISO } from 'date-fns';
|
|
5
5
|
export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
|
|
6
|
-
import { isString, isNil, isNumber, isDate, set, isObject, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1 } from 'lodash';
|
|
6
|
+
import { isString, isNil, isNumber, isDate, set, isObject, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1, omit } from 'lodash';
|
|
7
7
|
export { chunk, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set } from 'lodash';
|
|
8
|
+
import { CustomError } from 'ts-custom-error';
|
|
8
9
|
import { Md5 } from 'ts-md5';
|
|
9
10
|
import axios from 'axios';
|
|
10
11
|
import firebase from 'firebase';
|
|
11
|
-
import firebase$1 from 'firebase/app';
|
|
12
12
|
import { mutation, query } from 'gql-query-builder';
|
|
13
13
|
import fetch from 'node-fetch';
|
|
14
14
|
|
|
@@ -24,13 +24,13 @@ class BaseModel {
|
|
|
24
24
|
Object.assign(this, args);
|
|
25
25
|
}
|
|
26
26
|
static toInstance(data) {
|
|
27
|
-
return
|
|
27
|
+
return plainToInstance(this, data || {});
|
|
28
28
|
}
|
|
29
29
|
static isModel(value) {
|
|
30
30
|
return value instanceof this;
|
|
31
31
|
}
|
|
32
32
|
toPlain() {
|
|
33
|
-
return
|
|
33
|
+
return instanceToPlain(this);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -620,7 +620,7 @@ class Lead extends BaseModel {
|
|
|
620
620
|
}
|
|
621
621
|
}
|
|
622
622
|
|
|
623
|
-
class UnauthorizedError extends
|
|
623
|
+
class UnauthorizedError extends CustomError {
|
|
624
624
|
constructor(message) {
|
|
625
625
|
super(message);
|
|
626
626
|
this.message = message;
|
|
@@ -663,14 +663,14 @@ class Authentication {
|
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
665
|
|
|
666
|
-
class UserAlreadyRegisteredError extends
|
|
666
|
+
class UserAlreadyRegisteredError extends CustomError {
|
|
667
667
|
constructor(message) {
|
|
668
668
|
super(message);
|
|
669
669
|
this.message = message;
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
672
|
|
|
673
|
-
class WeakPasswordError extends
|
|
673
|
+
class WeakPasswordError extends CustomError {
|
|
674
674
|
constructor(message = 'Weak password') {
|
|
675
675
|
super(message);
|
|
676
676
|
this.message = message;
|
|
@@ -730,13 +730,6 @@ class RecoveryPassword {
|
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
732
|
|
|
733
|
-
var Shops;
|
|
734
|
-
(function (Shops) {
|
|
735
|
-
Shops["MENSMARKET"] = "mensmarket";
|
|
736
|
-
Shops["GLAMSHOP"] = "Glamshop";
|
|
737
|
-
Shops["GLAMPOINTS"] = "Glampoints";
|
|
738
|
-
})(Shops || (Shops = {}));
|
|
739
|
-
|
|
740
733
|
class Category extends BaseModel {
|
|
741
734
|
identifierFields() {
|
|
742
735
|
return ['id'];
|
|
@@ -746,6 +739,13 @@ class Category extends BaseModel {
|
|
|
746
739
|
}
|
|
747
740
|
}
|
|
748
741
|
|
|
742
|
+
var Shops;
|
|
743
|
+
(function (Shops) {
|
|
744
|
+
Shops["MENSMARKET"] = "mensmarket";
|
|
745
|
+
Shops["GLAMSHOP"] = "Glamshop";
|
|
746
|
+
Shops["GLAMPOINTS"] = "Glampoints";
|
|
747
|
+
})(Shops || (Shops = {}));
|
|
748
|
+
|
|
749
749
|
class Product extends BaseModel {
|
|
750
750
|
identifierFields() {
|
|
751
751
|
return ['id'];
|
|
@@ -758,6 +758,24 @@ class Product extends BaseModel {
|
|
|
758
758
|
return ['id'];
|
|
759
759
|
}
|
|
760
760
|
}
|
|
761
|
+
__decorate([
|
|
762
|
+
Type(() => KitProduct),
|
|
763
|
+
__metadata("design:type", Array)
|
|
764
|
+
], Product.prototype, "kitProducts", void 0);
|
|
765
|
+
|
|
766
|
+
class KitProduct extends BaseModel {
|
|
767
|
+
static get identifiersFields() {
|
|
768
|
+
return ['productId', 'kitProducId'];
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
__decorate([
|
|
772
|
+
Type(() => Product),
|
|
773
|
+
__metadata("design:type", Product)
|
|
774
|
+
], KitProduct.prototype, "kit", void 0);
|
|
775
|
+
__decorate([
|
|
776
|
+
Type(() => Product),
|
|
777
|
+
__metadata("design:type", Product)
|
|
778
|
+
], KitProduct.prototype, "product", void 0);
|
|
761
779
|
|
|
762
780
|
class Variant extends BaseModel {
|
|
763
781
|
identifierFields() {
|
|
@@ -980,14 +998,14 @@ class ShopMenu extends BaseModel {
|
|
|
980
998
|
}
|
|
981
999
|
}
|
|
982
1000
|
|
|
983
|
-
class InvalidArgumentError extends
|
|
1001
|
+
class InvalidArgumentError extends CustomError {
|
|
984
1002
|
constructor(message) {
|
|
985
1003
|
super(message);
|
|
986
1004
|
this.message = message;
|
|
987
1005
|
}
|
|
988
1006
|
}
|
|
989
1007
|
|
|
990
|
-
class RequiredArgumentError extends
|
|
1008
|
+
class RequiredArgumentError extends CustomError {
|
|
991
1009
|
constructor(args) {
|
|
992
1010
|
super(`Required arguments: ${args.join(', ')}`);
|
|
993
1011
|
this.args = args;
|
|
@@ -995,14 +1013,14 @@ class RequiredArgumentError extends Error {
|
|
|
995
1013
|
}
|
|
996
1014
|
}
|
|
997
1015
|
|
|
998
|
-
class NotFoundError extends
|
|
1016
|
+
class NotFoundError extends CustomError {
|
|
999
1017
|
constructor(message) {
|
|
1000
1018
|
super(message);
|
|
1001
1019
|
this.message = message;
|
|
1002
1020
|
}
|
|
1003
1021
|
}
|
|
1004
1022
|
|
|
1005
|
-
class DuplicatedResultsError extends
|
|
1023
|
+
class DuplicatedResultsError extends CustomError {
|
|
1006
1024
|
constructor(message) {
|
|
1007
1025
|
super(message);
|
|
1008
1026
|
this.message = message;
|
|
@@ -1013,6 +1031,21 @@ class AxiosAdapter {
|
|
|
1013
1031
|
constructor(config) {
|
|
1014
1032
|
this.config = config;
|
|
1015
1033
|
}
|
|
1034
|
+
get(index) {
|
|
1035
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1036
|
+
try {
|
|
1037
|
+
const { data } = yield axios({
|
|
1038
|
+
url: `${this.config.url}/${index}`,
|
|
1039
|
+
method: 'GET',
|
|
1040
|
+
headers: { Authorization: `Basic ${this.config.credential}` },
|
|
1041
|
+
});
|
|
1042
|
+
return data._source;
|
|
1043
|
+
}
|
|
1044
|
+
catch (error) {
|
|
1045
|
+
throw new NotFoundError(error.message);
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1016
1049
|
query(index, query) {
|
|
1017
1050
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1018
1051
|
const { data } = yield axios({
|
|
@@ -1027,12 +1060,37 @@ class AxiosAdapter {
|
|
|
1027
1060
|
};
|
|
1028
1061
|
});
|
|
1029
1062
|
}
|
|
1063
|
+
save(index, data) {
|
|
1064
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1065
|
+
yield axios({
|
|
1066
|
+
url: `${this.config.url}/${index}`,
|
|
1067
|
+
method: 'PUT',
|
|
1068
|
+
headers: { Authorization: `Basic ${this.config.credential}` },
|
|
1069
|
+
data,
|
|
1070
|
+
});
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
delete(index) {
|
|
1074
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1075
|
+
yield axios({
|
|
1076
|
+
url: `${this.config.url}/${index}`,
|
|
1077
|
+
method: 'DELETE',
|
|
1078
|
+
headers: { Authorization: `Basic ${this.config.credential}` },
|
|
1079
|
+
});
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1030
1082
|
}
|
|
1031
1083
|
|
|
1032
1084
|
class ProductsIndex {
|
|
1033
1085
|
constructor(adapter) {
|
|
1034
1086
|
this.adapter = adapter;
|
|
1035
1087
|
}
|
|
1088
|
+
get(id) {
|
|
1089
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1090
|
+
const data = yield this.adapter.get(`products/_doc/${id}`);
|
|
1091
|
+
return Product.toInstance(data);
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1036
1094
|
findById(ids, options) {
|
|
1037
1095
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1038
1096
|
const publishedField = options.shop === Shops.GLAMSHOP ? 'publishedGlam' : 'published';
|
|
@@ -1084,6 +1142,34 @@ class ProductsIndex {
|
|
|
1084
1142
|
return hits.map((hit) => Product.toInstance(hit._source));
|
|
1085
1143
|
});
|
|
1086
1144
|
}
|
|
1145
|
+
save(product) {
|
|
1146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1147
|
+
delete product.createdAt;
|
|
1148
|
+
delete product.updatedAt;
|
|
1149
|
+
delete product.kitProducts;
|
|
1150
|
+
try {
|
|
1151
|
+
if (!product.firestoreId)
|
|
1152
|
+
throw new Error('Is not a product from firestore');
|
|
1153
|
+
yield this.get(product.firestoreId);
|
|
1154
|
+
yield this.adapter.save(`products/_doc/${product.firestoreId}`, product.toPlain());
|
|
1155
|
+
}
|
|
1156
|
+
catch (error) {
|
|
1157
|
+
console.info(error.message);
|
|
1158
|
+
yield this.adapter.save(`products/_doc/${product.id}`, product.toPlain());
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
delete(product) {
|
|
1163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1164
|
+
try {
|
|
1165
|
+
yield this.get(product.firestoreId);
|
|
1166
|
+
yield this.adapter.delete(`products/_doc/${product.firestoreId}`);
|
|
1167
|
+
}
|
|
1168
|
+
catch (error) {
|
|
1169
|
+
yield this.adapter.delete(`products/_doc/${product.id}`);
|
|
1170
|
+
}
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1087
1173
|
}
|
|
1088
1174
|
|
|
1089
1175
|
const withFirestore = (MixinBase) => {
|
|
@@ -1097,7 +1183,7 @@ const withFirestore = (MixinBase) => {
|
|
|
1097
1183
|
fromFirestore: (snap) => {
|
|
1098
1184
|
const data = snap.data();
|
|
1099
1185
|
Object.keys(data).forEach((key) => {
|
|
1100
|
-
if (data[key]
|
|
1186
|
+
if (data[key] && typeof data[key] === 'object' && '_seconds' in data[key]) {
|
|
1101
1187
|
data[key] = data[key].toDate();
|
|
1102
1188
|
}
|
|
1103
1189
|
});
|
|
@@ -1182,11 +1268,11 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1182
1268
|
return queryReference.where(firestoreFieldName, (options === null || options === void 0 ? void 0 : options.operator) || '==', (options === null || options === void 0 ? void 0 : options.value) || options);
|
|
1183
1269
|
};
|
|
1184
1270
|
}
|
|
1185
|
-
find({ filters, limits, orderBy, }) {
|
|
1271
|
+
find({ filters, limits, orderBy, } = {}) {
|
|
1186
1272
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1187
|
-
let query = this.collection(this.buildCollectionPathForFind(filters));
|
|
1188
|
-
query = this.makeFirestoreWhere(query, filters);
|
|
1189
|
-
Object.keys(orderBy).forEach((fieldName) => (query = query.orderBy(fieldName, orderBy[fieldName])));
|
|
1273
|
+
let query = this.collection(this.buildCollectionPathForFind(filters || {}));
|
|
1274
|
+
query = this.makeFirestoreWhere(query, filters || {});
|
|
1275
|
+
Object.keys(orderBy || {}).forEach((fieldName) => (query = query.orderBy(fieldName, orderBy[fieldName])));
|
|
1190
1276
|
query = yield this.defineLimits(query, filters, limits);
|
|
1191
1277
|
const docs = yield query.get();
|
|
1192
1278
|
const data = docs.docs.map((doc) => doc.data());
|
|
@@ -1534,7 +1620,9 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
1534
1620
|
for (const productIds of chunks) {
|
|
1535
1621
|
if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
|
|
1536
1622
|
break;
|
|
1537
|
-
let query = yield this.collection('
|
|
1623
|
+
let query = yield this.collection('productsErpVitrine')
|
|
1624
|
+
.where(publishedField, '==', true)
|
|
1625
|
+
.where('id', 'in', productIds);
|
|
1538
1626
|
if (options === null || options === void 0 ? void 0 : options.hasStock)
|
|
1539
1627
|
query = query.where('stock.quantity', '>', 0);
|
|
1540
1628
|
if (options === null || options === void 0 ? void 0 : options.limit)
|
|
@@ -1553,21 +1641,48 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
1553
1641
|
constructor(firestore) {
|
|
1554
1642
|
super();
|
|
1555
1643
|
this.firestore = firestore;
|
|
1556
|
-
this.
|
|
1644
|
+
this.reviews = {};
|
|
1645
|
+
this.collectionName = 'productsErpVitrine';
|
|
1557
1646
|
this.model = Product;
|
|
1558
1647
|
}
|
|
1559
|
-
getBySlug(slug
|
|
1648
|
+
getBySlug(slug) {
|
|
1560
1649
|
var _a;
|
|
1561
1650
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1562
1651
|
const result = yield this.find({
|
|
1563
1652
|
filters: {
|
|
1564
1653
|
slug: { operator: Where.EQUALS, value: slug },
|
|
1565
|
-
shopAvailability: { operator: Where.IN, value: [shop] },
|
|
1566
1654
|
},
|
|
1567
1655
|
});
|
|
1568
1656
|
return (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
|
|
1569
1657
|
});
|
|
1570
1658
|
}
|
|
1659
|
+
fetchReviews(status) {
|
|
1660
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1661
|
+
const { data: products } = yield this.find();
|
|
1662
|
+
products.forEach((product) => {
|
|
1663
|
+
var _a;
|
|
1664
|
+
if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
|
|
1665
|
+
return;
|
|
1666
|
+
const productInfo = {
|
|
1667
|
+
productId: product.id,
|
|
1668
|
+
productName: product.name,
|
|
1669
|
+
productSku: product.sku,
|
|
1670
|
+
};
|
|
1671
|
+
this.reviews.pending = [];
|
|
1672
|
+
this.reviews.approved = [];
|
|
1673
|
+
this.reviews.rejected = [];
|
|
1674
|
+
product.reviews.forEach((review) => {
|
|
1675
|
+
if ([null, undefined].includes(review.status))
|
|
1676
|
+
return this.reviews.pending.push(Object.assign(Object.assign({}, review), productInfo));
|
|
1677
|
+
if (review.status === false)
|
|
1678
|
+
return this.reviews.rejected.push(Object.assign(Object.assign({}, review), productInfo));
|
|
1679
|
+
if (!!review.status)
|
|
1680
|
+
return this.reviews.approved.push(Object.assign(Object.assign({}, review), productInfo));
|
|
1681
|
+
});
|
|
1682
|
+
});
|
|
1683
|
+
return this.reviews[status];
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1571
1686
|
}
|
|
1572
1687
|
|
|
1573
1688
|
class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Product) {
|
|
@@ -1758,7 +1873,7 @@ class AuthenticationFirebaseAuthService {
|
|
|
1758
1873
|
}
|
|
1759
1874
|
signInWithGoogle() {
|
|
1760
1875
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1761
|
-
const credentials = yield this.firebaseAuth.signInWithPopup(new firebase
|
|
1876
|
+
const credentials = yield this.firebaseAuth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
|
|
1762
1877
|
const user = credentials.user;
|
|
1763
1878
|
return {
|
|
1764
1879
|
id: user.uid,
|
|
@@ -1813,6 +1928,121 @@ class RegisterFirebaseAuthService {
|
|
|
1813
1928
|
}
|
|
1814
1929
|
}
|
|
1815
1930
|
|
|
1931
|
+
class AttributeOptionHelper {
|
|
1932
|
+
}
|
|
1933
|
+
AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
1934
|
+
if (fields.includes(attributeName))
|
|
1935
|
+
return { columnName: attributeName.toString(), attributeName };
|
|
1936
|
+
const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
1937
|
+
const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName.toString()];
|
|
1938
|
+
if (isNil(fieldOption))
|
|
1939
|
+
return { columnName: attributeName.toString(), attributeName };
|
|
1940
|
+
if (Array.isArray(fieldOption))
|
|
1941
|
+
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
1942
|
+
return Object.assign({ attributeName, columnName: attributeName.toString() }, fieldOption);
|
|
1943
|
+
};
|
|
1944
|
+
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue.columnName;
|
|
1945
|
+
AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
1946
|
+
if (fields.includes(columnName))
|
|
1947
|
+
return { columnName, attributeName: columnName };
|
|
1948
|
+
const field = fields.find((columnOption) => {
|
|
1949
|
+
var _a;
|
|
1950
|
+
return isObject(columnOption) &&
|
|
1951
|
+
((_a = Object.values(columnOption).find((option) => AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName)) === null || _a === void 0 ? void 0 : _a.columnName) === columnName;
|
|
1952
|
+
}) || {};
|
|
1953
|
+
const attributeName = Object.keys(field).find((fieldOptionFromList) => AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) ||
|
|
1954
|
+
Array.isArray(field[fieldOptionFromList]));
|
|
1955
|
+
const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
|
|
1956
|
+
if (Array.isArray(fieldOption))
|
|
1957
|
+
return { attributeName: attributeName, fields: fieldOption };
|
|
1958
|
+
return Object.assign({ attributeName: attributeName || columnName, columnName }, fieldOption);
|
|
1959
|
+
};
|
|
1960
|
+
|
|
1961
|
+
class GraphQLFieldHelper {
|
|
1962
|
+
}
|
|
1963
|
+
GraphQLFieldHelper.CheckIsGraphQLParams = (params) => !isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
|
|
1964
|
+
GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
1965
|
+
return fields === null || fields === void 0 ? void 0 : fields.map((field) => {
|
|
1966
|
+
if (isString(field))
|
|
1967
|
+
return field.toString();
|
|
1968
|
+
const fieldName = Object.keys(field).shift();
|
|
1969
|
+
const fieldValue = field[fieldName];
|
|
1970
|
+
if (Array.isArray(fieldValue))
|
|
1971
|
+
return { [fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue) };
|
|
1972
|
+
if (!AttributeOptionHelper.CheckIsColumnOption(fieldValue))
|
|
1973
|
+
return;
|
|
1974
|
+
if (fieldValue.fields)
|
|
1975
|
+
return {
|
|
1976
|
+
[fieldValue.columnName || fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
1977
|
+
};
|
|
1978
|
+
return fieldValue.columnName;
|
|
1979
|
+
}).filter((field) => !!field);
|
|
1980
|
+
};
|
|
1981
|
+
GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
|
|
1982
|
+
const { attributeName, fields: attributeFields, from, } = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields);
|
|
1983
|
+
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
1984
|
+
if (Array.isArray(data[columnName]))
|
|
1985
|
+
return Object.assign(Object.assign({}, result), { [attributeName]: from
|
|
1986
|
+
? from(data[columnName], data)
|
|
1987
|
+
: data[columnName].map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(value, attributeFields)) });
|
|
1988
|
+
if (isObject(data[columnName]))
|
|
1989
|
+
return Object.assign(Object.assign({}, result), { [attributeName]: !!from
|
|
1990
|
+
? from(data[columnName])
|
|
1991
|
+
: GraphQLFieldHelper.ConvertFieldValueFrom(data[columnName], attributeFields) });
|
|
1992
|
+
}
|
|
1993
|
+
if (!!from)
|
|
1994
|
+
return Object.assign(Object.assign({}, result), { [attributeName]: from(data[columnName], data) });
|
|
1995
|
+
return Object.assign(Object.assign({}, result), { [attributeName]: parseDateTime(data[columnName]) });
|
|
1996
|
+
}, {});
|
|
1997
|
+
GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
1998
|
+
var _a;
|
|
1999
|
+
const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
2000
|
+
return Object.keys(data).reduce((result, attributeName) => {
|
|
2001
|
+
const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
|
|
2002
|
+
if (bindPersistData)
|
|
2003
|
+
return Object.assign(Object.assign({}, result), bindPersistData(data[attributeName], instance));
|
|
2004
|
+
if (isNil(columnName))
|
|
2005
|
+
return result;
|
|
2006
|
+
if (!!foreignKeyColumn &&
|
|
2007
|
+
!isEmpty(foreignKeyColumn) &&
|
|
2008
|
+
!Object.keys(foreignKeyColumn).filter((key) => { var _a; return !((_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[key]); }).length)
|
|
2009
|
+
return Object.keys(foreignKeyColumn).reduce((object, current) => { var _a; return (Object.assign(Object.assign({}, object), { [foreignKeyColumn[current]]: (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current] })); }, Object.assign({}, result));
|
|
2010
|
+
if (update && isObject(data[attributeName]) && !isNil(attributeFields) && !isDate(data[attributeName]))
|
|
2011
|
+
return result;
|
|
2012
|
+
if (!!columnName && Array.isArray(attributeFields) && isObject(data[attributeName])) {
|
|
2013
|
+
const converted = !isNil(columnName) && to ? to(instance[attributeName], instance) : data[attributeName];
|
|
2014
|
+
return Object.assign(Object.assign({}, result), (converted !== undefined
|
|
2015
|
+
? {
|
|
2016
|
+
[columnName]: {
|
|
2017
|
+
data: instance[attributeName] instanceof BaseModel
|
|
2018
|
+
? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
|
|
2019
|
+
: converted,
|
|
2020
|
+
},
|
|
2021
|
+
}
|
|
2022
|
+
: {}));
|
|
2023
|
+
}
|
|
2024
|
+
if (!!to)
|
|
2025
|
+
return Object.assign(Object.assign({}, result), { [columnName]: to(instance[attributeName], instance) });
|
|
2026
|
+
return Object.assign(Object.assign({}, result), { [columnName]: data[attributeName] });
|
|
2027
|
+
}, {});
|
|
2028
|
+
};
|
|
2029
|
+
|
|
2030
|
+
class FilterOptionHelper {
|
|
2031
|
+
}
|
|
2032
|
+
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
|
|
2033
|
+
FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
|
|
2034
|
+
if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
|
|
2035
|
+
return filter;
|
|
2036
|
+
if (filter.operator === Where.ISNULL)
|
|
2037
|
+
return true;
|
|
2038
|
+
if (filter.operator === Where.ISNOTNULL)
|
|
2039
|
+
return false;
|
|
2040
|
+
const converter = fieldOption.to ? fieldOption.to : (value) => value;
|
|
2041
|
+
return Array.isArray(filter.value) && !fieldOption.fields && [Where.IN, Where.NOTIN].includes(filter.operator)
|
|
2042
|
+
? filter.value.map((fieldValue) => converter(fieldValue))
|
|
2043
|
+
: converter(filter.value);
|
|
2044
|
+
};
|
|
2045
|
+
|
|
1816
2046
|
const withCreateHasuraGraphQL = (MixinBase) => {
|
|
1817
2047
|
return class CreateHasuraGraphQLMixin extends MixinBase {
|
|
1818
2048
|
constructor(...params) {
|
|
@@ -1829,7 +2059,25 @@ const withCreateHasuraGraphQL = (MixinBase) => {
|
|
|
1829
2059
|
}
|
|
1830
2060
|
save(data) {
|
|
1831
2061
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1832
|
-
const
|
|
2062
|
+
const primaryKeyColumns = this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName);
|
|
2063
|
+
const foreignKeyColumns = this.fields
|
|
2064
|
+
.map((field) => {
|
|
2065
|
+
const columnOptions = Object.values(field).shift();
|
|
2066
|
+
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
2067
|
+
columnOptions.foreignKeyColumn && [
|
|
2068
|
+
...Object.values(columnOptions.foreignKeyColumn),
|
|
2069
|
+
{
|
|
2070
|
+
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => {
|
|
2071
|
+
var _a;
|
|
2072
|
+
return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) ||
|
|
2073
|
+
foreignKeyField;
|
|
2074
|
+
}),
|
|
2075
|
+
},
|
|
2076
|
+
]);
|
|
2077
|
+
})
|
|
2078
|
+
.filter(Boolean)
|
|
2079
|
+
.reduce((keys, current) => [...keys, ...current], []);
|
|
2080
|
+
const result = yield this.mutation(this.insertGraphQLOperation, [...primaryKeyColumns, ...foreignKeyColumns], {
|
|
1833
2081
|
object: { type: this.insertGraphQLObjectType, required: true, value: this.convertDataToHasura(data) },
|
|
1834
2082
|
});
|
|
1835
2083
|
return Object.assign(Object.assign({}, data.toPlain()), this.convertDataFromHasura(result[this.insertGraphQLOperation]).toPlain());
|
|
@@ -1848,105 +2096,23 @@ const withDeleteHasuraGraphQL = (MixinBase) => {
|
|
|
1848
2096
|
delete(identifiers) {
|
|
1849
2097
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1850
2098
|
const instance = this.model.toInstance(identifiers);
|
|
1851
|
-
yield this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
2099
|
+
yield this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), this.model.identifiersFields.reduce((ids, identifier) => {
|
|
2100
|
+
if (isNil(instance[identifier]))
|
|
2101
|
+
return ids;
|
|
2102
|
+
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
|
|
2103
|
+
const value = columnOption.to(identifiers[identifier.toString()], instance);
|
|
2104
|
+
return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: {
|
|
2105
|
+
type: this.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
2106
|
+
value,
|
|
2107
|
+
required: true,
|
|
2108
|
+
} });
|
|
2109
|
+
}, {}));
|
|
1856
2110
|
});
|
|
1857
2111
|
}
|
|
1858
2112
|
};
|
|
1859
2113
|
};
|
|
1860
2114
|
|
|
1861
|
-
class AttributeOptionHelper {
|
|
1862
|
-
}
|
|
1863
|
-
AttributeOptionHelper.findByAttribute = (attributeName, fields) => {
|
|
1864
|
-
if (fields.includes(attributeName))
|
|
1865
|
-
return { columnName: attributeName.toString(), attributeName };
|
|
1866
|
-
const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
1867
|
-
const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName.toString()];
|
|
1868
|
-
if (isNil(fieldOption))
|
|
1869
|
-
return { columnName: attributeName.toString(), attributeName };
|
|
1870
|
-
if (Array.isArray(fieldOption))
|
|
1871
|
-
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
1872
|
-
return Object.assign({ attributeName, columnName: attributeName.toString() }, fieldOption);
|
|
1873
|
-
};
|
|
1874
|
-
|
|
1875
2115
|
const withHasuraGraphQL = (MixinBase) => {
|
|
1876
|
-
const checkIsGraphQLParams = (params) => !isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
|
|
1877
|
-
const checkIsColumnModelOption = (fieldValue) => !!fieldValue.columnName && !!fieldValue.fields;
|
|
1878
|
-
const checkIsColumnOption = (fieldValue) => checkIsColumnModelOption(fieldValue) || !!fieldValue.columnName;
|
|
1879
|
-
const convertModelFieldsToGraphQLFields = (fields) => {
|
|
1880
|
-
return fields
|
|
1881
|
-
.map((field) => {
|
|
1882
|
-
if (isString(field))
|
|
1883
|
-
return field.toString();
|
|
1884
|
-
const fieldName = Object.keys(field).shift();
|
|
1885
|
-
const fieldValue = field[fieldName];
|
|
1886
|
-
if (Array.isArray(fieldValue))
|
|
1887
|
-
return { [fieldName]: convertModelFieldsToGraphQLFields(fieldValue) };
|
|
1888
|
-
if (checkIsColumnModelOption(fieldValue))
|
|
1889
|
-
return { [fieldValue.columnName || fieldName]: convertModelFieldsToGraphQLFields(fieldValue.fields) };
|
|
1890
|
-
if (checkIsColumnOption(fieldValue))
|
|
1891
|
-
return fieldValue.columnName;
|
|
1892
|
-
return;
|
|
1893
|
-
})
|
|
1894
|
-
.filter((field) => !!field);
|
|
1895
|
-
};
|
|
1896
|
-
const findColumnOptionFromList = (columnName, fields) => {
|
|
1897
|
-
if (fields.includes(columnName))
|
|
1898
|
-
return { columnName, attributeName: columnName };
|
|
1899
|
-
const field = fields.find((columnOption) => {
|
|
1900
|
-
var _a;
|
|
1901
|
-
return isObject(columnOption) &&
|
|
1902
|
-
((_a = Object.values(columnOption).find((option) => checkIsColumnOption(option) && option.columnName === columnName)) === null || _a === void 0 ? void 0 : _a.columnName) === columnName;
|
|
1903
|
-
}) || {};
|
|
1904
|
-
const attributeName = Object.keys(field).find((fieldOption) => checkIsColumnOption(field[fieldOption]) || Array.isArray(field[fieldOption]));
|
|
1905
|
-
const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
|
|
1906
|
-
if (Array.isArray(fieldOption))
|
|
1907
|
-
return { attributeName: attributeName, fields: fieldOption };
|
|
1908
|
-
return Object.assign({ attributeName: attributeName || columnName, columnName }, fieldOption);
|
|
1909
|
-
};
|
|
1910
|
-
const convertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
|
|
1911
|
-
const { attributeName, fields: attributeFields, from } = findColumnOptionFromList(columnName, fields);
|
|
1912
|
-
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
1913
|
-
if (Array.isArray(data[columnName]))
|
|
1914
|
-
return Object.assign(Object.assign({}, result), { [attributeName]: from
|
|
1915
|
-
? from(data[columnName], data)
|
|
1916
|
-
: data[columnName].map((value) => convertFieldValueFrom(value, attributeFields)) });
|
|
1917
|
-
if (isObject(data[columnName]))
|
|
1918
|
-
return Object.assign(Object.assign({}, result), { [attributeName]: convertFieldValueFrom(data[columnName], attributeFields) });
|
|
1919
|
-
}
|
|
1920
|
-
if (!!from)
|
|
1921
|
-
return Object.assign(Object.assign({}, result), { [attributeName]: from(data[columnName], data) });
|
|
1922
|
-
return Object.assign(Object.assign({}, result), { [attributeName]: parseDateTime(data[columnName]) });
|
|
1923
|
-
}, {});
|
|
1924
|
-
const convertFieldValueTo = (instance, fields, update = false) => {
|
|
1925
|
-
var _a;
|
|
1926
|
-
const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
1927
|
-
return Object.keys(data)
|
|
1928
|
-
.filter((key) => !isNil(data[key]))
|
|
1929
|
-
.reduce((result, attributeName) => {
|
|
1930
|
-
const { columnName, fields: attributeFields, foreignKeyColumn, to, } = AttributeOptionHelper.findByAttribute(attributeName, fields);
|
|
1931
|
-
if (isNil(columnName))
|
|
1932
|
-
return result;
|
|
1933
|
-
if (!!foreignKeyColumn &&
|
|
1934
|
-
!isEmpty(foreignKeyColumn) &&
|
|
1935
|
-
!Object.keys(foreignKeyColumn).filter((key) => !data[attributeName][key]).length)
|
|
1936
|
-
return Object.keys(foreignKeyColumn).reduce((object, current) => (Object.assign(Object.assign({}, object), { [foreignKeyColumn[current]]: data[attributeName][current] })), Object.assign({}, result));
|
|
1937
|
-
if (update && isObject(data[attributeName]) && !isDate(data[attributeName]))
|
|
1938
|
-
return result;
|
|
1939
|
-
if (!!columnName && Array.isArray(attributeFields) && isObject(data[attributeName])) {
|
|
1940
|
-
const converted = !isNil(columnName) ? to(instance[attributeName], instance) : data[attributeName];
|
|
1941
|
-
return Object.assign(Object.assign({}, result), (converted !== undefined
|
|
1942
|
-
? { [columnName]: { data: convertFieldValueTo(data[attributeName], attributeFields) } }
|
|
1943
|
-
: {}));
|
|
1944
|
-
}
|
|
1945
|
-
if (!!to)
|
|
1946
|
-
return Object.assign(Object.assign({}, result), { [columnName]: to(instance[attributeName], instance) });
|
|
1947
|
-
return Object.assign(Object.assign({}, result), { [columnName]: data[attributeName] });
|
|
1948
|
-
}, {});
|
|
1949
|
-
};
|
|
1950
2116
|
return class HasuraGraphQLMixin extends MixinBase {
|
|
1951
2117
|
constructor(...params) {
|
|
1952
2118
|
const options = params[0];
|
|
@@ -1967,23 +2133,23 @@ const withHasuraGraphQL = (MixinBase) => {
|
|
|
1967
2133
|
const resultQuery = mutation({
|
|
1968
2134
|
operation,
|
|
1969
2135
|
variables,
|
|
1970
|
-
fields:
|
|
2136
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
|
|
1971
2137
|
});
|
|
1972
2138
|
return this.fetch(resultQuery);
|
|
1973
2139
|
});
|
|
1974
2140
|
}
|
|
1975
2141
|
query(operation, fields, variables) {
|
|
1976
2142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1977
|
-
const resultQuery =
|
|
2143
|
+
const resultQuery = GraphQLFieldHelper.CheckIsGraphQLParams(operation)
|
|
1978
2144
|
? query(operation.map((option) => ({
|
|
1979
2145
|
operation: option.operation,
|
|
1980
2146
|
variables: option.variables,
|
|
1981
|
-
fields:
|
|
2147
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(option.fields),
|
|
1982
2148
|
})))
|
|
1983
2149
|
: query({
|
|
1984
2150
|
operation,
|
|
1985
2151
|
variables,
|
|
1986
|
-
fields:
|
|
2152
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
|
|
1987
2153
|
});
|
|
1988
2154
|
return this.fetch(resultQuery);
|
|
1989
2155
|
});
|
|
@@ -2026,20 +2192,22 @@ const withHasuraGraphQL = (MixinBase) => {
|
|
|
2026
2192
|
return date;
|
|
2027
2193
|
}
|
|
2028
2194
|
convertDataFromHasura(data) {
|
|
2029
|
-
const plain =
|
|
2195
|
+
const plain = GraphQLFieldHelper.ConvertFieldValueFrom(data, this.fields);
|
|
2030
2196
|
return this.model.toInstance(plain);
|
|
2031
2197
|
}
|
|
2032
2198
|
convertDataToHasura(instance, update = false) {
|
|
2033
|
-
return
|
|
2199
|
+
return GraphQLFieldHelper.ConvertFieldValueTo(instance, this.fields, update);
|
|
2034
2200
|
}
|
|
2035
2201
|
};
|
|
2036
2202
|
};
|
|
2037
2203
|
|
|
2038
2204
|
const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
2039
2205
|
const getValueByAction = (options) => {
|
|
2040
|
-
if (
|
|
2206
|
+
if (options instanceof BaseModel)
|
|
2207
|
+
return options.toPlain();
|
|
2208
|
+
if (isNil(options === null || options === void 0 ? void 0 : options.action))
|
|
2041
2209
|
return options;
|
|
2042
|
-
if (
|
|
2210
|
+
if ([UpdateOptionActions.REMOVE_FIELD.toString(), UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
2043
2211
|
return null;
|
|
2044
2212
|
return options.value;
|
|
2045
2213
|
};
|
|
@@ -2054,7 +2222,7 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
2054
2222
|
update(data) {
|
|
2055
2223
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2056
2224
|
const plainData = this.paramsToPlain(data);
|
|
2057
|
-
yield this.mutation(this.updateGraphQLOperation, this.model.identifiersFields, {
|
|
2225
|
+
yield this.mutation(this.updateGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), {
|
|
2058
2226
|
_set: {
|
|
2059
2227
|
type: this.updateGraphQLObjectType,
|
|
2060
2228
|
value: this.convertDataToHasura(this.model.toInstance(plainData), true),
|
|
@@ -2069,10 +2237,18 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
2069
2237
|
const model = this.model;
|
|
2070
2238
|
if (model.isModel(params))
|
|
2071
2239
|
return params.toPlain();
|
|
2072
|
-
return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), { [currentKey]: getValueByAction(params[currentKey]) })), {});
|
|
2240
|
+
return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), (params[currentKey] !== undefined && { [currentKey]: getValueByAction(params[currentKey]) }))), {});
|
|
2073
2241
|
}
|
|
2074
2242
|
getUpdateModelKeys(data) {
|
|
2075
|
-
|
|
2243
|
+
const instance = this.model.toInstance(data);
|
|
2244
|
+
return this.model.identifiersFields.reduce((ids, identifier) => {
|
|
2245
|
+
var _a;
|
|
2246
|
+
if (isNil(instance[identifier]))
|
|
2247
|
+
return ids;
|
|
2248
|
+
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
|
|
2249
|
+
const 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];
|
|
2250
|
+
return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: value });
|
|
2251
|
+
}, {});
|
|
2076
2252
|
}
|
|
2077
2253
|
};
|
|
2078
2254
|
};
|
|
@@ -2087,15 +2263,18 @@ const withGetHasuraGraphQL = (MixinBase) => {
|
|
|
2087
2263
|
get(identifiers) {
|
|
2088
2264
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2089
2265
|
const instance = this.model.toInstance(identifiers);
|
|
2090
|
-
const result = yield this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce((ids, identifier) =>
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2266
|
+
const result = yield this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce((ids, identifier) => {
|
|
2267
|
+
var _a;
|
|
2268
|
+
if (isNil(instance[identifier]))
|
|
2269
|
+
return ids;
|
|
2270
|
+
const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
|
|
2271
|
+
const value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, identifiers[identifier.toString()], instance)) || identifiers[identifier.toString()];
|
|
2272
|
+
return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: {
|
|
2273
|
+
type: this.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
2274
|
+
value,
|
|
2096
2275
|
required: true,
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2276
|
+
} });
|
|
2277
|
+
}, {}));
|
|
2099
2278
|
const data = result[this.getGraphQLOperation];
|
|
2100
2279
|
if (isNil(data))
|
|
2101
2280
|
throw new NotFoundError(`${instance.constructor.name} not found`);
|
|
@@ -2134,33 +2313,25 @@ var HasuraGraphQLColumnType;
|
|
|
2134
2313
|
})(HasuraGraphQLColumnType || (HasuraGraphQLColumnType = {}));
|
|
2135
2314
|
|
|
2136
2315
|
const withFindHasuraGraphQL = (MixinBase) => {
|
|
2137
|
-
const checkIfIsFilterOption = (filter) => !isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
|
|
2138
|
-
const getValueFromFilter = (filter, fieldOption) => {
|
|
2139
|
-
if (!checkIfIsFilterOption(filter))
|
|
2140
|
-
return filter;
|
|
2141
|
-
if (filter.operator === Where.ISNULL)
|
|
2142
|
-
return true;
|
|
2143
|
-
if (filter.operator === Where.ISNOTNULL)
|
|
2144
|
-
return false;
|
|
2145
|
-
const converter = fieldOption.to ? fieldOption.to : (value) => value;
|
|
2146
|
-
return Array.isArray(filter.value) && [Where.IN, Where.NOTIN].includes(filter.operator)
|
|
2147
|
-
? filter.value.map((fieldValue) => converter(fieldValue))
|
|
2148
|
-
: converter(filter.value);
|
|
2149
|
-
};
|
|
2150
2316
|
return class FindHasuraGraphQLMixin extends MixinBase {
|
|
2151
2317
|
constructor() {
|
|
2152
2318
|
super(...arguments);
|
|
2153
|
-
this.makeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) =>
|
|
2154
|
-
|
|
2319
|
+
this.makeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => {
|
|
2320
|
+
const columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
|
|
2321
|
+
if (!columnOption.bindFindFilter)
|
|
2322
|
+
return Object.assign(Object.assign({}, variables), { [columnOption.columnName]: this.buildWhereSentence(fieldName, filter[fieldName], fields) });
|
|
2323
|
+
const builtFilter = columnOption.bindFindFilter(filter[fieldName]);
|
|
2324
|
+
return Object.assign(Object.assign({}, variables), Object.keys(builtFilter).reduce((variablesList, columnName) => (Object.assign(Object.assign({}, variablesList), { [columnName]: this.buildWhereSentence(fieldName, builtFilter[columnName], fields) })), {}));
|
|
2325
|
+
}, {});
|
|
2155
2326
|
this.buildWhereSentence = (field, options, fields) => {
|
|
2156
|
-
const fieldSentenceOptions = AttributeOptionHelper.
|
|
2327
|
+
const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
2157
2328
|
if (!Array.isArray(options) &&
|
|
2158
2329
|
isObject(options) &&
|
|
2159
2330
|
isNil(options === null || options === void 0 ? void 0 : options.operator) &&
|
|
2160
2331
|
isNil(options === null || options === void 0 ? void 0 : options.value) &&
|
|
2161
2332
|
isNil(fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.to))
|
|
2162
2333
|
return Object.keys(options).reduce((variables, key) => {
|
|
2163
|
-
const fieldOptions = AttributeOptionHelper.
|
|
2334
|
+
const fieldOptions = AttributeOptionHelper.FindByAttribute(key, (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || fields);
|
|
2164
2335
|
const columnName = fieldOptions.columnName;
|
|
2165
2336
|
const columnFields = fieldOptions.fields;
|
|
2166
2337
|
return Object.assign(Object.assign({}, variables), { [columnName]: this.buildWhereSentence(key, options[key], columnFields || []) });
|
|
@@ -2169,16 +2340,16 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
2169
2340
|
return {
|
|
2170
2341
|
[fieldSentenceOptions.fields[0]]: this.buildOperatorSentence(options, fieldSentenceOptions),
|
|
2171
2342
|
};
|
|
2172
|
-
if (isObject(options) && !
|
|
2343
|
+
if (isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
2173
2344
|
options = Object.values(options)[0];
|
|
2174
2345
|
return Array.isArray(options)
|
|
2175
2346
|
? options.reduce((whereSentence, option) => (Object.assign(Object.assign({}, whereSentence), this.buildOperatorSentence(option, fieldSentenceOptions))), {})
|
|
2176
2347
|
: this.buildOperatorSentence(options, fieldSentenceOptions);
|
|
2177
2348
|
};
|
|
2178
2349
|
this.buildOperatorSentence = (options, fieldOption) => ({
|
|
2179
|
-
[this.getHasuraOperator(options, fieldOption)]:
|
|
2350
|
+
[this.getHasuraOperator(options, fieldOption)]: FilterOptionHelper.GetValueFromFilter(options, fieldOption),
|
|
2180
2351
|
});
|
|
2181
|
-
this.getHasuraOperator = (options, fieldOption) =>
|
|
2352
|
+
this.getHasuraOperator = (options, fieldOption) => FilterOptionHelper.CheckIfIsFilterOption(options)
|
|
2182
2353
|
? fieldOption.type === HasuraGraphQLColumnType.Jsonb
|
|
2183
2354
|
? this.getHasuraJsonbOperator(options)
|
|
2184
2355
|
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator === Object.keys(Where).find((operator) => Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))]
|
|
@@ -2202,11 +2373,17 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
2202
2373
|
},
|
|
2203
2374
|
}));
|
|
2204
2375
|
const variables = Object.assign(Object.assign({}, (isNil(limits) ? {} : limits)), variablesCount);
|
|
2205
|
-
console.log(JSON.stringify(variables));
|
|
2206
2376
|
const result = yield this.query([
|
|
2207
2377
|
{
|
|
2208
2378
|
operation: this.tableName,
|
|
2209
|
-
fields:
|
|
2379
|
+
fields: options.fields
|
|
2380
|
+
? options.fields
|
|
2381
|
+
.map((fieldName) => {
|
|
2382
|
+
var _a;
|
|
2383
|
+
return (_a = this.fields.find((fieldOption) => fieldOption === fieldName)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName);
|
|
2384
|
+
})
|
|
2385
|
+
.filter(Boolean)
|
|
2386
|
+
: this.fields,
|
|
2210
2387
|
variables,
|
|
2211
2388
|
},
|
|
2212
2389
|
{
|
|
@@ -2215,7 +2392,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
2215
2392
|
variables: variablesCount,
|
|
2216
2393
|
},
|
|
2217
2394
|
]);
|
|
2218
|
-
const data = result[this.tableName].map((
|
|
2395
|
+
const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
|
|
2219
2396
|
const count = result[`${this.tableName}_aggregate`].aggregate.count;
|
|
2220
2397
|
return { count, data };
|
|
2221
2398
|
});
|
|
@@ -2228,6 +2405,35 @@ const withCrudHasuraGraphQL = (MixinBase) => {
|
|
|
2228
2405
|
};
|
|
2229
2406
|
};
|
|
2230
2407
|
|
|
2408
|
+
class CategoryHasuraGraphQL extends Category {
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
class ProductHasuraGraphQL extends Product {
|
|
2412
|
+
}
|
|
2413
|
+
__decorate([
|
|
2414
|
+
Type(() => KitProductHasuraGraphQL),
|
|
2415
|
+
__metadata("design:type", Array)
|
|
2416
|
+
], ProductHasuraGraphQL.prototype, "kitProducts", void 0);
|
|
2417
|
+
|
|
2418
|
+
class KitProductHasuraGraphQL extends KitProduct {
|
|
2419
|
+
}
|
|
2420
|
+
__decorate([
|
|
2421
|
+
Type(() => ProductHasuraGraphQL),
|
|
2422
|
+
__metadata("design:type", ProductHasuraGraphQL)
|
|
2423
|
+
], KitProductHasuraGraphQL.prototype, "kit", void 0);
|
|
2424
|
+
__decorate([
|
|
2425
|
+
Type(() => ProductHasuraGraphQL),
|
|
2426
|
+
__metadata("design:type", ProductHasuraGraphQL)
|
|
2427
|
+
], KitProductHasuraGraphQL.prototype, "product", void 0);
|
|
2428
|
+
|
|
2429
|
+
class VariantHasuraGraphQL extends Variant {
|
|
2430
|
+
constructor() {
|
|
2431
|
+
super(...arguments);
|
|
2432
|
+
this.name = '';
|
|
2433
|
+
this.hasVariants = false;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2231
2437
|
class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
2232
2438
|
constructor(endpoint, authOptions, productRepository) {
|
|
2233
2439
|
super({
|
|
@@ -2237,7 +2443,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2237
2443
|
authOptions,
|
|
2238
2444
|
fields: [
|
|
2239
2445
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
2240
|
-
'firestore_id',
|
|
2446
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
2241
2447
|
'name',
|
|
2242
2448
|
'description',
|
|
2243
2449
|
'image',
|
|
@@ -2248,11 +2454,22 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2248
2454
|
{ brandCategoryBanner: { columnName: 'brand_banner' } },
|
|
2249
2455
|
{ brandCategoryBannerMobile: { columnName: 'brand_banner_mobile' } },
|
|
2250
2456
|
{ brandLogo: { columnName: 'brand_logo' } },
|
|
2251
|
-
{
|
|
2457
|
+
{ brandCondition: { columnName: 'brand_condition' } },
|
|
2252
2458
|
{
|
|
2253
2459
|
conditions: {
|
|
2254
2460
|
columnName: 'tag_condition',
|
|
2255
|
-
|
|
2461
|
+
type: HasuraGraphQLColumnType.Jsonb,
|
|
2462
|
+
from: (tags, row) => ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }),
|
|
2463
|
+
bindPersistData: (value) => {
|
|
2464
|
+
var _a, _b;
|
|
2465
|
+
return {
|
|
2466
|
+
brand_condition: value.brand,
|
|
2467
|
+
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, '","')) || ''}"}`,
|
|
2468
|
+
};
|
|
2469
|
+
},
|
|
2470
|
+
bindFindFilter: (sentence) => {
|
|
2471
|
+
return Object.assign(Object.assign({}, (sentence.brand ? { brand_condition: sentence.brand } : {})), (sentence.tags ? { tag_condition: sentence.tags } : {}));
|
|
2472
|
+
},
|
|
2256
2473
|
},
|
|
2257
2474
|
},
|
|
2258
2475
|
'filters',
|
|
@@ -2263,6 +2480,9 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2263
2480
|
columnName: 'products',
|
|
2264
2481
|
fields: ['product_id'],
|
|
2265
2482
|
from: (value) => value.map((product) => product.product_id.toString()),
|
|
2483
|
+
to: (productIds) => productIds.map((productId) => ({
|
|
2484
|
+
product_id: +productId,
|
|
2485
|
+
})),
|
|
2266
2486
|
},
|
|
2267
2487
|
},
|
|
2268
2488
|
],
|
|
@@ -2276,7 +2496,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2276
2496
|
var _a;
|
|
2277
2497
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2278
2498
|
return Number.isNaN(+identifiers.id)
|
|
2279
|
-
? (_a = (yield this.find({ filters: {
|
|
2499
|
+
? (_a = (yield this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
|
|
2280
2500
|
: _super.get.call(this, identifiers);
|
|
2281
2501
|
});
|
|
2282
2502
|
}
|
|
@@ -2295,7 +2515,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2295
2515
|
getCategoriesForHome(categoryIds, limit = 4) {
|
|
2296
2516
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2297
2517
|
const { data: categories, count } = yield this.find({
|
|
2298
|
-
filters: {
|
|
2518
|
+
filters: { firestoreId: { operator: Where.IN, value: categoryIds.filter(Boolean) }, published: true },
|
|
2299
2519
|
});
|
|
2300
2520
|
if (!count)
|
|
2301
2521
|
throw new NotFoundError('Categories not found');
|
|
@@ -2312,15 +2532,32 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2312
2532
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2313
2533
|
if (!category.products)
|
|
2314
2534
|
throw new RequiredArgumentError(['Category products is empty']);
|
|
2315
|
-
console.log(category);
|
|
2316
|
-
console.log(category.products);
|
|
2317
2535
|
const products = [];
|
|
2318
2536
|
const publishedField = category.shop === Shops.GLAMSHOP ? 'publishedGlam' : 'published';
|
|
2319
|
-
const { data: productsData } = yield this.productRepository.find(Object.assign({ filters: {
|
|
2320
|
-
id
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2537
|
+
const { data: productsData } = yield this.productRepository.find(Object.assign({ filters: Object.assign({ id: { operator: Where.IN, value: category.products }, [publishedField]: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})), fields: [
|
|
2538
|
+
'id',
|
|
2539
|
+
'name',
|
|
2540
|
+
'slug',
|
|
2541
|
+
'images',
|
|
2542
|
+
'miniatures',
|
|
2543
|
+
'price',
|
|
2544
|
+
'fullPrice',
|
|
2545
|
+
'subscriberDiscountPercentage',
|
|
2546
|
+
'subscriberPrice',
|
|
2547
|
+
'stock',
|
|
2548
|
+
'published',
|
|
2549
|
+
'publishedGlam',
|
|
2550
|
+
'CEST',
|
|
2551
|
+
'EAN',
|
|
2552
|
+
'NCM',
|
|
2553
|
+
'brand',
|
|
2554
|
+
'costPrice',
|
|
2555
|
+
'hasVariants',
|
|
2556
|
+
'isKit',
|
|
2557
|
+
'shopAvailability',
|
|
2558
|
+
'sku',
|
|
2559
|
+
'rate',
|
|
2560
|
+
] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})));
|
|
2324
2561
|
products.push(...productsData);
|
|
2325
2562
|
return products;
|
|
2326
2563
|
});
|
|
@@ -2331,24 +2568,383 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2331
2568
|
constructor(endpoint, authOptions) {
|
|
2332
2569
|
super({
|
|
2333
2570
|
tableName: 'product',
|
|
2334
|
-
model:
|
|
2571
|
+
model: ProductHasuraGraphQL,
|
|
2572
|
+
endpoint,
|
|
2573
|
+
authOptions,
|
|
2574
|
+
fields: [],
|
|
2575
|
+
});
|
|
2576
|
+
this.bindReviewToModel = (plain) => (Object.assign(Object.assign({}, 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 }));
|
|
2577
|
+
this.bindReviewToHasura = (review) => (Object.assign(Object.assign({}, omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])), { person_id: review.personId, order_id: review.orderId }));
|
|
2578
|
+
const commonFields = [
|
|
2579
|
+
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
2580
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
2581
|
+
{ CEST: { columnName: 'cest' } },
|
|
2582
|
+
{ EAN: { columnName: 'ean' } },
|
|
2583
|
+
{ NCM: { columnName: 'ncm' } },
|
|
2584
|
+
'brand',
|
|
2585
|
+
{ costPrice: { columnName: 'cost_price' } },
|
|
2586
|
+
{
|
|
2587
|
+
description: {
|
|
2588
|
+
columnName: 'description',
|
|
2589
|
+
from: (description) => Object.values(Shops).reduce((shops, shop) => (Object.assign(Object.assign({}, shops), { [shop]: { description } })), {}),
|
|
2590
|
+
to: (value) => Object.values(value).shift().description,
|
|
2591
|
+
},
|
|
2592
|
+
},
|
|
2593
|
+
{ hasVariants: { columnName: 'has_variants' } },
|
|
2594
|
+
{ images: { columnName: 'images', to: (value) => { var _a; return `{"${((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, `","`)) || ''}"}`; } } },
|
|
2595
|
+
{ miniatures: { columnName: 'miniatures', to: (value) => { var _a; return `{"${((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, `","`)) || ''}"}`; } } },
|
|
2596
|
+
'name',
|
|
2597
|
+
{
|
|
2598
|
+
price: {
|
|
2599
|
+
columnName: 'price',
|
|
2600
|
+
from: (price, data) => Object.values(Shops).reduce((prices, shop) => (Object.assign(Object.assign({}, prices), { [shop]: {
|
|
2601
|
+
price,
|
|
2602
|
+
fullPrice: data.full_price,
|
|
2603
|
+
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
2604
|
+
subscriberPrice: data.subscriber_price,
|
|
2605
|
+
} })), {}),
|
|
2606
|
+
bindFindFilter: (sentence) => {
|
|
2607
|
+
const filters = Object.values(sentence).shift();
|
|
2608
|
+
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) && {
|
|
2609
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
2610
|
+
})), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
2611
|
+
subscriber_price: filters.subscriberPrice,
|
|
2612
|
+
}));
|
|
2613
|
+
},
|
|
2614
|
+
bindPersistData: (value) => {
|
|
2615
|
+
const priceData = Object.values(value).shift();
|
|
2616
|
+
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 && {
|
|
2617
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
2618
|
+
})), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }));
|
|
2619
|
+
},
|
|
2620
|
+
},
|
|
2621
|
+
},
|
|
2622
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
2623
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
2624
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
2625
|
+
'published',
|
|
2626
|
+
{ publishedGlam: { columnName: 'published_glam' } },
|
|
2627
|
+
'sku',
|
|
2628
|
+
{
|
|
2629
|
+
stock: {
|
|
2630
|
+
columnName: 'stock',
|
|
2631
|
+
from: (quantity) => ({ quantity }),
|
|
2632
|
+
to: (value) => (isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity),
|
|
2633
|
+
},
|
|
2634
|
+
},
|
|
2635
|
+
'slug',
|
|
2636
|
+
'type',
|
|
2637
|
+
'video',
|
|
2638
|
+
'weight',
|
|
2639
|
+
{
|
|
2640
|
+
shopAvailability: {
|
|
2641
|
+
columnName: 'shop_availabilities',
|
|
2642
|
+
fields: ['shop'],
|
|
2643
|
+
from: (shop) => (Array.isArray(shop) ? shop.map((row) => row.shop) : []),
|
|
2644
|
+
bindPersistData: (shops) => ({ shop_availabilities: { data: shops.map((shop) => ({ shop })) } }),
|
|
2645
|
+
},
|
|
2646
|
+
},
|
|
2647
|
+
{ tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
2648
|
+
{ isKit: { columnName: 'is_kit' } },
|
|
2649
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
2650
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
2651
|
+
{
|
|
2652
|
+
rate: {
|
|
2653
|
+
columnName: 'reviews_aggregate',
|
|
2654
|
+
fields: [{ aggregate: [{ avg: ['rate'] }] }],
|
|
2655
|
+
from: (value) => value.aggregate.avg.rate,
|
|
2656
|
+
},
|
|
2657
|
+
},
|
|
2658
|
+
];
|
|
2659
|
+
this.fields = [
|
|
2660
|
+
...commonFields,
|
|
2661
|
+
{
|
|
2662
|
+
categories: {
|
|
2663
|
+
columnName: 'categories',
|
|
2664
|
+
fields: ['category_id'],
|
|
2665
|
+
bindPersistData: (value) => ({
|
|
2666
|
+
categories: { data: value.map((category) => ({ category_id: +category })) },
|
|
2667
|
+
}),
|
|
2668
|
+
to: (categories) => categories.map((categoryId) => +categoryId),
|
|
2669
|
+
from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || [],
|
|
2670
|
+
},
|
|
2671
|
+
},
|
|
2672
|
+
{
|
|
2673
|
+
kitProducts: {
|
|
2674
|
+
columnName: 'kit_products',
|
|
2675
|
+
foreignKeyColumn: { productId: 'id' },
|
|
2676
|
+
fields: [
|
|
2677
|
+
{ productId: { columnName: 'product_id' } },
|
|
2678
|
+
{ kitProductId: { columnName: 'kit_product_id' } },
|
|
2679
|
+
'quantity',
|
|
2680
|
+
{ product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
|
|
2681
|
+
],
|
|
2682
|
+
},
|
|
2683
|
+
},
|
|
2684
|
+
];
|
|
2685
|
+
}
|
|
2686
|
+
get reviewsFields() {
|
|
2687
|
+
return [
|
|
2688
|
+
'id',
|
|
2689
|
+
'shop',
|
|
2690
|
+
'rate',
|
|
2691
|
+
'author',
|
|
2692
|
+
'email',
|
|
2693
|
+
'location',
|
|
2694
|
+
'review',
|
|
2695
|
+
'status',
|
|
2696
|
+
'title',
|
|
2697
|
+
'person_id',
|
|
2698
|
+
'points',
|
|
2699
|
+
'order_id',
|
|
2700
|
+
'created_at',
|
|
2701
|
+
'updated_at',
|
|
2702
|
+
];
|
|
2703
|
+
}
|
|
2704
|
+
create(data) {
|
|
2705
|
+
const _super = Object.create(null, {
|
|
2706
|
+
create: { get: () => super.create }
|
|
2707
|
+
});
|
|
2708
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2709
|
+
const product = yield _super.create.call(this, omit(data, ['reviews']));
|
|
2710
|
+
try {
|
|
2711
|
+
product.reviews = yield this.updateReviews(+product.id, data);
|
|
2712
|
+
}
|
|
2713
|
+
catch (error) {
|
|
2714
|
+
yield this.delete({ id: product.id });
|
|
2715
|
+
throw error;
|
|
2716
|
+
}
|
|
2717
|
+
return product;
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
get(identifiers) {
|
|
2721
|
+
const _super = Object.create(null, {
|
|
2722
|
+
get: { get: () => super.get }
|
|
2723
|
+
});
|
|
2724
|
+
var _a;
|
|
2725
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2726
|
+
const product = Number.isNaN(+identifiers.id)
|
|
2727
|
+
? (_a = (yield this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
|
|
2728
|
+
: yield _super.get.call(this, identifiers);
|
|
2729
|
+
product.reviews = yield this.findReviewsByProduct(+product.id);
|
|
2730
|
+
return product;
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
getBySlug(slug) {
|
|
2734
|
+
var _a;
|
|
2735
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2736
|
+
const result = yield this.find({
|
|
2737
|
+
filters: {
|
|
2738
|
+
slug,
|
|
2739
|
+
},
|
|
2740
|
+
});
|
|
2741
|
+
const product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
|
|
2742
|
+
product.reviews = yield this.findReviewsByProduct(+product.id);
|
|
2743
|
+
return product;
|
|
2744
|
+
});
|
|
2745
|
+
}
|
|
2746
|
+
update(params) {
|
|
2747
|
+
const _super = Object.create(null, {
|
|
2748
|
+
update: { get: () => super.update }
|
|
2749
|
+
});
|
|
2750
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2751
|
+
const { categories, kitProducts, reviews, id: checkId, shopAvailability, rate } = params, data = __rest(params, ["categories", "kitProducts", "reviews", "id", "shopAvailability", "rate"]);
|
|
2752
|
+
const plainData = this.paramsToPlain({ id: checkId });
|
|
2753
|
+
const id = yield this.getId(plainData.id);
|
|
2754
|
+
const product = yield _super.update.call(this, Object.assign({ id }, data));
|
|
2755
|
+
product.categories = categories && (yield this.updateCategories(+id, { categories }));
|
|
2756
|
+
product.kitProducts = kitProducts && (yield this.updateKitProducts(+id, { kitProducts }));
|
|
2757
|
+
product.reviews = reviews && (yield this.updateReviews(+id, { reviews }));
|
|
2758
|
+
return product;
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
fetchReviews(status) {
|
|
2762
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2763
|
+
const reviews = {
|
|
2764
|
+
status: status === 'pending'
|
|
2765
|
+
? { [HasuraGraphQLWhere.ISNULL]: true }
|
|
2766
|
+
: { [HasuraGraphQLWhere.EQUALS]: status === 'approved' },
|
|
2767
|
+
};
|
|
2768
|
+
const { product: data } = yield this.query('product', ['id', 'name', 'sku', { reviews: { columnName: 'reviews', fields: this.reviewsFields } }], {
|
|
2769
|
+
where: { value: { reviews }, type: 'product_bool_exp', required: true },
|
|
2770
|
+
});
|
|
2771
|
+
return data.reduce((reviews, product) => [
|
|
2772
|
+
...reviews,
|
|
2773
|
+
...product.reviews
|
|
2774
|
+
.filter((review) => (status === 'pending' && [undefined, null].includes(review.status)) ||
|
|
2775
|
+
(status === 'approved' && review.status === true) ||
|
|
2776
|
+
(status === 'rejected' && review.status === false))
|
|
2777
|
+
.map((review) => (Object.assign(Object.assign({}, this.bindReviewToModel(review)), { productId: product.id, productName: product.name, productSku: product.sku }))),
|
|
2778
|
+
], []);
|
|
2779
|
+
});
|
|
2780
|
+
}
|
|
2781
|
+
updateCategories(productId, { categories }) {
|
|
2782
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2783
|
+
const plainData = this.paramsToPlain({ categories });
|
|
2784
|
+
yield this.mutation('delete_category_product', ['affected_rows'], {
|
|
2785
|
+
where: {
|
|
2786
|
+
type: 'category_product_bool_exp',
|
|
2787
|
+
required: true,
|
|
2788
|
+
value: { product_id: { _eq: productId } },
|
|
2789
|
+
},
|
|
2790
|
+
});
|
|
2791
|
+
yield this.mutation('insert_category_product', ['affected_rows'], {
|
|
2792
|
+
objects: {
|
|
2793
|
+
type: '[category_product_insert_input!]',
|
|
2794
|
+
required: true,
|
|
2795
|
+
value: plainData.categories.map((categoryId) => ({ category_id: categoryId, product_id: productId })),
|
|
2796
|
+
},
|
|
2797
|
+
});
|
|
2798
|
+
return plainData.categories;
|
|
2799
|
+
});
|
|
2800
|
+
}
|
|
2801
|
+
updateKitProducts(productId, { kitProducts }) {
|
|
2802
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2803
|
+
const plainData = this.paramsToPlain({ kitProducts });
|
|
2804
|
+
yield this.mutation('delete_product_kit', ['affected_rows'], {
|
|
2805
|
+
where: {
|
|
2806
|
+
type: 'product_kit_bool_exp',
|
|
2807
|
+
required: true,
|
|
2808
|
+
value: { product_id: { _eq: productId } },
|
|
2809
|
+
},
|
|
2810
|
+
});
|
|
2811
|
+
yield this.mutation('insert_product_kit', ['affected_rows'], {
|
|
2812
|
+
objects: {
|
|
2813
|
+
type: '[product_kit_insert_input!]',
|
|
2814
|
+
required: true,
|
|
2815
|
+
value: plainData.kitProducts.map((kitProduct) => ({
|
|
2816
|
+
kit_product_id: kitProduct.productId || kitProduct.product.id,
|
|
2817
|
+
product_id: productId,
|
|
2818
|
+
quantity: kitProduct.quantity,
|
|
2819
|
+
})),
|
|
2820
|
+
},
|
|
2821
|
+
});
|
|
2822
|
+
return plainData.kitProducts;
|
|
2823
|
+
});
|
|
2824
|
+
}
|
|
2825
|
+
updateReviews(productId, { reviews }) {
|
|
2826
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2827
|
+
if (!reviews)
|
|
2828
|
+
return [];
|
|
2829
|
+
if ('action' in reviews && reviews.action === 'remove') {
|
|
2830
|
+
const reviewIds = yield Promise.all(reviews.value.map((reviewData) => __awaiter(this, void 0, void 0, function* () {
|
|
2831
|
+
const review = yield this.findReview(reviewData, productId);
|
|
2832
|
+
return review === null || review === void 0 ? void 0 : review.id;
|
|
2833
|
+
})));
|
|
2834
|
+
yield this.mutation('delete_product_review', ['affected_rows'], {
|
|
2835
|
+
where: { value: { id: { _in: reviewIds.filter(Boolean) } }, type: 'product_review_bool_exp', required: true },
|
|
2836
|
+
});
|
|
2837
|
+
return reviews.value.map((review, index) => !reviewIds[index] && review).filter(Boolean);
|
|
2838
|
+
}
|
|
2839
|
+
const plainData = this.paramsToPlain({ reviews });
|
|
2840
|
+
return Promise.all(plainData.reviews.map((reviewData) => __awaiter(this, void 0, void 0, function* () {
|
|
2841
|
+
const review = yield this.findReview(reviewData, productId);
|
|
2842
|
+
if (review.id)
|
|
2843
|
+
return this.bindReviewToModel((yield this.mutation('update_product_review_by_pk', this.reviewsFields, {
|
|
2844
|
+
pk_columns: {
|
|
2845
|
+
value: { id: review.id },
|
|
2846
|
+
type: 'product_review_pk_columns_input',
|
|
2847
|
+
required: true,
|
|
2848
|
+
},
|
|
2849
|
+
_set: {
|
|
2850
|
+
value: omit(this.bindReviewToHasura(reviewData), ['id', 'product_id']),
|
|
2851
|
+
type: 'product_review_set_input',
|
|
2852
|
+
required: true,
|
|
2853
|
+
},
|
|
2854
|
+
})).update_product_review_by_pk);
|
|
2855
|
+
return this.bindReviewToModel((yield this.mutation('insert_product_review_one', this.reviewsFields, {
|
|
2856
|
+
object: {
|
|
2857
|
+
value: omit(Object.assign(Object.assign({}, this.bindReviewToHasura(reviewData)), { product_id: productId }), ['id']),
|
|
2858
|
+
type: 'product_review_insert_input',
|
|
2859
|
+
required: true,
|
|
2860
|
+
},
|
|
2861
|
+
})).insert_product_review_one);
|
|
2862
|
+
})));
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2865
|
+
getId(id) {
|
|
2866
|
+
var _a, _b;
|
|
2867
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2868
|
+
if (!Number.isNaN(+id))
|
|
2869
|
+
return id;
|
|
2870
|
+
const { data } = yield this.find({ filters: { firestoreId: id } });
|
|
2871
|
+
if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
|
|
2872
|
+
return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
|
|
2873
|
+
throw new NotFoundError(`Product with id ${id} not found`);
|
|
2874
|
+
});
|
|
2875
|
+
}
|
|
2876
|
+
findReviewsByProduct(productId) {
|
|
2877
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2878
|
+
const { product_review: data } = yield this.query('product_review', this.reviewsFields, {
|
|
2879
|
+
where: {
|
|
2880
|
+
value: {
|
|
2881
|
+
product_id: { _eq: productId },
|
|
2882
|
+
},
|
|
2883
|
+
type: 'product_review_bool_exp',
|
|
2884
|
+
required: true,
|
|
2885
|
+
},
|
|
2886
|
+
});
|
|
2887
|
+
return data && data.map((review) => this.bindReviewToModel(review));
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
findReview(review, productId) {
|
|
2891
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2892
|
+
if (review.id)
|
|
2893
|
+
return review;
|
|
2894
|
+
let loadedReview;
|
|
2895
|
+
if (review.personId)
|
|
2896
|
+
loadedReview = yield this.getReviewByPersonId(review.personId, productId);
|
|
2897
|
+
if (!loadedReview && review.author && review.email)
|
|
2898
|
+
loadedReview = yield this.getReviewByAuthorAndEmail(review.author, review.email, productId);
|
|
2899
|
+
return loadedReview || review;
|
|
2900
|
+
});
|
|
2901
|
+
}
|
|
2902
|
+
getReviewByPersonId(personId, productId) {
|
|
2903
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2904
|
+
const { product_review: data } = yield this.query('product_review', this.reviewsFields, {
|
|
2905
|
+
where: {
|
|
2906
|
+
value: {
|
|
2907
|
+
product_id: { _eq: productId },
|
|
2908
|
+
person_id: { _eq: personId },
|
|
2909
|
+
},
|
|
2910
|
+
type: `product_review_bool_exp`,
|
|
2911
|
+
required: true,
|
|
2912
|
+
},
|
|
2913
|
+
});
|
|
2914
|
+
return data && data[0] && this.bindReviewToModel(data[0]);
|
|
2915
|
+
});
|
|
2916
|
+
}
|
|
2917
|
+
getReviewByAuthorAndEmail(author, email, productId) {
|
|
2918
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2919
|
+
const { product_review: data } = yield this.query('product_review', this.reviewsFields, {
|
|
2920
|
+
where: {
|
|
2921
|
+
value: {
|
|
2922
|
+
product_id: { _eq: productId },
|
|
2923
|
+
author: { _eq: author },
|
|
2924
|
+
email: { _eq: email },
|
|
2925
|
+
},
|
|
2926
|
+
type: `product_review_bool_exp`,
|
|
2927
|
+
required: true,
|
|
2928
|
+
},
|
|
2929
|
+
});
|
|
2930
|
+
return data && data[0] && this.bindReviewToModel(data[0]);
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
2936
|
+
constructor(endpoint, authOptions) {
|
|
2937
|
+
super({
|
|
2938
|
+
tableName: 'product',
|
|
2939
|
+
model: VariantHasuraGraphQL,
|
|
2335
2940
|
endpoint,
|
|
2336
2941
|
authOptions,
|
|
2337
2942
|
fields: [
|
|
2338
2943
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
2339
|
-
{
|
|
2944
|
+
{ firestoreId: { columnName: 'firestore_id' } },
|
|
2945
|
+
{ productId: { columnName: 'main_product_id', to: (value) => +value, from: (value) => value === null || value === void 0 ? void 0 : value.toString() } },
|
|
2340
2946
|
{ EAN: { columnName: 'ean' } },
|
|
2341
|
-
{ NCM: { columnName: 'ncm' } },
|
|
2342
|
-
'brand',
|
|
2343
2947
|
{ costPrice: { columnName: 'cost_price' } },
|
|
2344
|
-
'description',
|
|
2345
|
-
{ hasVariants: { columnName: 'has_variants' } },
|
|
2346
|
-
'images',
|
|
2347
|
-
'miniatures',
|
|
2348
|
-
'name',
|
|
2349
|
-
{ price: { columnName: 'full_price' } },
|
|
2350
|
-
{ price: { columnName: 'subscriber_discount_percentage' } },
|
|
2351
|
-
{ price: { columnName: 'subscriber_price' } },
|
|
2352
2948
|
{
|
|
2353
2949
|
price: {
|
|
2354
2950
|
columnName: 'price',
|
|
@@ -2358,52 +2954,80 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2358
2954
|
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
2359
2955
|
subscriberPrice: data.subscriber_price,
|
|
2360
2956
|
} })), {}),
|
|
2957
|
+
bindFindFilter: (sentence) => {
|
|
2958
|
+
const filters = Object.values(sentence).shift();
|
|
2959
|
+
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) && {
|
|
2960
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
2961
|
+
})), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
2962
|
+
subscriber_price: filters.subscriberPrice,
|
|
2963
|
+
}));
|
|
2964
|
+
},
|
|
2965
|
+
bindPersistData: (value) => {
|
|
2966
|
+
const priceData = Object.values(value).shift();
|
|
2967
|
+
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 && {
|
|
2968
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
2969
|
+
})), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }));
|
|
2970
|
+
},
|
|
2361
2971
|
},
|
|
2362
2972
|
},
|
|
2363
|
-
'
|
|
2364
|
-
{
|
|
2973
|
+
{ fullPrice: { columnName: 'full_price' } },
|
|
2974
|
+
{ subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
|
|
2975
|
+
{ subscriberPrice: { columnName: 'subscriber_price' } },
|
|
2365
2976
|
'sku',
|
|
2366
2977
|
{
|
|
2367
2978
|
stock: {
|
|
2368
2979
|
columnName: 'stock',
|
|
2369
2980
|
from: (quantity) => ({ quantity }),
|
|
2370
|
-
to: (value) => (value === null || value === void 0 ? void 0 : value.quantity) || value,
|
|
2981
|
+
to: (value) => (isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity),
|
|
2371
2982
|
},
|
|
2372
2983
|
},
|
|
2373
|
-
'type',
|
|
2374
|
-
'video',
|
|
2375
2984
|
'weight',
|
|
2985
|
+
{ name: { to: () => '', from: () => undefined } },
|
|
2986
|
+
{ hasVariants: { columnName: 'has_variants', to: () => false, from: () => undefined } },
|
|
2987
|
+
{ createdAt: { columnName: 'created_at' } },
|
|
2988
|
+
{ updatedAt: { columnName: 'updated_at' } },
|
|
2376
2989
|
{
|
|
2377
|
-
|
|
2378
|
-
columnName: '
|
|
2379
|
-
|
|
2380
|
-
to: (category_id) => +category_id,
|
|
2381
|
-
from: (categories) => (categories === null || categories === void 0 ? void 0 : categories.map((category) => { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || [],
|
|
2382
|
-
},
|
|
2383
|
-
},
|
|
2384
|
-
{
|
|
2385
|
-
shopAvailability: {
|
|
2386
|
-
columnName: 'shop_availabilities',
|
|
2387
|
-
fields: ['shop'],
|
|
2388
|
-
from: (shop) => (Array.isArray(shop) ? shop.map((row) => row.shop) : []),
|
|
2990
|
+
grade: {
|
|
2991
|
+
columnName: 'grade',
|
|
2992
|
+
type: HasuraGraphQLColumnType.Jsonb,
|
|
2389
2993
|
},
|
|
2390
2994
|
},
|
|
2391
|
-
{ tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
2392
|
-
{ createdAt: { columnName: 'created_at' } },
|
|
2393
|
-
{ updatedAt: { columnName: 'updated_at' } },
|
|
2394
2995
|
],
|
|
2395
2996
|
});
|
|
2396
2997
|
}
|
|
2397
|
-
|
|
2998
|
+
get(identifiers) {
|
|
2999
|
+
const _super = Object.create(null, {
|
|
3000
|
+
get: { get: () => super.get }
|
|
3001
|
+
});
|
|
2398
3002
|
var _a;
|
|
2399
3003
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2400
|
-
|
|
2401
|
-
filters: {
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
3004
|
+
return Number.isNaN(+identifiers.id)
|
|
3005
|
+
? (_a = (yield this.find({ filters: { firestoreId: identifiers.id } })).data) === null || _a === void 0 ? void 0 : _a[0]
|
|
3006
|
+
: _super.get.call(this, identifiers);
|
|
3007
|
+
});
|
|
3008
|
+
}
|
|
3009
|
+
update(params) {
|
|
3010
|
+
const _super = Object.create(null, {
|
|
3011
|
+
update: { get: () => super.update }
|
|
3012
|
+
});
|
|
3013
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3014
|
+
const { productId, id: checkId } = params, data = __rest(params, ["productId", "id"]);
|
|
3015
|
+
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
3016
|
+
const id = yield this.getId(dataWithProductId.id);
|
|
3017
|
+
const product = yield _super.update.call(this, Object.assign({ id }, data));
|
|
3018
|
+
product.productId = dataWithProductId.productId;
|
|
3019
|
+
return product;
|
|
3020
|
+
});
|
|
3021
|
+
}
|
|
3022
|
+
getId(id) {
|
|
3023
|
+
var _a, _b;
|
|
3024
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3025
|
+
if (!Number.isNaN(+id))
|
|
3026
|
+
return id;
|
|
3027
|
+
const { data } = yield this.find({ filters: { firestoreId: id } });
|
|
3028
|
+
if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
|
|
3029
|
+
return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
|
|
3030
|
+
throw new NotFoundError(`Product with id ${id} not found`);
|
|
2407
3031
|
});
|
|
2408
3032
|
}
|
|
2409
3033
|
}
|
|
@@ -2412,5 +3036,5 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2412
3036
|
* Generated bundle index. Do not edit.
|
|
2413
3037
|
*/
|
|
2414
3038
|
|
|
2415
|
-
export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FinancialCoupon, FragranceImportances, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserSearchFirestoreRepository, UserType, Variant, WeakPasswordError, Where, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
|
|
3039
|
+
export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FinancialCoupon, FragranceImportances, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserSearchFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
|
|
2416
3040
|
//# sourceMappingURL=infrab4a-connect.js.map
|