@infrab4a/connect 4.0.0-beta.19 → 4.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/domain/catalog/models/category.d.ts +4 -0
- package/domain/catalog/models/product.d.ts +6 -1
- package/domain/catalog/models/types/index.d.ts +1 -0
- package/domain/catalog/models/types/product-evaluation.type.d.ts +6 -0
- package/domain/users/models/lead.d.ts +1 -0
- package/esm2020/domain/catalog/models/category.mjs +5 -1
- package/esm2020/domain/catalog/models/product.mjs +24 -1
- package/esm2020/domain/catalog/models/types/index.mjs +2 -1
- package/esm2020/domain/catalog/models/types/product-evaluation.type.mjs +2 -0
- package/esm2020/domain/users/models/lead.mjs +1 -1
- package/esm2020/infra/elasticsearch/adapters/axios.adapter.mjs +28 -11
- package/esm2020/infra/elasticsearch/adapters/elastic-search.adapter.mjs +1 -1
- package/esm2020/infra/elasticsearch/indexes/products-index.mjs +58 -52
- package/esm2020/infra/elasticsearch/types/elastic-search-result.mjs +1 -1
- package/esm2020/infra/hasura-graphql/mixins/helpers/graphql-field.helper.mjs +8 -5
- package/esm2020/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.mjs +2 -2
- package/esm2020/infra/hasura-graphql/models/product-hasura-graphql.mjs +1 -1
- package/esm2020/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.mjs +2 -1
- package/esm2020/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.mjs +12 -1
- package/esm2020/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.mjs +2 -1
- package/esm2020/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.mjs +2 -1
- package/esm2020/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.mjs +19 -11
- package/fesm2015/infrab4a-connect.mjs +152 -72
- package/fesm2015/infrab4a-connect.mjs.map +1 -1
- package/fesm2020/infrab4a-connect.mjs +149 -75
- package/fesm2020/infrab4a-connect.mjs.map +1 -1
- package/infra/elasticsearch/adapters/axios.adapter.d.ts +6 -4
- package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +3 -2
- package/infra/elasticsearch/indexes/products-index.d.ts +8 -10
- package/infra/elasticsearch/types/elastic-search-result.d.ts +2 -0
- package/infra/hasura-graphql/models/product-hasura-graphql.d.ts +1 -0
- package/package.json +1 -1
|
@@ -776,6 +776,10 @@ class Category extends BaseModel {
|
|
|
776
776
|
return ['id'];
|
|
777
777
|
}
|
|
778
778
|
}
|
|
779
|
+
__decorate([
|
|
780
|
+
Type(() => Category),
|
|
781
|
+
__metadata("design:type", Category)
|
|
782
|
+
], Category.prototype, "parent", void 0);
|
|
779
783
|
__decorate([
|
|
780
784
|
Type(() => Filter),
|
|
781
785
|
__metadata("design:type", Array)
|
|
@@ -816,6 +820,24 @@ class FilterOption extends BaseModel {
|
|
|
816
820
|
}
|
|
817
821
|
|
|
818
822
|
class Product extends BaseModel {
|
|
823
|
+
get evaluation() {
|
|
824
|
+
return {
|
|
825
|
+
reviews: this.reviews,
|
|
826
|
+
count: this.reviewsTotal,
|
|
827
|
+
rating: this.rate,
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
set evaluation(evaluation) {
|
|
831
|
+
if (!evaluation) {
|
|
832
|
+
this.reviews = null;
|
|
833
|
+
this.reviewsTotal = null;
|
|
834
|
+
this.rate = null;
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
this.reviews = evaluation.reviews || this.reviews;
|
|
838
|
+
this.reviewsTotal = evaluation.count || this.reviewsTotal;
|
|
839
|
+
this.rate = evaluation.rating || this.rate;
|
|
840
|
+
}
|
|
819
841
|
identifierFields() {
|
|
820
842
|
return ['id'];
|
|
821
843
|
}
|
|
@@ -823,6 +845,10 @@ class Product extends BaseModel {
|
|
|
823
845
|
return ['id'];
|
|
824
846
|
}
|
|
825
847
|
}
|
|
848
|
+
__decorate([
|
|
849
|
+
Type(() => Category),
|
|
850
|
+
__metadata("design:type", Category)
|
|
851
|
+
], Product.prototype, "category", void 0);
|
|
826
852
|
__decorate([
|
|
827
853
|
Type(() => KitProduct),
|
|
828
854
|
__metadata("design:type", Array)
|
|
@@ -1088,12 +1114,16 @@ class AxiosAdapter {
|
|
|
1088
1114
|
constructor(config) {
|
|
1089
1115
|
this.config = config;
|
|
1090
1116
|
}
|
|
1091
|
-
async get(index) {
|
|
1117
|
+
async get(index, id) {
|
|
1092
1118
|
try {
|
|
1093
1119
|
const { data } = await axios({
|
|
1094
|
-
url: `${this.config.url}/${index}`,
|
|
1120
|
+
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
1095
1121
|
method: 'GET',
|
|
1096
|
-
|
|
1122
|
+
responseType: 'json',
|
|
1123
|
+
headers: {
|
|
1124
|
+
'Content-Type': 'application/json',
|
|
1125
|
+
Authorization: `ApiKey ${this.config.credential}`,
|
|
1126
|
+
},
|
|
1097
1127
|
});
|
|
1098
1128
|
return data._source;
|
|
1099
1129
|
}
|
|
@@ -1105,9 +1135,14 @@ class AxiosAdapter {
|
|
|
1105
1135
|
}
|
|
1106
1136
|
async query(index, query) {
|
|
1107
1137
|
const { data } = await axios({
|
|
1108
|
-
url: `${this.config.url}/${index}`,
|
|
1138
|
+
url: `${this.config.url}/${index}/_search`,
|
|
1109
1139
|
method: 'POST',
|
|
1110
|
-
|
|
1140
|
+
responseType: 'json',
|
|
1141
|
+
headers: {
|
|
1142
|
+
Accept: 'application/vnd.elasticsearch+json;compatible-with=7',
|
|
1143
|
+
'Content-Type': 'application/vnd.elasticsearch+json;compatible-with=7',
|
|
1144
|
+
Authorization: `ApiKey ${this.config.credential}`,
|
|
1145
|
+
},
|
|
1111
1146
|
data: query,
|
|
1112
1147
|
});
|
|
1113
1148
|
return {
|
|
@@ -1117,17 +1152,25 @@ class AxiosAdapter {
|
|
|
1117
1152
|
}
|
|
1118
1153
|
async save(index, data) {
|
|
1119
1154
|
await axios({
|
|
1120
|
-
url: `${this.config.url}/${index}`,
|
|
1155
|
+
url: `${this.config.url}/${index}/_doc`,
|
|
1156
|
+
method: 'POST',
|
|
1157
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1158
|
+
data,
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
async update(index, id, data) {
|
|
1162
|
+
await axios({
|
|
1163
|
+
url: `${this.config.url}/${index}/_update/${id}`,
|
|
1121
1164
|
method: 'PUT',
|
|
1122
|
-
headers: { Authorization: `
|
|
1165
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1123
1166
|
data,
|
|
1124
1167
|
});
|
|
1125
1168
|
}
|
|
1126
|
-
async delete(index) {
|
|
1169
|
+
async delete(index, id) {
|
|
1127
1170
|
await axios({
|
|
1128
|
-
url: `${this.config.url}/${index}`,
|
|
1171
|
+
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
1129
1172
|
method: 'DELETE',
|
|
1130
|
-
headers: { Authorization: `
|
|
1173
|
+
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
1131
1174
|
});
|
|
1132
1175
|
}
|
|
1133
1176
|
}
|
|
@@ -1135,13 +1178,16 @@ class AxiosAdapter {
|
|
|
1135
1178
|
class ProductsIndex {
|
|
1136
1179
|
constructor(adapter) {
|
|
1137
1180
|
this.adapter = adapter;
|
|
1181
|
+
this.index = `products`;
|
|
1138
1182
|
}
|
|
1139
|
-
async
|
|
1140
|
-
const data = await this.adapter.get(
|
|
1183
|
+
async getById(id) {
|
|
1184
|
+
const data = await this.adapter.get(this.index, id);
|
|
1141
1185
|
return Product.toInstance(data);
|
|
1142
1186
|
}
|
|
1143
|
-
async
|
|
1187
|
+
async search(searchTerm, total, shop) {
|
|
1188
|
+
const size = total >= 10 ? 500 : 9;
|
|
1144
1189
|
const fields = [
|
|
1190
|
+
'EAN',
|
|
1145
1191
|
'brand',
|
|
1146
1192
|
'id',
|
|
1147
1193
|
'images',
|
|
@@ -1152,74 +1198,77 @@ class ProductsIndex {
|
|
|
1152
1198
|
'stock',
|
|
1153
1199
|
'slug',
|
|
1154
1200
|
'reviews',
|
|
1155
|
-
'pricePaid',
|
|
1156
|
-
'isGift',
|
|
1157
|
-
'stock',
|
|
1158
|
-
'weight',
|
|
1159
|
-
'tags',
|
|
1160
|
-
'filters',
|
|
1161
1201
|
'hasVariants',
|
|
1162
|
-
'
|
|
1202
|
+
'rate',
|
|
1163
1203
|
];
|
|
1164
|
-
const {
|
|
1204
|
+
const filter = [{ term: { published: true } }];
|
|
1205
|
+
if (size > 9) {
|
|
1206
|
+
fields.push(...['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
|
|
1207
|
+
}
|
|
1208
|
+
else {
|
|
1209
|
+
filter.push({ term: { tags: shop == Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
|
|
1210
|
+
}
|
|
1211
|
+
const search = await this.adapter.query(this.index, {
|
|
1212
|
+
size,
|
|
1165
1213
|
_source: fields,
|
|
1166
1214
|
query: {
|
|
1167
1215
|
bool: {
|
|
1168
|
-
|
|
1169
|
-
{
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1216
|
+
must: {
|
|
1217
|
+
multi_match: {
|
|
1218
|
+
query: `${searchTerm}`,
|
|
1219
|
+
type: 'bool_prefix',
|
|
1220
|
+
fields: [
|
|
1221
|
+
'name',
|
|
1222
|
+
'name.folded',
|
|
1223
|
+
'name.search',
|
|
1224
|
+
'description',
|
|
1225
|
+
'description.search',
|
|
1226
|
+
'description.folded',
|
|
1227
|
+
'brand',
|
|
1228
|
+
'brand.search',
|
|
1229
|
+
'brand.folded',
|
|
1230
|
+
],
|
|
1231
|
+
fuzziness: 2,
|
|
1173
1232
|
},
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1233
|
+
},
|
|
1234
|
+
should: {
|
|
1235
|
+
match_phrase_prefix: {
|
|
1236
|
+
'name.search': {
|
|
1237
|
+
query: `${searchTerm}`,
|
|
1238
|
+
slop: 10,
|
|
1177
1239
|
},
|
|
1178
1240
|
},
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
{
|
|
1182
|
-
range: {
|
|
1183
|
-
'stock.quantity': {
|
|
1184
|
-
gt: 0,
|
|
1185
|
-
},
|
|
1186
|
-
},
|
|
1187
|
-
},
|
|
1188
|
-
]
|
|
1189
|
-
: []),
|
|
1190
|
-
],
|
|
1241
|
+
},
|
|
1242
|
+
filter,
|
|
1191
1243
|
},
|
|
1192
1244
|
},
|
|
1193
|
-
...(options?.size ? { size: options?.size } : {}),
|
|
1194
1245
|
});
|
|
1195
|
-
|
|
1246
|
+
search.hits = search.hits.filter((e) => e._source.name !== '');
|
|
1247
|
+
return search;
|
|
1196
1248
|
}
|
|
1197
1249
|
async save(product) {
|
|
1198
|
-
delete product.createdAt;
|
|
1199
|
-
delete product.updatedAt;
|
|
1200
|
-
delete product.kitProducts;
|
|
1201
1250
|
try {
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
await this.get(product.firestoreId);
|
|
1205
|
-
await this.adapter.save(`products/_doc/${product.firestoreId}`, product.toPlain());
|
|
1251
|
+
const { createdAt, updatedAt, kitProducts, ...data } = product;
|
|
1252
|
+
this.adapter.save(this.index, data);
|
|
1206
1253
|
}
|
|
1207
1254
|
catch (error) {
|
|
1208
|
-
|
|
1209
|
-
throw error;
|
|
1210
|
-
console.error(error.message);
|
|
1211
|
-
await this.adapter.save(`products/_doc/${product.id}`, product.toPlain());
|
|
1255
|
+
console.error(error);
|
|
1212
1256
|
}
|
|
1213
1257
|
}
|
|
1214
|
-
async
|
|
1215
|
-
|
|
1216
|
-
|
|
1258
|
+
async update(product) {
|
|
1259
|
+
try {
|
|
1260
|
+
await this.adapter.update(this.index, product.id, product);
|
|
1261
|
+
}
|
|
1262
|
+
catch (error) {
|
|
1263
|
+
console.error(error);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
async delete(id) {
|
|
1217
1267
|
try {
|
|
1218
|
-
await this.
|
|
1219
|
-
await this.adapter.delete(`products/_doc/${product.firestoreId}`);
|
|
1268
|
+
await this.adapter.delete(this.index, id);
|
|
1220
1269
|
}
|
|
1221
1270
|
catch (error) {
|
|
1222
|
-
|
|
1271
|
+
console.error(error);
|
|
1223
1272
|
}
|
|
1224
1273
|
}
|
|
1225
1274
|
}
|
|
@@ -2329,10 +2378,13 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
|
2329
2378
|
if (!!foreignKeyColumn &&
|
|
2330
2379
|
!isEmpty(foreignKeyColumn) &&
|
|
2331
2380
|
!Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
|
|
2332
|
-
return Object.keys(foreignKeyColumn).reduce((object, current) =>
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2381
|
+
return Object.keys(foreignKeyColumn).reduce((object, current) => {
|
|
2382
|
+
const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
|
|
2383
|
+
return {
|
|
2384
|
+
...object,
|
|
2385
|
+
[foreignColumnName]: data[attributeName]?.[current],
|
|
2386
|
+
};
|
|
2387
|
+
}, { ...result });
|
|
2336
2388
|
if (update &&
|
|
2337
2389
|
isObject(data[attributeName]) &&
|
|
2338
2390
|
!isNil(attributeFields) &&
|
|
@@ -2385,7 +2437,7 @@ const withCreateHasuraGraphQL = (MixinBase) => {
|
|
|
2385
2437
|
const columnOptions = Object.values(field).shift();
|
|
2386
2438
|
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
2387
2439
|
columnOptions.foreignKeyColumn && [
|
|
2388
|
-
...Object.values(columnOptions.foreignKeyColumn),
|
|
2440
|
+
...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => AttributeOptionHelper.FindByAttribute(foreignKeyName, this.fields)?.columnName),
|
|
2389
2441
|
{
|
|
2390
2442
|
[columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)?.columnName ||
|
|
2391
2443
|
foreignKeyField),
|
|
@@ -2704,6 +2756,7 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
|
|
|
2704
2756
|
model: CategoryFilter,
|
|
2705
2757
|
endpoint,
|
|
2706
2758
|
authOptions,
|
|
2759
|
+
interceptors,
|
|
2707
2760
|
fields: [
|
|
2708
2761
|
'id',
|
|
2709
2762
|
{ filterId: { columnName: 'filter_id' } },
|
|
@@ -2825,6 +2878,16 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2825
2878
|
}),
|
|
2826
2879
|
},
|
|
2827
2880
|
},
|
|
2881
|
+
{ isCollection: { columnName: 'is_collection' } },
|
|
2882
|
+
'reference',
|
|
2883
|
+
{ parentId: { columnName: 'parent_id' } },
|
|
2884
|
+
{
|
|
2885
|
+
parent: {
|
|
2886
|
+
columnName: 'parent',
|
|
2887
|
+
foreignKeyColumn: { id: 'parentId' },
|
|
2888
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
2889
|
+
},
|
|
2890
|
+
},
|
|
2828
2891
|
],
|
|
2829
2892
|
});
|
|
2830
2893
|
this.productRepository = productRepository;
|
|
@@ -2917,6 +2980,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
2917
2980
|
'type',
|
|
2918
2981
|
'shoppingCount',
|
|
2919
2982
|
'gender',
|
|
2983
|
+
'createdAt',
|
|
2920
2984
|
],
|
|
2921
2985
|
...(options?.limit ? { limits: { limit: options?.limit } } : {}),
|
|
2922
2986
|
options: { enableCount: false },
|
|
@@ -3056,6 +3120,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
3056
3120
|
model: Filter,
|
|
3057
3121
|
endpoint,
|
|
3058
3122
|
authOptions,
|
|
3123
|
+
interceptors,
|
|
3059
3124
|
fields: [
|
|
3060
3125
|
'id',
|
|
3061
3126
|
'description',
|
|
@@ -3157,6 +3222,7 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
|
|
|
3157
3222
|
model: FilterOption,
|
|
3158
3223
|
endpoint,
|
|
3159
3224
|
authOptions,
|
|
3225
|
+
interceptors,
|
|
3160
3226
|
fields: [
|
|
3161
3227
|
'id',
|
|
3162
3228
|
'description',
|
|
@@ -3308,18 +3374,17 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
3308
3374
|
{ isKit: { columnName: 'is_kit' } },
|
|
3309
3375
|
{ createdAt: { columnName: 'created_at' } },
|
|
3310
3376
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
3377
|
+
{ rate: { columnName: 'rating' } },
|
|
3378
|
+
{ reviewsTotal: { columnName: 'reviews_total' } },
|
|
3379
|
+
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
3380
|
+
{ categoryId: { columnName: 'category_id' } },
|
|
3311
3381
|
{
|
|
3312
|
-
|
|
3313
|
-
columnName: '
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
filterType: 'product_review_bool_exp',
|
|
3317
|
-
},
|
|
3318
|
-
fields: [{ aggregate: [{ avg: ['rate'] }] }],
|
|
3319
|
-
from: (value) => value.aggregate.avg.rate,
|
|
3382
|
+
category: {
|
|
3383
|
+
columnName: 'category',
|
|
3384
|
+
foreignKeyColumn: { id: 'categoryId' },
|
|
3385
|
+
fields: ['id', 'name', 'reference', 'slug'],
|
|
3320
3386
|
},
|
|
3321
3387
|
},
|
|
3322
|
-
{ shoppingCount: { columnName: 'shopping_count' } },
|
|
3323
3388
|
];
|
|
3324
3389
|
this.fields = [
|
|
3325
3390
|
...commonFields,
|
|
@@ -3412,7 +3477,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
3412
3477
|
return super.find({
|
|
3413
3478
|
...options,
|
|
3414
3479
|
filters: { ...filters, productId: { operator: Where.ISNULL } },
|
|
3415
|
-
fields:
|
|
3480
|
+
fields: [
|
|
3481
|
+
...bindFields,
|
|
3482
|
+
...(bindFields.includes('price')
|
|
3483
|
+
? [
|
|
3484
|
+
'subscriberPrice',
|
|
3485
|
+
'subscriberDiscountPercentage',
|
|
3486
|
+
'fullPrice',
|
|
3487
|
+
]
|
|
3488
|
+
: []),
|
|
3489
|
+
],
|
|
3416
3490
|
});
|
|
3417
3491
|
}
|
|
3418
3492
|
async getBySlug(slug) {
|