@infrab4a/connect 4.25.0-beta.1 → 4.25.0-beta.11
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/index.cjs.js +1004 -608
- package/index.esm.js +1005 -608
- package/package.json +1 -1
- package/src/domain/catalog/repositories/category.repository.d.ts +15 -4
- package/src/domain/catalog/repositories/product.repository.d.ts +13 -5
- package/src/domain/general/cacheadapter.d.ts +11 -0
- package/src/domain/general/index.d.ts +1 -0
- package/src/domain/general/models/index.d.ts +0 -1
- package/src/domain/general/repositories/index.d.ts +0 -1
- package/src/domain/generic/repository/find.repository.d.ts +4 -2
- package/src/domain/generic/repository/get.repository.d.ts +4 -1
- package/src/domain/generic/repository/types/index.d.ts +3 -2
- package/src/domain/generic/repository/types/repository-cache-options.type.d.ts +9 -0
- package/src/infra/cache/index.d.ts +1 -0
- package/src/infra/cache/restcache.adapter.d.ts +15 -0
- package/src/infra/firebase/firestore/mixins/helpers/cache-key-generator.helper.d.ts +9 -0
- package/src/infra/firebase/firestore/mixins/helpers/index.d.ts +1 -0
- package/src/infra/firebase/firestore/mixins/with-firestore.mixin.d.ts +2 -1
- package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/general/index.d.ts +0 -1
- package/src/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/subscription-materialization-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/subscription-summary-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +1 -1
- package/src/infra/firebase/firestore/types/firestore.repository.type.d.ts +2 -1
- package/src/infra/hasura-graphql/mixins/helpers/cache-key-generator.helper.d.ts +6 -0
- package/src/infra/hasura-graphql/mixins/helpers/index.d.ts +2 -0
- package/src/infra/hasura-graphql/mixins/helpers/md5-generator.helper.d.ts +4 -0
- package/src/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +22 -3
- package/src/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +6 -2
- package/src/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.d.ts +2 -1
- package/src/infra/hasura-graphql/repositories/catalog/category-collection-children-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +20 -7
- package/src/infra/hasura-graphql/repositories/catalog/category-product-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/product-errors-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +20 -8
- package/src/infra/hasura-graphql/repositories/catalog/product-review-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/product-stock-notification-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +1 -1
- package/src/infra/hasura-graphql/types/graphql.repository.type.d.ts +2 -1
- package/src/infra/index.d.ts +1 -0
- package/src/domain/general/enums/index.d.ts +0 -1
- package/src/domain/general/enums/queue-status.enum.d.ts +0 -6
- package/src/domain/general/models/product-queue.d.ts +0 -15
- package/src/domain/general/repositories/product-queue.repository.d.ts +0 -4
- package/src/domain/general/types/index.d.ts +0 -1
- package/src/domain/general/types/queue-status.type.d.ts +0 -2
- package/src/infra/firebase/firestore/repositories/general/product-queue.repository.d.ts +0 -7
package/index.cjs.js
CHANGED
|
@@ -11,6 +11,7 @@ var debug = require('debug');
|
|
|
11
11
|
var tsCustomError = require('ts-custom-error');
|
|
12
12
|
var axios = require('axios');
|
|
13
13
|
var auth = require('firebase/auth');
|
|
14
|
+
var tsMd5 = require('ts-md5');
|
|
14
15
|
var firestore = require('firebase/firestore');
|
|
15
16
|
var storage = require('firebase/storage');
|
|
16
17
|
var gqlQueryBuilder = require('gql-query-builder');
|
|
@@ -2558,6 +2559,7 @@ class GlampointsPaymentService {
|
|
|
2558
2559
|
console.error('[rewards - rewardByOrder] reward request error', error.response.status, JSON.stringify(error.response.data.message), order.orderNumber);
|
|
2559
2560
|
else
|
|
2560
2561
|
console.log(JSON.stringify(error));
|
|
2562
|
+
throw new Error(`Reward errors: ${error.response.data.message}`);
|
|
2561
2563
|
}
|
|
2562
2564
|
}
|
|
2563
2565
|
async negativateRewardByOrderId(order) {
|
|
@@ -2610,12 +2612,6 @@ class LogDocument extends BaseModel {
|
|
|
2610
2612
|
}
|
|
2611
2613
|
}
|
|
2612
2614
|
|
|
2613
|
-
class ProductQueue extends BaseModel {
|
|
2614
|
-
static get identifiersFields() {
|
|
2615
|
-
return ['id'];
|
|
2616
|
-
}
|
|
2617
|
-
}
|
|
2618
|
-
|
|
2619
2615
|
class Sequence extends BaseModel {
|
|
2620
2616
|
static get identifiersFields() {
|
|
2621
2617
|
return ['id'];
|
|
@@ -2839,6 +2835,71 @@ class AdyenCardAxiosAdapter {
|
|
|
2839
2835
|
}
|
|
2840
2836
|
}
|
|
2841
2837
|
|
|
2838
|
+
class RestCacheAdapter {
|
|
2839
|
+
constructor(config) {
|
|
2840
|
+
this.logger = new DebugHelper('RestCacheAdapter');
|
|
2841
|
+
this.client = axios__default["default"].create({
|
|
2842
|
+
baseURL: config.baseURL,
|
|
2843
|
+
headers: Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (lodash.isNil(config.authToken) ? {} : { Authorization: `Bearer ${config.authToken}` })), (lodash.isNil(config.mobileApiKey) ? {} : { 'X-Mobile-API-Key': config.mobileApiKey })),
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2846
|
+
async set(options) {
|
|
2847
|
+
try {
|
|
2848
|
+
const response = await this.client.post('/redis/set', {
|
|
2849
|
+
key: options.key,
|
|
2850
|
+
data: options.data,
|
|
2851
|
+
ex: options.expirationInSeconds,
|
|
2852
|
+
});
|
|
2853
|
+
return response.data.success;
|
|
2854
|
+
}
|
|
2855
|
+
catch (error) {
|
|
2856
|
+
if (error instanceof Error)
|
|
2857
|
+
this.logger.error(new Error(`[RestCacheAdapter] Erro ao definir cache: ${error.message}`));
|
|
2858
|
+
return false;
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
async get(key) {
|
|
2862
|
+
try {
|
|
2863
|
+
const response = await this.client.post('/redis/get', {
|
|
2864
|
+
key,
|
|
2865
|
+
});
|
|
2866
|
+
if (response.data.success) {
|
|
2867
|
+
return response.data.data;
|
|
2868
|
+
}
|
|
2869
|
+
return null;
|
|
2870
|
+
}
|
|
2871
|
+
catch (error) {
|
|
2872
|
+
if (error instanceof Error)
|
|
2873
|
+
this.logger.error(new Error(`[RestCacheAdapter] Erro ao recuperar cache: ${error.message}`));
|
|
2874
|
+
return null;
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
async remove(key) {
|
|
2878
|
+
try {
|
|
2879
|
+
const response = await this.client.post('/redis/del', {
|
|
2880
|
+
key,
|
|
2881
|
+
});
|
|
2882
|
+
return response.data.success;
|
|
2883
|
+
}
|
|
2884
|
+
catch (error) {
|
|
2885
|
+
if (error instanceof Error)
|
|
2886
|
+
this.logger.error(new Error(`[RestCacheAdapter] Erro ao remover cache: ${error.message}`));
|
|
2887
|
+
return false;
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
async clear() {
|
|
2891
|
+
try {
|
|
2892
|
+
const response = await this.client.post('/redis/flushdb', {});
|
|
2893
|
+
return response.data.success;
|
|
2894
|
+
}
|
|
2895
|
+
catch (error) {
|
|
2896
|
+
if (error instanceof Error)
|
|
2897
|
+
this.logger.error(new Error(`[RestCacheAdapter] Erro ao limpar cache: ${error.message}`));
|
|
2898
|
+
return false;
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
|
|
2842
2903
|
class AxiosAdapter {
|
|
2843
2904
|
constructor(config) {
|
|
2844
2905
|
this.config = config;
|
|
@@ -3175,6 +3236,7 @@ const withFirestore = (MixinBase) => {
|
|
|
3175
3236
|
this.fields = options.fields;
|
|
3176
3237
|
this.interceptors = options.interceptors;
|
|
3177
3238
|
this.logger = DebugHelper.from(this);
|
|
3239
|
+
this.cache = options.cache;
|
|
3178
3240
|
}
|
|
3179
3241
|
collection(path) {
|
|
3180
3242
|
return this.firestore.getCollection(path || this.collectionName).withConverter(this.buildModelInstance());
|
|
@@ -3221,123 +3283,487 @@ const withHelpers = (MixinBase) => {
|
|
|
3221
3283
|
};
|
|
3222
3284
|
};
|
|
3223
3285
|
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
? `${this.parentRepository.collectionName}/${identifiers[this.parentIdField]}/${this.collectionName}`
|
|
3254
|
-
: this.collectionName;
|
|
3255
|
-
}
|
|
3256
|
-
};
|
|
3286
|
+
class AttributeOptionHelper {
|
|
3287
|
+
}
|
|
3288
|
+
AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
3289
|
+
var _a;
|
|
3290
|
+
if (fields.includes(attributeName))
|
|
3291
|
+
return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
|
|
3292
|
+
const field = fields.find((columnOption) => lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
3293
|
+
const fieldOption = (_a = is(field)) === null || _a === void 0 ? void 0 : _a[attributeName];
|
|
3294
|
+
if (lodash.isNil(fieldOption))
|
|
3295
|
+
return { columnName: attributeName.toString(), attributeName };
|
|
3296
|
+
if (Array.isArray(fieldOption))
|
|
3297
|
+
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
3298
|
+
return Object.assign({ attributeName, columnName: attributeName.toString() }, fieldOption);
|
|
3299
|
+
};
|
|
3300
|
+
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.columnName);
|
|
3301
|
+
AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
3302
|
+
if (fields.includes(columnName))
|
|
3303
|
+
return { columnName, attributeName: columnName };
|
|
3304
|
+
const field = is(fields.find((field) => {
|
|
3305
|
+
if (!lodash.isObject(field))
|
|
3306
|
+
return false;
|
|
3307
|
+
const columnOption = Object.values(field).find((option) => AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName ? option : {});
|
|
3308
|
+
return AttributeOptionHelper.CheckIsColumnOption(columnOption) && (columnOption === null || columnOption === void 0 ? void 0 : columnOption.columnName) === columnName;
|
|
3309
|
+
}) || {});
|
|
3310
|
+
const attributeName = Object.keys(field).find((fieldOptionFromList) => AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) || Array.isArray(field[fieldOptionFromList]));
|
|
3311
|
+
const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
|
|
3312
|
+
if (Array.isArray(fieldOption))
|
|
3313
|
+
return { attributeName: attributeName, fields: fieldOption };
|
|
3314
|
+
return Object.assign({ attributeName: attributeName || columnName, columnName }, fieldOption);
|
|
3257
3315
|
};
|
|
3258
3316
|
|
|
3259
|
-
var
|
|
3260
|
-
(function (
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3317
|
+
var HasuraGraphQLWhere;
|
|
3318
|
+
(function (HasuraGraphQLWhere) {
|
|
3319
|
+
HasuraGraphQLWhere["EQUALS"] = "_eq";
|
|
3320
|
+
HasuraGraphQLWhere["GT"] = "_gt";
|
|
3321
|
+
HasuraGraphQLWhere["GTE"] = "_gte";
|
|
3322
|
+
HasuraGraphQLWhere["IN"] = "_in";
|
|
3323
|
+
HasuraGraphQLWhere["NOTIN"] = "_nin";
|
|
3324
|
+
HasuraGraphQLWhere["LT"] = "_lt";
|
|
3325
|
+
HasuraGraphQLWhere["LTE"] = "_lte";
|
|
3326
|
+
HasuraGraphQLWhere["LIKE"] = "_like";
|
|
3327
|
+
HasuraGraphQLWhere["ILIKE"] = "_ilike";
|
|
3328
|
+
HasuraGraphQLWhere["NOTLIKE"] = "_nlike";
|
|
3329
|
+
HasuraGraphQLWhere["ISNULL"] = "_is_null";
|
|
3330
|
+
HasuraGraphQLWhere["ISNOTNULL"] = "_is_null";
|
|
3331
|
+
HasuraGraphQLWhere["JSON_CONTAINS"] = "_contains";
|
|
3332
|
+
HasuraGraphQLWhere["JSON_HAS_KEYS_ANY"] = "_has_keys_any";
|
|
3333
|
+
HasuraGraphQLWhere["IREGEX"] = "_iregex";
|
|
3334
|
+
HasuraGraphQLWhere["REGEX"] = "_regex";
|
|
3335
|
+
})(HasuraGraphQLWhere || (HasuraGraphQLWhere = {}));
|
|
3268
3336
|
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
return Object.keys(fieldsToOrderBy).map((fieldName) => [
|
|
3327
|
-
fieldName,
|
|
3328
|
-
fieldsToOrderBy[fieldName],
|
|
3329
|
-
]);
|
|
3337
|
+
var HasuraGraphQLColumnType;
|
|
3338
|
+
(function (HasuraGraphQLColumnType) {
|
|
3339
|
+
HasuraGraphQLColumnType["Int"] = "Int";
|
|
3340
|
+
HasuraGraphQLColumnType["Float"] = "Float";
|
|
3341
|
+
HasuraGraphQLColumnType["Boolean"] = "Boolean";
|
|
3342
|
+
HasuraGraphQLColumnType["String"] = "String";
|
|
3343
|
+
HasuraGraphQLColumnType["DateTime"] = "timestampz";
|
|
3344
|
+
HasuraGraphQLColumnType["Json"] = "json";
|
|
3345
|
+
HasuraGraphQLColumnType["Jsonb"] = "jsonb";
|
|
3346
|
+
HasuraGraphQLColumnType["Enum"] = "enum";
|
|
3347
|
+
HasuraGraphQLColumnType["Uuid"] = "uuid";
|
|
3348
|
+
})(HasuraGraphQLColumnType || (HasuraGraphQLColumnType = {}));
|
|
3349
|
+
|
|
3350
|
+
class FilterOptionHelper {
|
|
3351
|
+
}
|
|
3352
|
+
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
|
|
3353
|
+
FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
|
|
3354
|
+
if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
|
|
3355
|
+
return filter;
|
|
3356
|
+
if (filter.operator === exports.Where.ISNULL)
|
|
3357
|
+
return true;
|
|
3358
|
+
if (filter.operator === exports.Where.ISNOTNULL)
|
|
3359
|
+
return false;
|
|
3360
|
+
const converter = fieldOption.to
|
|
3361
|
+
? fieldOption.to
|
|
3362
|
+
: (value) => filter.operator === exports.Where.LIKE && !Array.isArray(filter.value) && value.indexOf('%') < 0
|
|
3363
|
+
? `%${value}%`
|
|
3364
|
+
: value;
|
|
3365
|
+
const converterResult = Array.isArray(filter.value) && !fieldOption.fields && [exports.Where.IN, exports.Where.NOTIN].includes(filter.operator)
|
|
3366
|
+
? filter.value.map((fieldValue) => converter(fieldValue))
|
|
3367
|
+
: converter(filter.value);
|
|
3368
|
+
const newValue = filter.ignoreCase && !filter.ignoreAccent && !Array.isArray(filter.value) && converterResult.indexOf('%') < 0
|
|
3369
|
+
? `%${converterResult}%`
|
|
3370
|
+
: converterResult;
|
|
3371
|
+
return filter.ignoreAccent && !Array.isArray(filter.value)
|
|
3372
|
+
? FilterOptionHelper.buildInsensitiveSentence(newValue)
|
|
3373
|
+
: newValue;
|
|
3374
|
+
};
|
|
3375
|
+
FilterOptionHelper.buildInsensitiveSentence = (value) => {
|
|
3376
|
+
const valueWithoutAccents = FilterOptionHelper.removeAccents(value);
|
|
3377
|
+
let result = '';
|
|
3378
|
+
for (const char of valueWithoutAccents) {
|
|
3379
|
+
const allCharOptions = [];
|
|
3380
|
+
if (['a', 'e', 'i', 'o', 'u', 'c', 'A', 'E', 'I', 'O', 'U', 'C'].includes(char)) {
|
|
3381
|
+
const charOptions = {
|
|
3382
|
+
a: ['á', 'â', 'ã', 'à', 'a'],
|
|
3383
|
+
e: ['é', 'ê', 'ẽ', 'è', 'e'],
|
|
3384
|
+
i: ['í', 'î', 'ĩ', 'ì', 'i'],
|
|
3385
|
+
o: ['ó', 'ô', 'õ', 'ò', 'o'],
|
|
3386
|
+
u: ['ú', 'û', 'ũ', 'ù', 'u'],
|
|
3387
|
+
c: ['ç', 'c'],
|
|
3388
|
+
A: ['Á', 'Â', 'Ã', 'À', 'A'],
|
|
3389
|
+
E: ['É', 'Ê', 'Ẽ', 'È', 'E'],
|
|
3390
|
+
I: ['Í', 'Î', 'Ĩ', 'Ì', 'I'],
|
|
3391
|
+
O: ['Ó', 'Ô', 'Õ', 'Ò', 'O'],
|
|
3392
|
+
U: ['Ú', 'Û', 'Ũ', 'Ù', 'U'],
|
|
3393
|
+
C: ['Ç', 'C'],
|
|
3330
3394
|
};
|
|
3395
|
+
allCharOptions.push(...charOptions[char]);
|
|
3396
|
+
result += `[${allCharOptions.join('')}]`;
|
|
3331
3397
|
}
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3398
|
+
else {
|
|
3399
|
+
result += char;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
return result;
|
|
3403
|
+
};
|
|
3404
|
+
FilterOptionHelper.removeAccents = (text) => {
|
|
3405
|
+
return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
3406
|
+
};
|
|
3407
|
+
|
|
3408
|
+
class BindFilterQueryHelper {
|
|
3409
|
+
}
|
|
3410
|
+
BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => {
|
|
3411
|
+
const columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
|
|
3412
|
+
if (!columnOption.bindFindFilter)
|
|
3413
|
+
return Object.assign(Object.assign({}, variables), {
|
|
3414
|
+
[columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
|
|
3415
|
+
});
|
|
3416
|
+
const builtFilter = columnOption.bindFindFilter(filter[fieldName]);
|
|
3417
|
+
return Object.assign(Object.assign({}, variables), Object.keys(builtFilter).reduce((variablesList, columnName) => (Object.assign(Object.assign({}, variablesList), { [columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields) })), {}));
|
|
3418
|
+
}, {});
|
|
3419
|
+
BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
3420
|
+
const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
3421
|
+
const isNestedField = !Array.isArray(options) &&
|
|
3422
|
+
lodash.isObject(options) &&
|
|
3423
|
+
lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) &&
|
|
3424
|
+
lodash.isNil(options === null || options === void 0 ? void 0 : options.value) &&
|
|
3425
|
+
lodash.isNil(fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.to);
|
|
3426
|
+
if (isNestedField)
|
|
3427
|
+
return Object.keys(options).reduce((variables, key) => {
|
|
3428
|
+
const fieldOptions = AttributeOptionHelper.FindByAttribute(key, (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || fields);
|
|
3429
|
+
const columnName = fieldOptions.columnName;
|
|
3430
|
+
const columnFields = fieldOptions.fields;
|
|
3431
|
+
return Object.assign(Object.assign({}, variables), { [columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || columnFields || fields) });
|
|
3432
|
+
}, {});
|
|
3433
|
+
if (!Array.isArray(options) && !lodash.isNil(fieldSentenceOptions.fields))
|
|
3434
|
+
return {
|
|
3435
|
+
[fieldSentenceOptions.fields[0]]: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions),
|
|
3436
|
+
};
|
|
3437
|
+
if (!Array.isArray(options) && lodash.isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
3438
|
+
options = Object.values(options)[0];
|
|
3439
|
+
return Array.isArray(options)
|
|
3440
|
+
? options.reduce((whereSentence, option) => (Object.assign(Object.assign({}, whereSentence), BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions))), {})
|
|
3441
|
+
: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions);
|
|
3442
|
+
};
|
|
3443
|
+
BindFilterQueryHelper.BuildOperatorSentence = (options, fieldOption) => ({
|
|
3444
|
+
[BindFilterQueryHelper.GetHasuraOperator(options, fieldOption)]: FilterOptionHelper.GetValueFromFilter(options, fieldOption),
|
|
3445
|
+
});
|
|
3446
|
+
BindFilterQueryHelper.GetHasuraOperator = (options, fieldOption) => FilterOptionHelper.CheckIfIsFilterOption(options)
|
|
3447
|
+
? fieldOption.type === HasuraGraphQLColumnType.Jsonb
|
|
3448
|
+
? BindFilterQueryHelper.GetHasuraJsonbOperator(options)
|
|
3449
|
+
: options.operator === exports.Where.LIKE && options.ignoreCase && options.ignoreAccent
|
|
3450
|
+
? HasuraGraphQLWhere.IREGEX
|
|
3451
|
+
: options.operator === exports.Where.LIKE && options.ignoreAccent
|
|
3452
|
+
? HasuraGraphQLWhere.REGEX
|
|
3453
|
+
: options.operator === exports.Where.LIKE && options.ignoreCase
|
|
3454
|
+
? HasuraGraphQLWhere.ILIKE
|
|
3455
|
+
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3456
|
+
Object.keys(exports.Where).find((operator) => exports.Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))]
|
|
3457
|
+
: HasuraGraphQLWhere.EQUALS;
|
|
3458
|
+
BindFilterQueryHelper.GetHasuraJsonbOperator = (options) => options.operator === exports.Where.IN
|
|
3459
|
+
? HasuraGraphQLWhere.JSON_CONTAINS
|
|
3460
|
+
: options.operator === exports.Where.LIKE
|
|
3461
|
+
? HasuraGraphQLWhere.JSON_HAS_KEYS_ANY
|
|
3462
|
+
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
3463
|
+
Object.keys(exports.Where).find((operator) => exports.Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))];
|
|
3464
|
+
|
|
3465
|
+
class CacheKeyGeneratorHelper {
|
|
3466
|
+
static generateCacheKeyFromIdentifiers(modelOrModelName, identifiers) {
|
|
3467
|
+
const sortedKeys = Object.keys(identifiers).sort();
|
|
3468
|
+
const keyParts = sortedKeys.map((key) => `${String(key)}:${identifiers[key]}`);
|
|
3469
|
+
const modelName = modelOrModelName.name.toLowerCase();
|
|
3470
|
+
return `${modelName}:get:${keyParts.join(':')}`;
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
class GraphQLFieldHelper {
|
|
3475
|
+
}
|
|
3476
|
+
GraphQLFieldHelper.CheckIsGraphQLParams = (params) => !lodash.isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation;
|
|
3477
|
+
GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
3478
|
+
return fields === null || fields === void 0 ? void 0 : fields.map((field) => {
|
|
3479
|
+
if (lodash.isString(field))
|
|
3480
|
+
return field.toString();
|
|
3481
|
+
if (field === 'affected_rows')
|
|
3482
|
+
return field;
|
|
3483
|
+
const fieldName = Object.keys(field).shift();
|
|
3484
|
+
const fieldValue = is(field[fieldName]);
|
|
3485
|
+
if (Array.isArray(fieldValue))
|
|
3486
|
+
return { [fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue) };
|
|
3487
|
+
if (!AttributeOptionHelper.CheckIsColumnOption(fieldValue))
|
|
3488
|
+
return;
|
|
3489
|
+
const isNestedField = !!fieldValue.fields;
|
|
3490
|
+
if (isNestedField)
|
|
3491
|
+
return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
|
|
3492
|
+
return fieldValue.columnName;
|
|
3493
|
+
}).filter((field) => !!field);
|
|
3494
|
+
};
|
|
3495
|
+
GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
|
|
3496
|
+
const { attributeName, fields: attributeFields, from, } = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields);
|
|
3497
|
+
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
3498
|
+
if (Array.isArray(data[columnName]))
|
|
3499
|
+
return Object.assign(Object.assign({}, result), { [attributeName]: from
|
|
3500
|
+
? from(data[columnName], data)
|
|
3501
|
+
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)) });
|
|
3502
|
+
if (lodash.isObject(data[columnName]))
|
|
3503
|
+
return Object.assign(Object.assign({}, result), { [attributeName]: !!from
|
|
3504
|
+
? from(data[columnName])
|
|
3505
|
+
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields) });
|
|
3506
|
+
}
|
|
3507
|
+
if (!!from)
|
|
3508
|
+
return Object.assign(Object.assign({}, result), { [attributeName]: from(data[columnName], data) });
|
|
3509
|
+
return Object.assign(Object.assign({}, result), { [attributeName]: lodash.isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName] });
|
|
3510
|
+
}, {});
|
|
3511
|
+
GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
|
|
3512
|
+
var _a;
|
|
3513
|
+
const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
3514
|
+
return Object.keys(data).reduce((result, attributeName) => {
|
|
3515
|
+
const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
|
|
3516
|
+
if (bindPersistData)
|
|
3517
|
+
return Object.assign(Object.assign({}, result), bindPersistData(data[attributeName], instance));
|
|
3518
|
+
if (lodash.isNil(columnName))
|
|
3519
|
+
return result;
|
|
3520
|
+
if (!!foreignKeyColumn &&
|
|
3521
|
+
!lodash.isEmpty(foreignKeyColumn) &&
|
|
3522
|
+
!Object.keys(foreignKeyColumn).filter((key) => { var _a; return !((_a = is(data[attributeName])) === null || _a === void 0 ? void 0 : _a[key]); }).length)
|
|
3523
|
+
return Object.keys(foreignKeyColumn).reduce((object, current) => {
|
|
3524
|
+
var _a;
|
|
3525
|
+
const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
|
|
3526
|
+
return Object.assign(Object.assign({}, object), { [foreignColumnName]: (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current] });
|
|
3527
|
+
}, Object.assign({}, result));
|
|
3528
|
+
if (update &&
|
|
3529
|
+
lodash.isObject(data[attributeName]) &&
|
|
3530
|
+
!lodash.isNil(attributeFields) &&
|
|
3531
|
+
!lodash.isDate(data[attributeName]))
|
|
3532
|
+
return result;
|
|
3533
|
+
if (!!columnName &&
|
|
3534
|
+
Array.isArray(attributeFields) &&
|
|
3535
|
+
lodash.isObject(data[attributeName])) {
|
|
3536
|
+
const converted = !lodash.isNil(columnName) && to
|
|
3537
|
+
? to(instance[attributeName], instance)
|
|
3538
|
+
: data[attributeName];
|
|
3539
|
+
return Object.assign(Object.assign({}, result), (converted !== undefined
|
|
3540
|
+
? {
|
|
3541
|
+
[columnName]: {
|
|
3542
|
+
data: instance[attributeName] instanceof BaseModel
|
|
3543
|
+
? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
|
|
3544
|
+
: converted,
|
|
3545
|
+
},
|
|
3546
|
+
}
|
|
3547
|
+
: {}));
|
|
3548
|
+
}
|
|
3549
|
+
if (!!to)
|
|
3550
|
+
return Object.assign(Object.assign({}, result), { [columnName]: to(instance[attributeName], instance) });
|
|
3551
|
+
return Object.assign(Object.assign({}, result), { [columnName]: data[attributeName] });
|
|
3552
|
+
}, {});
|
|
3553
|
+
};
|
|
3554
|
+
GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
|
|
3555
|
+
const hasCustomFilters = !!fieldValue.filters;
|
|
3556
|
+
if (hasCustomFilters)
|
|
3557
|
+
return {
|
|
3558
|
+
operation: fieldValue.columnName || fieldName,
|
|
3559
|
+
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
3560
|
+
variables: {
|
|
3561
|
+
[`${fieldValue.columnName}_where`]: {
|
|
3562
|
+
name: 'where',
|
|
3563
|
+
type: fieldValue.filters.filterType,
|
|
3564
|
+
value: BindFilterQueryHelper.MakeGraphQLWhere(fieldValue.filters.filters, fieldValue.fields),
|
|
3565
|
+
required: true,
|
|
3566
|
+
},
|
|
3567
|
+
},
|
|
3568
|
+
};
|
|
3569
|
+
return {
|
|
3570
|
+
[fieldValue.columnName || fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
3571
|
+
};
|
|
3572
|
+
};
|
|
3573
|
+
|
|
3574
|
+
class MD5GeneratorHelper {
|
|
3575
|
+
static generateMD5(data) {
|
|
3576
|
+
if (data === null || data === undefined)
|
|
3577
|
+
return tsMd5.Md5.hashStr('null');
|
|
3578
|
+
const normalizedData = this.normalizeData(data);
|
|
3579
|
+
const jsonString = JSON.stringify(normalizedData);
|
|
3580
|
+
return tsMd5.Md5.hashStr(jsonString);
|
|
3581
|
+
}
|
|
3582
|
+
static normalizeData(data, depth = 0, maxDepth = 100) {
|
|
3583
|
+
if (depth > maxDepth)
|
|
3584
|
+
return '[MAX_DEPTH_REACHED]';
|
|
3585
|
+
if (data === null || data === undefined)
|
|
3586
|
+
return null;
|
|
3587
|
+
if (typeof data !== 'object')
|
|
3588
|
+
return data;
|
|
3589
|
+
if (Array.isArray(data))
|
|
3590
|
+
return data
|
|
3591
|
+
.map((item) => this.normalizeData(item, depth + 1, maxDepth))
|
|
3592
|
+
.sort((a, b) => {
|
|
3593
|
+
const strA = typeof a === 'object' && a !== null ? JSON.stringify(a) : String(a);
|
|
3594
|
+
const strB = typeof b === 'object' && b !== null ? JSON.stringify(b) : String(b);
|
|
3595
|
+
return strA.localeCompare(strB);
|
|
3596
|
+
});
|
|
3597
|
+
const sortedObj = {};
|
|
3598
|
+
const keys = Object.keys(data).sort();
|
|
3599
|
+
keys.forEach((key) => {
|
|
3600
|
+
const value = data[key];
|
|
3601
|
+
sortedObj[key] = this.normalizeData(value, depth + 1, maxDepth);
|
|
3602
|
+
});
|
|
3603
|
+
return sortedObj;
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
|
|
3607
|
+
class FirestoreCacheKeyGeneratorHelper {
|
|
3608
|
+
static generateGetCacheKey(model, identifiers) {
|
|
3609
|
+
const sortedEntries = Object.entries(identifiers).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
|
|
3610
|
+
const keyParts = [];
|
|
3611
|
+
for (const [key, value] of sortedEntries) {
|
|
3612
|
+
keyParts.push(`${key}:${value}`);
|
|
3613
|
+
}
|
|
3614
|
+
return `${model.name.toLowerCase()}:get:${keyParts.join(':')}`;
|
|
3615
|
+
}
|
|
3616
|
+
static generateFindCacheKey(model, findParams) {
|
|
3617
|
+
const md5 = MD5GeneratorHelper.generateMD5(findParams);
|
|
3618
|
+
return `${model.name.toLowerCase()}:find:${md5}`;
|
|
3619
|
+
}
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3622
|
+
const withGetFirestore = (MixinBase) => {
|
|
3623
|
+
return class GetFirestore extends MixinBase {
|
|
3624
|
+
async get(identifiers, options) {
|
|
3625
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
3626
|
+
const logger = this.logger.with('get');
|
|
3627
|
+
const collectionName = this.buildCollectionPathForGet(identifiers);
|
|
3628
|
+
const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
|
|
3629
|
+
const req = { collection: collectionName, data: identifiers };
|
|
3630
|
+
if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled) !== false) {
|
|
3631
|
+
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
|
|
3632
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
3633
|
+
if (cachedData) {
|
|
3634
|
+
logger.log({ req, res: 'Dados recuperados do cache', cacheKey });
|
|
3635
|
+
return this.model.toInstance(JSON.parse(cachedData));
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
try {
|
|
3639
|
+
const intercepted = await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.call(_c, { instance }));
|
|
3640
|
+
const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
|
|
3641
|
+
const docRef = await this.collection(collectionName)
|
|
3642
|
+
.getDoc(Object.values(builded.identifier).shift().toString())
|
|
3643
|
+
.get();
|
|
3644
|
+
const data = docRef.data();
|
|
3645
|
+
if (lodash.isNil(data))
|
|
3646
|
+
throw new NotFoundError(`Document '${collectionName}/${Object.values(identifiers).shift()}' not found`);
|
|
3647
|
+
const res = (await ((_f = (_e = this.interceptors) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.call(_e, data, intercepted))) || data;
|
|
3648
|
+
logger.log({ req, res });
|
|
3649
|
+
if (((_g = this.cache) === null || _g === void 0 ? void 0 : _g.cacheAdapter) && ((_h = options === null || options === void 0 ? void 0 : options.cache) === null || _h === void 0 ? void 0 : _h.enabled) !== false) {
|
|
3650
|
+
const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
|
|
3651
|
+
await this.cache.cacheAdapter.set({
|
|
3652
|
+
key: cacheKey,
|
|
3653
|
+
data: JSON.stringify((res === null || res === void 0 ? void 0 : res.toPlain()) || res),
|
|
3654
|
+
expirationInSeconds: ((_j = options === null || options === void 0 ? void 0 : options.cache) === null || _j === void 0 ? void 0 : _j.ttl) || this.cache.ttlDefault,
|
|
3655
|
+
});
|
|
3656
|
+
logger.log({ req, message: 'Dados salvos no cache', cacheKey });
|
|
3657
|
+
}
|
|
3658
|
+
return res;
|
|
3659
|
+
}
|
|
3660
|
+
catch (error) {
|
|
3661
|
+
if (error instanceof Error)
|
|
3662
|
+
logger.log({ req, res: error, stack: error.stack });
|
|
3663
|
+
throw error;
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
buildCollectionPathForGet(identifiers) {
|
|
3667
|
+
return this.isSubCollection(this)
|
|
3668
|
+
? `${this.parentRepository.collectionName}/${identifiers[this.parentIdField]}/${this.collectionName}`
|
|
3669
|
+
: this.collectionName;
|
|
3670
|
+
}
|
|
3671
|
+
};
|
|
3672
|
+
};
|
|
3673
|
+
|
|
3674
|
+
var FirestoreFieldType;
|
|
3675
|
+
(function (FirestoreFieldType) {
|
|
3676
|
+
FirestoreFieldType["String"] = "string";
|
|
3677
|
+
FirestoreFieldType["Number"] = "number";
|
|
3678
|
+
FirestoreFieldType["Boolean"] = "boolean";
|
|
3679
|
+
FirestoreFieldType["Timestamp"] = "timestamp";
|
|
3680
|
+
FirestoreFieldType["Array"] = "array";
|
|
3681
|
+
FirestoreFieldType["Map"] = "map";
|
|
3682
|
+
})(FirestoreFieldType || (FirestoreFieldType = {}));
|
|
3683
|
+
|
|
3684
|
+
const withFindFirestore = (MixinBase) => {
|
|
3685
|
+
const checkIfIsFilterOption = (filter) => !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
|
|
3686
|
+
const getValueFromFilter = (filter) => {
|
|
3687
|
+
return checkIfIsFilterOption(filter) ? filter.value : filter;
|
|
3688
|
+
};
|
|
3689
|
+
return class FindFirestore extends MixinBase {
|
|
3690
|
+
constructor() {
|
|
3691
|
+
super(...arguments);
|
|
3692
|
+
this.makeFirestoreWhere = (filter) => Object.keys(filter).reduce((queries, fieldName) => [
|
|
3693
|
+
...queries,
|
|
3694
|
+
...this.buildWhereSentence(fieldName, is(filter[fieldName])),
|
|
3695
|
+
], []);
|
|
3696
|
+
this.buildWhereSentence = (fieldName, options) => {
|
|
3697
|
+
var _a, _b, _c, _d;
|
|
3698
|
+
if (this.isSubCollection(this) && fieldName === this.parentIdField)
|
|
3699
|
+
return [];
|
|
3700
|
+
const value = (options === null || options === void 0 ? void 0 : options.value) || options;
|
|
3701
|
+
const object = {};
|
|
3702
|
+
lodash.set(object, fieldName, value);
|
|
3703
|
+
const plainInstance = new this.model(object).toPlain();
|
|
3704
|
+
const firestoreFieldName = fieldName.toString().indexOf('.') > -1
|
|
3705
|
+
? fieldName.toString()
|
|
3706
|
+
: Object.keys(plainInstance).find((key) => plainInstance[key]);
|
|
3707
|
+
if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.LIKE) {
|
|
3708
|
+
if (Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
|
|
3709
|
+
(((_a = this.fields) === null || _a === void 0 ? void 0 : _a[firestoreFieldName]) ===
|
|
3710
|
+
FirestoreFieldType.Array ||
|
|
3711
|
+
!((_b = this.fields) === null || _b === void 0 ? void 0 : _b[firestoreFieldName])))
|
|
3712
|
+
return [[firestoreFieldName, 'array-contains-any', options.value]];
|
|
3713
|
+
return [
|
|
3714
|
+
[firestoreFieldName, '>=', options.value],
|
|
3715
|
+
[firestoreFieldName, '<=', `${options.value}~`],
|
|
3716
|
+
];
|
|
3717
|
+
}
|
|
3718
|
+
if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.IN &&
|
|
3719
|
+
Array.isArray(options === null || options === void 0 ? void 0 : options.value) &&
|
|
3720
|
+
(((_c = this.fields) === null || _c === void 0 ? void 0 : _c[firestoreFieldName]) ===
|
|
3721
|
+
FirestoreFieldType.Array ||
|
|
3722
|
+
!((_d = this.fields) === null || _d === void 0 ? void 0 : _d[firestoreFieldName])))
|
|
3723
|
+
return [[firestoreFieldName, 'array-contains', options.value]];
|
|
3724
|
+
if (lodash.isObject(options) && lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) && lodash.isNil(options === null || options === void 0 ? void 0 : options.value)) {
|
|
3725
|
+
return Object.keys(options).reduce((queries, key) => [
|
|
3726
|
+
...queries,
|
|
3727
|
+
...this.buildWhereSentence(`${fieldName.toString()}.${key}`, is(options)[key]),
|
|
3728
|
+
], []);
|
|
3729
|
+
}
|
|
3730
|
+
return [[firestoreFieldName, ((options === null || options === void 0 ? void 0 : options.operator) || '=='), (options === null || options === void 0 ? void 0 : options.value) || options]];
|
|
3731
|
+
};
|
|
3732
|
+
this.makeFirestoreOrderBy = (filters, fieldsToOrderBy) => {
|
|
3733
|
+
const orderByKeys = Object.keys(fieldsToOrderBy || {});
|
|
3734
|
+
if (!orderByKeys.length)
|
|
3735
|
+
return [];
|
|
3736
|
+
const filtersKeysWithUnordered = Object.keys(filters || {}).filter((filterKey) => !orderByKeys.includes(filterKey));
|
|
3737
|
+
if (filtersKeysWithUnordered.length)
|
|
3738
|
+
filtersKeysWithUnordered.forEach((filterKey) => (fieldsToOrderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(is(filters[filterKey]).operator)
|
|
3739
|
+
? { [filterKey]: 'asc' }
|
|
3740
|
+
: {})), fieldsToOrderBy)));
|
|
3741
|
+
return Object.keys(fieldsToOrderBy).map((fieldName) => [
|
|
3742
|
+
fieldName,
|
|
3743
|
+
fieldsToOrderBy[fieldName],
|
|
3744
|
+
]);
|
|
3745
|
+
};
|
|
3746
|
+
}
|
|
3747
|
+
generateCacheKey(findParams) {
|
|
3748
|
+
return FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(this.model, findParams);
|
|
3749
|
+
}
|
|
3750
|
+
async find(find = {}, options) {
|
|
3751
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
3752
|
+
const logger = this.logger.with('find');
|
|
3753
|
+
if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled) !== false) {
|
|
3754
|
+
const cacheKey = this.generateCacheKey(find);
|
|
3755
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
3756
|
+
if (cachedData) {
|
|
3757
|
+
logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
3758
|
+
return JSON.parse(cachedData);
|
|
3759
|
+
}
|
|
3760
|
+
}
|
|
3761
|
+
const collectionName = this.buildCollectionPathForFind(find.filters);
|
|
3762
|
+
const collection = this.collection(collectionName);
|
|
3763
|
+
const enableCount = (_d = (_c = find === null || find === void 0 ? void 0 : find.options) === null || _c === void 0 ? void 0 : _c.enableCount) !== null && _d !== void 0 ? _d : true;
|
|
3338
3764
|
const req = { collection: collectionName, data: find };
|
|
3339
3765
|
try {
|
|
3340
|
-
const intercepted = await ((
|
|
3766
|
+
const intercepted = await ((_f = (_e = this.interceptors) === null || _e === void 0 ? void 0 : _e.request) === null || _f === void 0 ? void 0 : _f.call(_e, { find }));
|
|
3341
3767
|
const { fields, filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
|
|
3342
3768
|
const queries = this.makeFirestoreWhere(filters || {});
|
|
3343
3769
|
const ordination = this.makeFirestoreOrderBy(filters, orderBy);
|
|
@@ -3347,10 +3773,19 @@ const withFindFirestore = (MixinBase) => {
|
|
|
3347
3773
|
.getDocs();
|
|
3348
3774
|
const data = docs.docs.map((doc) => doc.data());
|
|
3349
3775
|
const res = {
|
|
3350
|
-
data: (await ((
|
|
3776
|
+
data: (await ((_h = (_g = this.interceptors) === null || _g === void 0 ? void 0 : _g.response) === null || _h === void 0 ? void 0 : _h.call(_g, data, intercepted))) || data,
|
|
3351
3777
|
count: enableCount ? this.calculateCount(data, limits) : Infinity,
|
|
3352
3778
|
};
|
|
3353
3779
|
logger.log({ req, queries, ordination, offsets, res });
|
|
3780
|
+
if (((_j = this.cache) === null || _j === void 0 ? void 0 : _j.cacheAdapter) && ((_k = options === null || options === void 0 ? void 0 : options.cache) === null || _k === void 0 ? void 0 : _k.enabled) !== false) {
|
|
3781
|
+
const cacheKey = this.generateCacheKey(find);
|
|
3782
|
+
await this.cache.cacheAdapter.set({
|
|
3783
|
+
key: cacheKey,
|
|
3784
|
+
data: JSON.stringify(res),
|
|
3785
|
+
expirationInSeconds: ((_l = options === null || options === void 0 ? void 0 : options.cache) === null || _l === void 0 ? void 0 : _l.ttl) || this.cache.ttlDefault,
|
|
3786
|
+
});
|
|
3787
|
+
logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
3788
|
+
}
|
|
3354
3789
|
return res;
|
|
3355
3790
|
}
|
|
3356
3791
|
catch (error) {
|
|
@@ -3454,24 +3889,41 @@ const withUpdateFirestore = (MixinBase) => {
|
|
|
3454
3889
|
return options === null || options === void 0 ? void 0 : options.value;
|
|
3455
3890
|
};
|
|
3456
3891
|
return class UpdateFirestore extends MixinBase {
|
|
3892
|
+
getIdentifiersFromData(data) {
|
|
3893
|
+
const identifiers = {};
|
|
3894
|
+
const model = new this.model();
|
|
3895
|
+
const keyField = model.identifiersFields.shift();
|
|
3896
|
+
const identifierValue = getValueFromParams(data, keyField);
|
|
3897
|
+
identifiers[keyField] = identifierValue;
|
|
3898
|
+
return identifiers;
|
|
3899
|
+
}
|
|
3900
|
+
generateCacheKey(identifiers) {
|
|
3901
|
+
return FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
|
|
3902
|
+
}
|
|
3457
3903
|
async update(data) {
|
|
3458
|
-
var _a, _b, _c, _d;
|
|
3904
|
+
var _a, _b, _c, _d, _e;
|
|
3459
3905
|
const logger = this.logger.with('update');
|
|
3460
3906
|
const collectionName = this.buildCollectionPathForUpdate(data);
|
|
3461
3907
|
const model = new this.model();
|
|
3462
3908
|
const keyField = model.identifiersFields.shift();
|
|
3463
3909
|
const req = { collection: collectionName, data };
|
|
3910
|
+
if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
|
|
3911
|
+
const identifiers = this.getIdentifiersFromData(data);
|
|
3912
|
+
const cacheKey = this.generateCacheKey(identifiers);
|
|
3913
|
+
await this.cache.cacheAdapter.remove(cacheKey);
|
|
3914
|
+
logger.log(`Cache removido: ${cacheKey}`);
|
|
3915
|
+
}
|
|
3464
3916
|
try {
|
|
3465
3917
|
const identifiers = getValueFromParams(data, keyField);
|
|
3466
3918
|
const docRef = this.collection(collectionName).getDoc(identifiers.toString());
|
|
3467
3919
|
if (!(await docRef.get()).data())
|
|
3468
3920
|
throw new NotFoundError(`Document '${collectionName}/${Object.values(identifiers.toString())}' not found`);
|
|
3469
3921
|
const plainFromData = this.model.toInstance(this.paramsToPlain(data));
|
|
3470
|
-
const intercepted = await ((
|
|
3922
|
+
const intercepted = await ((_c = (_b = this.interceptors) === null || _b === void 0 ? void 0 : _b.request) === null || _c === void 0 ? void 0 : _c.call(_b, { instance: plainFromData }));
|
|
3471
3923
|
const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
|
|
3472
3924
|
await docRef.save(builded.toPlain());
|
|
3473
3925
|
const docData = await docRef.get();
|
|
3474
|
-
const res = ((
|
|
3926
|
+
const res = ((_e = (_d = this.interceptors) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.call(_d, docData.data(), intercepted)) || docData.data();
|
|
3475
3927
|
logger.log({ req, res, identifiers });
|
|
3476
3928
|
return res;
|
|
3477
3929
|
}
|
|
@@ -3497,17 +3949,25 @@ const withUpdateFirestore = (MixinBase) => {
|
|
|
3497
3949
|
|
|
3498
3950
|
const withDeleteFirestore = (MixinBase) => {
|
|
3499
3951
|
return class DeleteFirestore extends MixinBase {
|
|
3952
|
+
generateCacheKey(identifiers) {
|
|
3953
|
+
return FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
|
|
3954
|
+
}
|
|
3500
3955
|
async delete(identifiers) {
|
|
3501
|
-
var _a, _b, _c, _d;
|
|
3956
|
+
var _a, _b, _c, _d, _e;
|
|
3502
3957
|
const logger = this.logger.with('delete');
|
|
3503
3958
|
const collectionName = this.buildCollectionPathForRemove(identifiers);
|
|
3504
3959
|
const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
|
|
3505
3960
|
const req = { collection: collectionName, data: identifiers };
|
|
3961
|
+
if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
|
|
3962
|
+
const cacheKey = this.generateCacheKey(identifiers);
|
|
3963
|
+
await this.cache.cacheAdapter.remove(cacheKey);
|
|
3964
|
+
logger.log(`Cache removido: ${cacheKey}`);
|
|
3965
|
+
}
|
|
3506
3966
|
try {
|
|
3507
|
-
const intercepted = await ((
|
|
3967
|
+
const intercepted = await ((_c = (_b = this.interceptors) === null || _b === void 0 ? void 0 : _b.request) === null || _c === void 0 ? void 0 : _c.call(_b, { instance }));
|
|
3508
3968
|
const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
|
|
3509
3969
|
await this.collection(collectionName).getDoc(Object.values(builded.identifier).shift().toString()).delete();
|
|
3510
|
-
await ((
|
|
3970
|
+
await ((_e = (_d = this.interceptors) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.call(_d, instance, intercepted));
|
|
3511
3971
|
logger.log({ req, res: undefined });
|
|
3512
3972
|
}
|
|
3513
3973
|
catch (error) {
|
|
@@ -3722,30 +4182,19 @@ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpe
|
|
|
3722
4182
|
constructor({ firestore, interceptors }) {
|
|
3723
4183
|
super({
|
|
3724
4184
|
firestore,
|
|
3725
|
-
collectionName: 'subscriptionProducts',
|
|
3726
|
-
model: Product,
|
|
3727
|
-
interceptors,
|
|
3728
|
-
});
|
|
3729
|
-
}
|
|
3730
|
-
}
|
|
3731
|
-
|
|
3732
|
-
class LogFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3733
|
-
constructor({ firestore, interceptors, }) {
|
|
3734
|
-
super({
|
|
3735
|
-
firestore,
|
|
3736
|
-
collectionName: 'logs',
|
|
3737
|
-
model: LogDocument,
|
|
4185
|
+
collectionName: 'subscriptionProducts',
|
|
4186
|
+
model: Product,
|
|
3738
4187
|
interceptors,
|
|
3739
4188
|
});
|
|
3740
4189
|
}
|
|
3741
4190
|
}
|
|
3742
4191
|
|
|
3743
|
-
class
|
|
4192
|
+
class LogFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3744
4193
|
constructor({ firestore, interceptors, }) {
|
|
3745
4194
|
super({
|
|
3746
4195
|
firestore,
|
|
3747
|
-
collectionName: '
|
|
3748
|
-
model:
|
|
4196
|
+
collectionName: 'logs',
|
|
4197
|
+
model: LogDocument,
|
|
3749
4198
|
interceptors,
|
|
3750
4199
|
});
|
|
3751
4200
|
}
|
|
@@ -3763,12 +4212,13 @@ class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
3763
4212
|
}
|
|
3764
4213
|
|
|
3765
4214
|
class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3766
|
-
constructor({ firestore, interceptors }) {
|
|
4215
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3767
4216
|
super({
|
|
3768
4217
|
firestore,
|
|
3769
4218
|
collectionName: 'dms',
|
|
3770
4219
|
model: Home,
|
|
3771
4220
|
interceptors,
|
|
4221
|
+
cache,
|
|
3772
4222
|
});
|
|
3773
4223
|
this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
|
|
3774
4224
|
var _a, _b, _c;
|
|
@@ -3825,89 +4275,97 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
|
|
|
3825
4275
|
}
|
|
3826
4276
|
|
|
3827
4277
|
class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3828
|
-
constructor({ firestore, interceptors }) {
|
|
4278
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3829
4279
|
super({
|
|
3830
4280
|
firestore,
|
|
3831
4281
|
collectionName: 'shopMenus',
|
|
3832
4282
|
model: ShopMenu,
|
|
3833
4283
|
interceptors,
|
|
4284
|
+
cache,
|
|
3834
4285
|
});
|
|
3835
4286
|
}
|
|
3836
4287
|
}
|
|
3837
4288
|
|
|
3838
4289
|
class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3839
|
-
constructor({ firestore, interceptors, }) {
|
|
4290
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3840
4291
|
super({
|
|
3841
4292
|
firestore,
|
|
3842
4293
|
collectionName: 'shopSettings',
|
|
3843
4294
|
model: ShopSettings,
|
|
3844
4295
|
interceptors,
|
|
4296
|
+
cache,
|
|
3845
4297
|
});
|
|
3846
4298
|
}
|
|
3847
4299
|
}
|
|
3848
4300
|
|
|
3849
4301
|
class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3850
|
-
constructor({ firestore, interceptors }) {
|
|
4302
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3851
4303
|
super({
|
|
3852
4304
|
firestore,
|
|
3853
4305
|
collectionName: 'buy2win',
|
|
3854
4306
|
model: Buy2Win,
|
|
3855
4307
|
interceptors,
|
|
4308
|
+
cache,
|
|
3856
4309
|
});
|
|
3857
4310
|
}
|
|
3858
4311
|
}
|
|
3859
4312
|
|
|
3860
4313
|
class CampaignDashboardFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3861
|
-
constructor({ firestore, interceptors, }) {
|
|
4314
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3862
4315
|
super({
|
|
3863
4316
|
firestore,
|
|
3864
4317
|
collectionName: 'dashboardCampaignsAuto',
|
|
3865
4318
|
model: CampaignDashboard,
|
|
3866
4319
|
interceptors,
|
|
4320
|
+
cache,
|
|
3867
4321
|
});
|
|
3868
4322
|
}
|
|
3869
4323
|
}
|
|
3870
4324
|
|
|
3871
4325
|
class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3872
|
-
constructor({ firestore, interceptors, }) {
|
|
4326
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3873
4327
|
super({
|
|
3874
4328
|
firestore,
|
|
3875
4329
|
collectionName: 'hashtagCampaignsAuto',
|
|
3876
4330
|
model: CampaignHashtag,
|
|
3877
4331
|
interceptors,
|
|
4332
|
+
cache,
|
|
3878
4333
|
});
|
|
3879
4334
|
}
|
|
3880
4335
|
}
|
|
3881
4336
|
|
|
3882
4337
|
class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3883
|
-
constructor({ firestore, interceptors }) {
|
|
4338
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3884
4339
|
super({
|
|
3885
4340
|
firestore,
|
|
3886
4341
|
collectionName: 'checkouts',
|
|
3887
4342
|
model: Checkout,
|
|
3888
4343
|
interceptors,
|
|
4344
|
+
cache,
|
|
3889
4345
|
});
|
|
3890
4346
|
}
|
|
3891
4347
|
}
|
|
3892
4348
|
|
|
3893
4349
|
class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3894
|
-
constructor({ firestore, interceptors, }) {
|
|
4350
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3895
4351
|
super({
|
|
3896
4352
|
firestore,
|
|
3897
4353
|
collectionName: 'checkoutsSubscription',
|
|
3898
4354
|
model: CheckoutSubscription,
|
|
3899
4355
|
interceptors,
|
|
4356
|
+
cache,
|
|
3900
4357
|
});
|
|
3901
4358
|
}
|
|
3902
4359
|
}
|
|
3903
4360
|
|
|
3904
4361
|
class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3905
|
-
constructor({ firestore, interceptors }) {
|
|
4362
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3906
4363
|
super({
|
|
3907
4364
|
firestore,
|
|
3908
4365
|
collectionName: 'coupons',
|
|
3909
4366
|
model: Coupon,
|
|
3910
4367
|
interceptors,
|
|
4368
|
+
cache,
|
|
3911
4369
|
});
|
|
3912
4370
|
}
|
|
3913
4371
|
buildModelInstance() {
|
|
@@ -3930,12 +4388,13 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
|
|
|
3930
4388
|
}
|
|
3931
4389
|
|
|
3932
4390
|
class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3933
|
-
constructor({ firestore, interceptors }) {
|
|
4391
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3934
4392
|
super({
|
|
3935
4393
|
firestore,
|
|
3936
4394
|
collectionName: 'orders',
|
|
3937
4395
|
model: Order,
|
|
3938
4396
|
interceptors,
|
|
4397
|
+
cache,
|
|
3939
4398
|
fields: {
|
|
3940
4399
|
status: FirestoreFieldType.String,
|
|
3941
4400
|
},
|
|
@@ -3967,22 +4426,24 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
|
|
|
3967
4426
|
}
|
|
3968
4427
|
|
|
3969
4428
|
class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
|
|
3970
|
-
constructor({ firestore, interceptors }) {
|
|
4429
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3971
4430
|
super({
|
|
3972
4431
|
firestore,
|
|
3973
4432
|
interceptors,
|
|
4433
|
+
cache,
|
|
3974
4434
|
});
|
|
3975
4435
|
this.collectionName = 'legacyOrders';
|
|
3976
4436
|
}
|
|
3977
4437
|
}
|
|
3978
4438
|
|
|
3979
4439
|
class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
3980
|
-
constructor({ firestore, interceptors, }) {
|
|
4440
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
3981
4441
|
super({
|
|
3982
4442
|
firestore,
|
|
3983
4443
|
collectionName: 'paymentBlockedAttempts',
|
|
3984
4444
|
model: OrderBlocked,
|
|
3985
4445
|
interceptors,
|
|
4446
|
+
cache,
|
|
3986
4447
|
});
|
|
3987
4448
|
}
|
|
3988
4449
|
async createBlockedOrderOrPayment(checkout, blockType, type, limiteRange, card = null) {
|
|
@@ -4014,130 +4475,141 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
|
|
|
4014
4475
|
}
|
|
4015
4476
|
|
|
4016
4477
|
class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4017
|
-
constructor({ firestore, interceptors }) {
|
|
4478
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
4018
4479
|
super({
|
|
4019
4480
|
firestore,
|
|
4020
4481
|
collectionName: 'payments',
|
|
4021
4482
|
model: Payment,
|
|
4022
4483
|
interceptors,
|
|
4484
|
+
cache,
|
|
4023
4485
|
});
|
|
4024
4486
|
}
|
|
4025
4487
|
}
|
|
4026
4488
|
|
|
4027
4489
|
class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4028
|
-
constructor({ firestore, interceptors, }) {
|
|
4490
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
4029
4491
|
super({
|
|
4030
4492
|
firestore,
|
|
4031
4493
|
collectionName: 'subscriptionPlans',
|
|
4032
4494
|
model: SubscriptionPlan,
|
|
4033
4495
|
interceptors,
|
|
4496
|
+
cache,
|
|
4034
4497
|
});
|
|
4035
4498
|
}
|
|
4036
4499
|
}
|
|
4037
4500
|
|
|
4038
4501
|
class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4039
|
-
constructor({ firestore, interceptors }) {
|
|
4502
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
4040
4503
|
super({
|
|
4041
4504
|
firestore,
|
|
4042
4505
|
collectionName: 'leads',
|
|
4043
4506
|
model: Lead,
|
|
4044
4507
|
interceptors,
|
|
4508
|
+
cache,
|
|
4045
4509
|
});
|
|
4046
4510
|
}
|
|
4047
4511
|
}
|
|
4048
4512
|
|
|
4049
4513
|
class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
|
|
4050
|
-
constructor({ firestore, interceptors }, parentRepository) {
|
|
4514
|
+
constructor({ firestore, interceptors, cache, }, parentRepository) {
|
|
4051
4515
|
super({
|
|
4052
4516
|
firestore,
|
|
4053
4517
|
collectionName: 'editions',
|
|
4054
4518
|
parentIdField: 'subscriptionId',
|
|
4055
4519
|
model: Edition,
|
|
4056
4520
|
interceptors,
|
|
4521
|
+
cache,
|
|
4057
4522
|
});
|
|
4058
4523
|
this.parentRepository = parentRepository;
|
|
4059
4524
|
}
|
|
4060
4525
|
}
|
|
4061
4526
|
|
|
4062
4527
|
class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4063
|
-
constructor({ firestore, interceptors, }) {
|
|
4528
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
4064
4529
|
super({
|
|
4065
4530
|
firestore,
|
|
4066
4531
|
collectionName: 'subscription',
|
|
4067
4532
|
model: Subscription,
|
|
4068
4533
|
interceptors,
|
|
4534
|
+
cache,
|
|
4069
4535
|
});
|
|
4070
4536
|
}
|
|
4071
4537
|
}
|
|
4072
4538
|
|
|
4073
4539
|
class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4074
|
-
constructor({ firestore, interceptors }) {
|
|
4540
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
4075
4541
|
super({
|
|
4076
4542
|
firestore,
|
|
4077
4543
|
collectionName: 'subscriptionMaterialization',
|
|
4078
4544
|
model: SubscriptionMaterialization,
|
|
4079
4545
|
interceptors,
|
|
4546
|
+
cache,
|
|
4080
4547
|
});
|
|
4081
4548
|
}
|
|
4082
4549
|
}
|
|
4083
4550
|
|
|
4084
4551
|
class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
|
|
4085
|
-
constructor({ firestore, interceptors }, parentRepository) {
|
|
4552
|
+
constructor({ firestore, interceptors, cache, }, parentRepository) {
|
|
4086
4553
|
super({
|
|
4087
4554
|
firestore,
|
|
4088
4555
|
collectionName: 'payments',
|
|
4089
4556
|
parentIdField: 'subscriptionId',
|
|
4090
4557
|
model: SubscriptionPayment,
|
|
4091
4558
|
interceptors,
|
|
4559
|
+
cache,
|
|
4092
4560
|
});
|
|
4093
4561
|
this.parentRepository = parentRepository;
|
|
4094
4562
|
}
|
|
4095
4563
|
}
|
|
4096
4564
|
|
|
4097
4565
|
class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4098
|
-
constructor({ firestore, interceptors, }) {
|
|
4566
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
4099
4567
|
super({
|
|
4100
4568
|
firestore,
|
|
4101
4569
|
collectionName: 'subscriptionSummary',
|
|
4102
4570
|
model: SubscriptionSummary,
|
|
4103
4571
|
interceptors,
|
|
4572
|
+
cache,
|
|
4104
4573
|
});
|
|
4105
4574
|
}
|
|
4106
4575
|
}
|
|
4107
4576
|
|
|
4108
4577
|
class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
|
|
4109
|
-
constructor({ firestore, interceptors }, parentRepository) {
|
|
4578
|
+
constructor({ firestore, interceptors, cache, }, parentRepository) {
|
|
4110
4579
|
super({
|
|
4111
4580
|
firestore,
|
|
4112
4581
|
collectionName: 'address',
|
|
4113
4582
|
parentIdField: 'userId',
|
|
4114
4583
|
model: UserAddress,
|
|
4115
4584
|
interceptors,
|
|
4585
|
+
cache,
|
|
4116
4586
|
});
|
|
4117
4587
|
this.parentRepository = parentRepository;
|
|
4118
4588
|
}
|
|
4119
4589
|
}
|
|
4120
4590
|
|
|
4121
4591
|
class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
|
|
4122
|
-
constructor({ firestore, interceptors }, parentRepository) {
|
|
4592
|
+
constructor({ firestore, interceptors, cache, }, parentRepository) {
|
|
4123
4593
|
super({
|
|
4124
4594
|
firestore,
|
|
4125
4595
|
collectionName: 'CX',
|
|
4126
4596
|
parentIdField: 'userId',
|
|
4127
4597
|
model: BeautyProfile,
|
|
4128
4598
|
interceptors,
|
|
4599
|
+
cache,
|
|
4129
4600
|
});
|
|
4130
4601
|
this.parentRepository = parentRepository;
|
|
4131
4602
|
}
|
|
4132
4603
|
}
|
|
4133
4604
|
|
|
4134
4605
|
class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4135
|
-
constructor({ firestore, interceptors }) {
|
|
4606
|
+
constructor({ firestore, interceptors, cache, }) {
|
|
4136
4607
|
super({
|
|
4137
4608
|
firestore,
|
|
4138
4609
|
collectionName: 'users',
|
|
4139
4610
|
model: User,
|
|
4140
4611
|
interceptors,
|
|
4612
|
+
cache,
|
|
4141
4613
|
});
|
|
4142
4614
|
}
|
|
4143
4615
|
async get(identifiers) {
|
|
@@ -4197,13 +4669,14 @@ tslib.__decorate([
|
|
|
4197
4669
|
], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
|
|
4198
4670
|
|
|
4199
4671
|
class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
|
|
4200
|
-
constructor({ firestore, interceptors }, parentRepository) {
|
|
4672
|
+
constructor({ firestore, interceptors, cache, }, parentRepository) {
|
|
4201
4673
|
super({
|
|
4202
4674
|
firestore,
|
|
4203
4675
|
collectionName: 'payment_method',
|
|
4204
4676
|
parentIdField: 'userId',
|
|
4205
4677
|
model: UserPaymentMethod,
|
|
4206
4678
|
interceptors,
|
|
4679
|
+
cache,
|
|
4207
4680
|
});
|
|
4208
4681
|
this.parentRepository = parentRepository;
|
|
4209
4682
|
}
|
|
@@ -4315,331 +4788,52 @@ class ConnectCollectionService {
|
|
|
4315
4788
|
return this;
|
|
4316
4789
|
}
|
|
4317
4790
|
fromStartAt(startingAt) {
|
|
4318
|
-
this.startingAt = startingAt;
|
|
4319
|
-
return this;
|
|
4320
|
-
}
|
|
4321
|
-
fromStartAfter(startingAt) {
|
|
4322
|
-
this.startingAfter = firestore.startAfter(startingAt);
|
|
4323
|
-
return this;
|
|
4324
|
-
}
|
|
4325
|
-
withConverter(params) {
|
|
4326
|
-
this.converter = params;
|
|
4327
|
-
this.reference = this.reference.withConverter({
|
|
4328
|
-
toFirestore: (data) => params.toFirestore(data),
|
|
4329
|
-
fromFirestore: (snapshot, options) => params.fromFirestore(new ConnectBaseDocumentSnapshot(snapshot), options),
|
|
4330
|
-
});
|
|
4331
|
-
return this;
|
|
4332
|
-
}
|
|
4333
|
-
async save(data, id) {
|
|
4334
|
-
if (lodash.isEmpty(id))
|
|
4335
|
-
return firestore.addDoc(this.reference, data);
|
|
4336
|
-
const docRef = firestore.doc(this.reference, id);
|
|
4337
|
-
await firestore.setDoc(docRef, data);
|
|
4338
|
-
return docRef;
|
|
4339
|
-
}
|
|
4340
|
-
}
|
|
4341
|
-
|
|
4342
|
-
class ConnectFirestoreService {
|
|
4343
|
-
constructor(firestore) {
|
|
4344
|
-
this.firestore = firestore;
|
|
4345
|
-
}
|
|
4346
|
-
getCollection(path) {
|
|
4347
|
-
return new ConnectCollectionService(path, this.firestore);
|
|
4348
|
-
}
|
|
4349
|
-
getDocument(path) {
|
|
4350
|
-
return new ConnectDocumentService(path, this.firestore);
|
|
4351
|
-
}
|
|
4352
|
-
}
|
|
4353
|
-
|
|
4354
|
-
class FirebaseFileUploaderService {
|
|
4355
|
-
constructor(storage, baseUrl) {
|
|
4356
|
-
this.storage = storage;
|
|
4357
|
-
this.baseUrl = baseUrl;
|
|
4358
|
-
}
|
|
4359
|
-
async upload(path, file) {
|
|
4360
|
-
const storageRef = storage.ref(this.storage, path);
|
|
4361
|
-
return storage.uploadBytes(storageRef, file).then((reference) => `${this.baseUrl}/${reference.ref.bucket}/${reference.ref.fullPath}`);
|
|
4362
|
-
}
|
|
4363
|
-
}
|
|
4364
|
-
|
|
4365
|
-
class AttributeOptionHelper {
|
|
4366
|
-
}
|
|
4367
|
-
AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
|
|
4368
|
-
var _a;
|
|
4369
|
-
if (fields.includes(attributeName))
|
|
4370
|
-
return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
|
|
4371
|
-
const field = fields.find((columnOption) => lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
|
|
4372
|
-
const fieldOption = (_a = is(field)) === null || _a === void 0 ? void 0 : _a[attributeName];
|
|
4373
|
-
if (lodash.isNil(fieldOption))
|
|
4374
|
-
return { columnName: attributeName.toString(), attributeName };
|
|
4375
|
-
if (Array.isArray(fieldOption))
|
|
4376
|
-
return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
|
|
4377
|
-
return Object.assign({ attributeName, columnName: attributeName.toString() }, fieldOption);
|
|
4378
|
-
};
|
|
4379
|
-
AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.columnName);
|
|
4380
|
-
AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
|
|
4381
|
-
if (fields.includes(columnName))
|
|
4382
|
-
return { columnName, attributeName: columnName };
|
|
4383
|
-
const field = is(fields.find((field) => {
|
|
4384
|
-
if (!lodash.isObject(field))
|
|
4385
|
-
return false;
|
|
4386
|
-
const columnOption = Object.values(field).find((option) => AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName ? option : {});
|
|
4387
|
-
return AttributeOptionHelper.CheckIsColumnOption(columnOption) && (columnOption === null || columnOption === void 0 ? void 0 : columnOption.columnName) === columnName;
|
|
4388
|
-
}) || {});
|
|
4389
|
-
const attributeName = Object.keys(field).find((fieldOptionFromList) => AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) || Array.isArray(field[fieldOptionFromList]));
|
|
4390
|
-
const fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
|
|
4391
|
-
if (Array.isArray(fieldOption))
|
|
4392
|
-
return { attributeName: attributeName, fields: fieldOption };
|
|
4393
|
-
return Object.assign({ attributeName: attributeName || columnName, columnName }, fieldOption);
|
|
4394
|
-
};
|
|
4395
|
-
|
|
4396
|
-
var HasuraGraphQLWhere;
|
|
4397
|
-
(function (HasuraGraphQLWhere) {
|
|
4398
|
-
HasuraGraphQLWhere["EQUALS"] = "_eq";
|
|
4399
|
-
HasuraGraphQLWhere["GT"] = "_gt";
|
|
4400
|
-
HasuraGraphQLWhere["GTE"] = "_gte";
|
|
4401
|
-
HasuraGraphQLWhere["IN"] = "_in";
|
|
4402
|
-
HasuraGraphQLWhere["NOTIN"] = "_nin";
|
|
4403
|
-
HasuraGraphQLWhere["LT"] = "_lt";
|
|
4404
|
-
HasuraGraphQLWhere["LTE"] = "_lte";
|
|
4405
|
-
HasuraGraphQLWhere["LIKE"] = "_like";
|
|
4406
|
-
HasuraGraphQLWhere["ILIKE"] = "_ilike";
|
|
4407
|
-
HasuraGraphQLWhere["NOTLIKE"] = "_nlike";
|
|
4408
|
-
HasuraGraphQLWhere["ISNULL"] = "_is_null";
|
|
4409
|
-
HasuraGraphQLWhere["ISNOTNULL"] = "_is_null";
|
|
4410
|
-
HasuraGraphQLWhere["JSON_CONTAINS"] = "_contains";
|
|
4411
|
-
HasuraGraphQLWhere["JSON_HAS_KEYS_ANY"] = "_has_keys_any";
|
|
4412
|
-
HasuraGraphQLWhere["IREGEX"] = "_iregex";
|
|
4413
|
-
HasuraGraphQLWhere["REGEX"] = "_regex";
|
|
4414
|
-
})(HasuraGraphQLWhere || (HasuraGraphQLWhere = {}));
|
|
4415
|
-
|
|
4416
|
-
var HasuraGraphQLColumnType;
|
|
4417
|
-
(function (HasuraGraphQLColumnType) {
|
|
4418
|
-
HasuraGraphQLColumnType["Int"] = "Int";
|
|
4419
|
-
HasuraGraphQLColumnType["Float"] = "Float";
|
|
4420
|
-
HasuraGraphQLColumnType["Boolean"] = "Boolean";
|
|
4421
|
-
HasuraGraphQLColumnType["String"] = "String";
|
|
4422
|
-
HasuraGraphQLColumnType["DateTime"] = "timestampz";
|
|
4423
|
-
HasuraGraphQLColumnType["Json"] = "json";
|
|
4424
|
-
HasuraGraphQLColumnType["Jsonb"] = "jsonb";
|
|
4425
|
-
HasuraGraphQLColumnType["Enum"] = "enum";
|
|
4426
|
-
HasuraGraphQLColumnType["Uuid"] = "uuid";
|
|
4427
|
-
})(HasuraGraphQLColumnType || (HasuraGraphQLColumnType = {}));
|
|
4428
|
-
|
|
4429
|
-
class FilterOptionHelper {
|
|
4430
|
-
}
|
|
4431
|
-
FilterOptionHelper.CheckIfIsFilterOption = (filter) => !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator);
|
|
4432
|
-
FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
|
|
4433
|
-
if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
|
|
4434
|
-
return filter;
|
|
4435
|
-
if (filter.operator === exports.Where.ISNULL)
|
|
4436
|
-
return true;
|
|
4437
|
-
if (filter.operator === exports.Where.ISNOTNULL)
|
|
4438
|
-
return false;
|
|
4439
|
-
const converter = fieldOption.to
|
|
4440
|
-
? fieldOption.to
|
|
4441
|
-
: (value) => filter.operator === exports.Where.LIKE && !Array.isArray(filter.value) && value.indexOf('%') < 0
|
|
4442
|
-
? `%${value}%`
|
|
4443
|
-
: value;
|
|
4444
|
-
const converterResult = Array.isArray(filter.value) && !fieldOption.fields && [exports.Where.IN, exports.Where.NOTIN].includes(filter.operator)
|
|
4445
|
-
? filter.value.map((fieldValue) => converter(fieldValue))
|
|
4446
|
-
: converter(filter.value);
|
|
4447
|
-
const newValue = filter.ignoreCase && !filter.ignoreAccent && !Array.isArray(filter.value) && converterResult.indexOf('%') < 0
|
|
4448
|
-
? `%${converterResult}%`
|
|
4449
|
-
: converterResult;
|
|
4450
|
-
return filter.ignoreAccent && !Array.isArray(filter.value)
|
|
4451
|
-
? FilterOptionHelper.buildInsensitiveSentence(newValue)
|
|
4452
|
-
: newValue;
|
|
4453
|
-
};
|
|
4454
|
-
FilterOptionHelper.buildInsensitiveSentence = (value) => {
|
|
4455
|
-
const valueWithoutAccents = FilterOptionHelper.removeAccents(value);
|
|
4456
|
-
let result = '';
|
|
4457
|
-
for (const char of valueWithoutAccents) {
|
|
4458
|
-
const allCharOptions = [];
|
|
4459
|
-
if (['a', 'e', 'i', 'o', 'u', 'c', 'A', 'E', 'I', 'O', 'U', 'C'].includes(char)) {
|
|
4460
|
-
const charOptions = {
|
|
4461
|
-
a: ['á', 'â', 'ã', 'à', 'a'],
|
|
4462
|
-
e: ['é', 'ê', 'ẽ', 'è', 'e'],
|
|
4463
|
-
i: ['í', 'î', 'ĩ', 'ì', 'i'],
|
|
4464
|
-
o: ['ó', 'ô', 'õ', 'ò', 'o'],
|
|
4465
|
-
u: ['ú', 'û', 'ũ', 'ù', 'u'],
|
|
4466
|
-
c: ['ç', 'c'],
|
|
4467
|
-
A: ['Á', 'Â', 'Ã', 'À', 'A'],
|
|
4468
|
-
E: ['É', 'Ê', 'Ẽ', 'È', 'E'],
|
|
4469
|
-
I: ['Í', 'Î', 'Ĩ', 'Ì', 'I'],
|
|
4470
|
-
O: ['Ó', 'Ô', 'Õ', 'Ò', 'O'],
|
|
4471
|
-
U: ['Ú', 'Û', 'Ũ', 'Ù', 'U'],
|
|
4472
|
-
C: ['Ç', 'C'],
|
|
4473
|
-
};
|
|
4474
|
-
allCharOptions.push(...charOptions[char]);
|
|
4475
|
-
result += `[${allCharOptions.join('')}]`;
|
|
4476
|
-
}
|
|
4477
|
-
else {
|
|
4478
|
-
result += char;
|
|
4479
|
-
}
|
|
4480
|
-
}
|
|
4481
|
-
return result;
|
|
4482
|
-
};
|
|
4483
|
-
FilterOptionHelper.removeAccents = (text) => {
|
|
4484
|
-
return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
4485
|
-
};
|
|
4486
|
-
|
|
4487
|
-
class BindFilterQueryHelper {
|
|
4488
|
-
}
|
|
4489
|
-
BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter).reduce((variables, fieldName) => {
|
|
4490
|
-
const columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
|
|
4491
|
-
if (!columnOption.bindFindFilter)
|
|
4492
|
-
return Object.assign(Object.assign({}, variables), {
|
|
4493
|
-
[columnOption.columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, filter[fieldName], fields),
|
|
4494
|
-
});
|
|
4495
|
-
const builtFilter = columnOption.bindFindFilter(filter[fieldName]);
|
|
4496
|
-
return Object.assign(Object.assign({}, variables), Object.keys(builtFilter).reduce((variablesList, columnName) => (Object.assign(Object.assign({}, variablesList), { [columnName]: BindFilterQueryHelper.BuildWhereSentence(fieldName, builtFilter[columnName], fields) })), {}));
|
|
4497
|
-
}, {});
|
|
4498
|
-
BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
|
|
4499
|
-
const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
|
|
4500
|
-
const isNestedField = !Array.isArray(options) &&
|
|
4501
|
-
lodash.isObject(options) &&
|
|
4502
|
-
lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) &&
|
|
4503
|
-
lodash.isNil(options === null || options === void 0 ? void 0 : options.value) &&
|
|
4504
|
-
lodash.isNil(fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.to);
|
|
4505
|
-
if (isNestedField)
|
|
4506
|
-
return Object.keys(options).reduce((variables, key) => {
|
|
4507
|
-
const fieldOptions = AttributeOptionHelper.FindByAttribute(key, (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || fields);
|
|
4508
|
-
const columnName = fieldOptions.columnName;
|
|
4509
|
-
const columnFields = fieldOptions.fields;
|
|
4510
|
-
return Object.assign(Object.assign({}, variables), { [columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || columnFields || fields) });
|
|
4511
|
-
}, {});
|
|
4512
|
-
if (!Array.isArray(options) && !lodash.isNil(fieldSentenceOptions.fields))
|
|
4513
|
-
return {
|
|
4514
|
-
[fieldSentenceOptions.fields[0]]: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions),
|
|
4515
|
-
};
|
|
4516
|
-
if (!Array.isArray(options) && lodash.isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
|
|
4517
|
-
options = Object.values(options)[0];
|
|
4518
|
-
return Array.isArray(options)
|
|
4519
|
-
? options.reduce((whereSentence, option) => (Object.assign(Object.assign({}, whereSentence), BindFilterQueryHelper.BuildOperatorSentence(option, fieldSentenceOptions))), {})
|
|
4520
|
-
: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions);
|
|
4521
|
-
};
|
|
4522
|
-
BindFilterQueryHelper.BuildOperatorSentence = (options, fieldOption) => ({
|
|
4523
|
-
[BindFilterQueryHelper.GetHasuraOperator(options, fieldOption)]: FilterOptionHelper.GetValueFromFilter(options, fieldOption),
|
|
4524
|
-
});
|
|
4525
|
-
BindFilterQueryHelper.GetHasuraOperator = (options, fieldOption) => FilterOptionHelper.CheckIfIsFilterOption(options)
|
|
4526
|
-
? fieldOption.type === HasuraGraphQLColumnType.Jsonb
|
|
4527
|
-
? BindFilterQueryHelper.GetHasuraJsonbOperator(options)
|
|
4528
|
-
: options.operator === exports.Where.LIKE && options.ignoreCase && options.ignoreAccent
|
|
4529
|
-
? HasuraGraphQLWhere.IREGEX
|
|
4530
|
-
: options.operator === exports.Where.LIKE && options.ignoreAccent
|
|
4531
|
-
? HasuraGraphQLWhere.REGEX
|
|
4532
|
-
: options.operator === exports.Where.LIKE && options.ignoreCase
|
|
4533
|
-
? HasuraGraphQLWhere.ILIKE
|
|
4534
|
-
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
4535
|
-
Object.keys(exports.Where).find((operator) => exports.Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))]
|
|
4536
|
-
: HasuraGraphQLWhere.EQUALS;
|
|
4537
|
-
BindFilterQueryHelper.GetHasuraJsonbOperator = (options) => options.operator === exports.Where.IN
|
|
4538
|
-
? HasuraGraphQLWhere.JSON_CONTAINS
|
|
4539
|
-
: options.operator === exports.Where.LIKE
|
|
4540
|
-
? HasuraGraphQLWhere.JSON_HAS_KEYS_ANY
|
|
4541
|
-
: HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find((graphQLOperator) => graphQLOperator ===
|
|
4542
|
-
Object.keys(exports.Where).find((operator) => exports.Where[operator] === (options === null || options === void 0 ? void 0 : options.operator)))];
|
|
4791
|
+
this.startingAt = startingAt;
|
|
4792
|
+
return this;
|
|
4793
|
+
}
|
|
4794
|
+
fromStartAfter(startingAt) {
|
|
4795
|
+
this.startingAfter = firestore.startAfter(startingAt);
|
|
4796
|
+
return this;
|
|
4797
|
+
}
|
|
4798
|
+
withConverter(params) {
|
|
4799
|
+
this.converter = params;
|
|
4800
|
+
this.reference = this.reference.withConverter({
|
|
4801
|
+
toFirestore: (data) => params.toFirestore(data),
|
|
4802
|
+
fromFirestore: (snapshot, options) => params.fromFirestore(new ConnectBaseDocumentSnapshot(snapshot), options),
|
|
4803
|
+
});
|
|
4804
|
+
return this;
|
|
4805
|
+
}
|
|
4806
|
+
async save(data, id) {
|
|
4807
|
+
if (lodash.isEmpty(id))
|
|
4808
|
+
return firestore.addDoc(this.reference, data);
|
|
4809
|
+
const docRef = firestore.doc(this.reference, id);
|
|
4810
|
+
await firestore.setDoc(docRef, data);
|
|
4811
|
+
return docRef;
|
|
4812
|
+
}
|
|
4813
|
+
}
|
|
4543
4814
|
|
|
4544
|
-
class
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
|
|
4548
|
-
return fields === null || fields === void 0 ? void 0 : fields.map((field) => {
|
|
4549
|
-
if (lodash.isString(field))
|
|
4550
|
-
return field.toString();
|
|
4551
|
-
if (field === 'affected_rows')
|
|
4552
|
-
return field;
|
|
4553
|
-
const fieldName = Object.keys(field).shift();
|
|
4554
|
-
const fieldValue = is(field[fieldName]);
|
|
4555
|
-
if (Array.isArray(fieldValue))
|
|
4556
|
-
return { [fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue) };
|
|
4557
|
-
if (!AttributeOptionHelper.CheckIsColumnOption(fieldValue))
|
|
4558
|
-
return;
|
|
4559
|
-
const isNestedField = !!fieldValue.fields;
|
|
4560
|
-
if (isNestedField)
|
|
4561
|
-
return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
|
|
4562
|
-
return fieldValue.columnName;
|
|
4563
|
-
}).filter((field) => !!field);
|
|
4564
|
-
};
|
|
4565
|
-
GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).reduce((result, columnName) => {
|
|
4566
|
-
const { attributeName, fields: attributeFields, from, } = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields);
|
|
4567
|
-
if (!!attributeFields && Array.isArray(attributeFields)) {
|
|
4568
|
-
if (Array.isArray(data[columnName]))
|
|
4569
|
-
return Object.assign(Object.assign({}, result), { [attributeName]: from
|
|
4570
|
-
? from(data[columnName], data)
|
|
4571
|
-
: is(data[columnName]).map((value) => GraphQLFieldHelper.ConvertFieldValueFrom(is(value), attributeFields)) });
|
|
4572
|
-
if (lodash.isObject(data[columnName]))
|
|
4573
|
-
return Object.assign(Object.assign({}, result), { [attributeName]: !!from
|
|
4574
|
-
? from(data[columnName])
|
|
4575
|
-
: GraphQLFieldHelper.ConvertFieldValueFrom(is(data[columnName]), attributeFields) });
|
|
4815
|
+
class ConnectFirestoreService {
|
|
4816
|
+
constructor(firestore) {
|
|
4817
|
+
this.firestore = firestore;
|
|
4576
4818
|
}
|
|
4577
|
-
|
|
4578
|
-
return
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
|
|
4596
|
-
return Object.assign(Object.assign({}, object), { [foreignColumnName]: (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current] });
|
|
4597
|
-
}, Object.assign({}, result));
|
|
4598
|
-
if (update &&
|
|
4599
|
-
lodash.isObject(data[attributeName]) &&
|
|
4600
|
-
!lodash.isNil(attributeFields) &&
|
|
4601
|
-
!lodash.isDate(data[attributeName]))
|
|
4602
|
-
return result;
|
|
4603
|
-
if (!!columnName &&
|
|
4604
|
-
Array.isArray(attributeFields) &&
|
|
4605
|
-
lodash.isObject(data[attributeName])) {
|
|
4606
|
-
const converted = !lodash.isNil(columnName) && to
|
|
4607
|
-
? to(instance[attributeName], instance)
|
|
4608
|
-
: data[attributeName];
|
|
4609
|
-
return Object.assign(Object.assign({}, result), (converted !== undefined
|
|
4610
|
-
? {
|
|
4611
|
-
[columnName]: {
|
|
4612
|
-
data: instance[attributeName] instanceof BaseModel
|
|
4613
|
-
? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
|
|
4614
|
-
: converted,
|
|
4615
|
-
},
|
|
4616
|
-
}
|
|
4617
|
-
: {}));
|
|
4618
|
-
}
|
|
4619
|
-
if (!!to)
|
|
4620
|
-
return Object.assign(Object.assign({}, result), { [columnName]: to(instance[attributeName], instance) });
|
|
4621
|
-
return Object.assign(Object.assign({}, result), { [columnName]: data[attributeName] });
|
|
4622
|
-
}, {});
|
|
4623
|
-
};
|
|
4624
|
-
GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
|
|
4625
|
-
const hasCustomFilters = !!fieldValue.filters;
|
|
4626
|
-
if (hasCustomFilters)
|
|
4627
|
-
return {
|
|
4628
|
-
operation: fieldValue.columnName || fieldName,
|
|
4629
|
-
fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
4630
|
-
variables: {
|
|
4631
|
-
[`${fieldValue.columnName}_where`]: {
|
|
4632
|
-
name: 'where',
|
|
4633
|
-
type: fieldValue.filters.filterType,
|
|
4634
|
-
value: BindFilterQueryHelper.MakeGraphQLWhere(fieldValue.filters.filters, fieldValue.fields),
|
|
4635
|
-
required: true,
|
|
4636
|
-
},
|
|
4637
|
-
},
|
|
4638
|
-
};
|
|
4639
|
-
return {
|
|
4640
|
-
[fieldValue.columnName || fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
|
|
4641
|
-
};
|
|
4642
|
-
};
|
|
4819
|
+
getCollection(path) {
|
|
4820
|
+
return new ConnectCollectionService(path, this.firestore);
|
|
4821
|
+
}
|
|
4822
|
+
getDocument(path) {
|
|
4823
|
+
return new ConnectDocumentService(path, this.firestore);
|
|
4824
|
+
}
|
|
4825
|
+
}
|
|
4826
|
+
|
|
4827
|
+
class FirebaseFileUploaderService {
|
|
4828
|
+
constructor(storage, baseUrl) {
|
|
4829
|
+
this.storage = storage;
|
|
4830
|
+
this.baseUrl = baseUrl;
|
|
4831
|
+
}
|
|
4832
|
+
async upload(path, file) {
|
|
4833
|
+
const storageRef = storage.ref(this.storage, path);
|
|
4834
|
+
return storage.uploadBytes(storageRef, file).then((reference) => `${this.baseUrl}/${reference.ref.bucket}/${reference.ref.fullPath}`);
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
4643
4837
|
|
|
4644
4838
|
const withCreateHasuraGraphQL = (MixinBase) => {
|
|
4645
4839
|
return class CreateHasuraGraphQLMixin extends MixinBase {
|
|
@@ -4688,7 +4882,13 @@ const withDeleteHasuraGraphQL = (MixinBase) => {
|
|
|
4688
4882
|
this.deleteGraphQLOperation = (options === null || options === void 0 ? void 0 : options.deleteGraphQLOperation) || `delete_${this.tableName}_by_pk`;
|
|
4689
4883
|
}
|
|
4690
4884
|
async delete(identifiers) {
|
|
4885
|
+
var _a;
|
|
4691
4886
|
this.logger = DebugHelper.from(this, 'delete');
|
|
4887
|
+
if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
|
|
4888
|
+
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
|
|
4889
|
+
await this.cache.cacheAdapter.remove(cacheKey);
|
|
4890
|
+
this.logger.log(`Cache removido: ${cacheKey}`);
|
|
4891
|
+
}
|
|
4692
4892
|
const instance = this.model.toInstance(identifiers);
|
|
4693
4893
|
await this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), this.model.identifiersFields.reduce((ids, identifier) => {
|
|
4694
4894
|
const identifierBinded = identifier;
|
|
@@ -4726,6 +4926,7 @@ const withHasuraGraphQL = (MixinBase) => {
|
|
|
4726
4926
|
this.model = options.model;
|
|
4727
4927
|
this.fields = options.fields || this.model.identifiersFields;
|
|
4728
4928
|
this.logger = DebugHelper.from(this);
|
|
4929
|
+
this.cache = options.cache;
|
|
4729
4930
|
}
|
|
4730
4931
|
async mutation(operation, fields, variables) {
|
|
4731
4932
|
const resultQuery = gqlQueryBuilder.mutation({
|
|
@@ -4827,9 +5028,29 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
4827
5028
|
this.updateGraphQLObjectType = (options === null || options === void 0 ? void 0 : options.updateGraphQLObjectType) || `${this.tableName}_set_input`;
|
|
4828
5029
|
this.updateGraphQLPKType = (options === null || options === void 0 ? void 0 : options.updateGraphQLPKType) || `${this.tableName}_pk_columns_input`;
|
|
4829
5030
|
}
|
|
5031
|
+
getIdentifiersFromData(data) {
|
|
5032
|
+
const instance = this.model.toInstance(data);
|
|
5033
|
+
const identifiers = {};
|
|
5034
|
+
this.model.identifiersFields.forEach((identifier) => {
|
|
5035
|
+
const field = identifier;
|
|
5036
|
+
if (!lodash.isNil(instance[field])) {
|
|
5037
|
+
identifiers[String(field)] = instance[field];
|
|
5038
|
+
}
|
|
5039
|
+
});
|
|
5040
|
+
return identifiers;
|
|
5041
|
+
}
|
|
4830
5042
|
async update(data) {
|
|
5043
|
+
var _a;
|
|
4831
5044
|
this.logger = DebugHelper.from(this, 'update');
|
|
4832
5045
|
const plainData = this.paramsToPlain(data);
|
|
5046
|
+
if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
|
|
5047
|
+
const identifiers = this.getIdentifiersFromData(plainData);
|
|
5048
|
+
if (Object.keys(identifiers).length > 0) {
|
|
5049
|
+
const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
|
|
5050
|
+
await this.cache.cacheAdapter.remove(cacheKey);
|
|
5051
|
+
this.logger.log(`Cache removido: ${cacheKey}`);
|
|
5052
|
+
}
|
|
5053
|
+
}
|
|
4833
5054
|
await this.mutation(this.updateGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), {
|
|
4834
5055
|
_set: {
|
|
4835
5056
|
type: this.updateGraphQLObjectType,
|
|
@@ -4870,8 +5091,20 @@ const withGetHasuraGraphQL = (MixinBase) => {
|
|
|
4870
5091
|
super(...params);
|
|
4871
5092
|
this.getGraphQLOperation = (options === null || options === void 0 ? void 0 : options.getGraphQLOperation) || `${this.tableName}_by_pk`;
|
|
4872
5093
|
}
|
|
4873
|
-
|
|
5094
|
+
generateCacheKey(identifiers) {
|
|
5095
|
+
return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
|
|
5096
|
+
}
|
|
5097
|
+
async get(identifiers, options) {
|
|
5098
|
+
var _a, _b, _c, _d, _e;
|
|
4874
5099
|
this.logger = DebugHelper.from(this, 'get');
|
|
5100
|
+
if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
|
|
5101
|
+
const cacheKey = this.generateCacheKey(identifiers);
|
|
5102
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
5103
|
+
if (cachedData) {
|
|
5104
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
5105
|
+
return this.model.toInstance(JSON.parse(cachedData));
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
4875
5108
|
const instance = this.model.toInstance(identifiers);
|
|
4876
5109
|
const result = await this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce((ids, identifier) => {
|
|
4877
5110
|
var _a;
|
|
@@ -4890,12 +5123,26 @@ const withGetHasuraGraphQL = (MixinBase) => {
|
|
|
4890
5123
|
const data = result[this.getGraphQLOperation];
|
|
4891
5124
|
if (lodash.isNil(data))
|
|
4892
5125
|
throw new NotFoundError(`${instance.constructor.name} not found`);
|
|
4893
|
-
|
|
5126
|
+
const resultModel = this.convertDataFromHasura(result[this.getGraphQLOperation]);
|
|
5127
|
+
if (((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter) && ((_d = options === null || options === void 0 ? void 0 : options.cache) === null || _d === void 0 ? void 0 : _d.enabled)) {
|
|
5128
|
+
const cacheKey = this.generateCacheKey(identifiers);
|
|
5129
|
+
await this.cache.cacheAdapter.set({
|
|
5130
|
+
key: cacheKey,
|
|
5131
|
+
data: JSON.stringify(resultModel.toPlain()),
|
|
5132
|
+
expirationInSeconds: ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl) || this.cache.ttlDefault,
|
|
5133
|
+
});
|
|
5134
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5135
|
+
}
|
|
5136
|
+
return resultModel;
|
|
4894
5137
|
}
|
|
4895
5138
|
};
|
|
4896
5139
|
};
|
|
4897
5140
|
|
|
4898
5141
|
const withFindHasuraGraphQL = (MixinBase) => {
|
|
5142
|
+
const generateCacheKey = (model, params) => {
|
|
5143
|
+
const md5 = MD5GeneratorHelper.generateMD5(params);
|
|
5144
|
+
return `${model.name.toLowerCase()}:find:${md5}`;
|
|
5145
|
+
};
|
|
4899
5146
|
return class FindHasuraGraphQLMixin extends MixinBase {
|
|
4900
5147
|
constructor() {
|
|
4901
5148
|
super(...arguments);
|
|
@@ -4934,12 +5181,20 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
4934
5181
|
return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
|
|
4935
5182
|
});
|
|
4936
5183
|
}
|
|
4937
|
-
async find(params) {
|
|
4938
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
5184
|
+
async find(params, options) {
|
|
5185
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
4939
5186
|
this.logger = DebugHelper.from(this, 'find');
|
|
4940
|
-
const { filters, limits, orderBy, options } = params || {};
|
|
5187
|
+
const { filters, limits, orderBy, options: findOptions } = params || {};
|
|
4941
5188
|
const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
|
|
4942
|
-
const enableCount = (_a =
|
|
5189
|
+
const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
|
|
5190
|
+
if (((_b = this.cache) === null || _b === void 0 ? void 0 : _b.cacheAdapter) && ((_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.enabled)) {
|
|
5191
|
+
const cacheKey = generateCacheKey(this.model, params);
|
|
5192
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
5193
|
+
if (cachedData) {
|
|
5194
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
5195
|
+
return this.bindResult(JSON.parse(cachedData), { enableCount, findOptions, tableFiltersNamed });
|
|
5196
|
+
}
|
|
5197
|
+
}
|
|
4943
5198
|
const variablesFilters = lodash.isNil(filters)
|
|
4944
5199
|
? {}
|
|
4945
5200
|
: {
|
|
@@ -4990,7 +5245,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
4990
5245
|
]
|
|
4991
5246
|
: []),
|
|
4992
5247
|
...((!this.lastDistinct[tableFiltersNamed] &&
|
|
4993
|
-
((
|
|
5248
|
+
((_e = (_d = params.options) === null || _d === void 0 ? void 0 : _d.distinct) === null || _e === void 0 ? void 0 : _e.map((distinct) => {
|
|
4994
5249
|
var _a, _b;
|
|
4995
5250
|
const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
|
|
4996
5251
|
const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
|
|
@@ -5010,29 +5265,43 @@ const withFindHasuraGraphQL = (MixinBase) => {
|
|
|
5010
5265
|
}))) ||
|
|
5011
5266
|
[]),
|
|
5012
5267
|
]);
|
|
5268
|
+
if (((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) && ((_g = options === null || options === void 0 ? void 0 : options.cache) === null || _g === void 0 ? void 0 : _g.enabled)) {
|
|
5269
|
+
const cacheKey = generateCacheKey(this.model, params);
|
|
5270
|
+
await this.cache.cacheAdapter.set({
|
|
5271
|
+
key: cacheKey,
|
|
5272
|
+
data: JSON.stringify(result),
|
|
5273
|
+
expirationInSeconds: ((_h = options === null || options === void 0 ? void 0 : options.cache) === null || _h === void 0 ? void 0 : _h.ttl) || this.cache.ttlDefault,
|
|
5274
|
+
});
|
|
5275
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
5276
|
+
}
|
|
5277
|
+
return this.bindResult(result, { enableCount, findOptions, tableFiltersNamed });
|
|
5278
|
+
}
|
|
5279
|
+
bindResult(result, { enableCount, findOptions, tableFiltersNamed, }) {
|
|
5280
|
+
var _a, _b, _c, _d;
|
|
5013
5281
|
const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
|
|
5014
|
-
|
|
5282
|
+
const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _a === void 0 ? void 0 : _a.length)
|
|
5015
5283
|
? {
|
|
5016
|
-
minimal:
|
|
5284
|
+
minimal: findOptions.minimal.reduce((minimals, current) => {
|
|
5017
5285
|
var _a;
|
|
5018
5286
|
return (Object.assign(Object.assign({}, minimals), lodash.set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
|
|
5019
5287
|
}, {}),
|
|
5020
5288
|
}
|
|
5021
|
-
: {})), (((
|
|
5289
|
+
: {})), (((_b = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _b === void 0 ? void 0 : _b.length)
|
|
5022
5290
|
? {
|
|
5023
|
-
maximum:
|
|
5291
|
+
maximum: findOptions.maximum.reduce((maximums, current) => {
|
|
5024
5292
|
var _a;
|
|
5025
5293
|
return (Object.assign(Object.assign({}, maximums), lodash.set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
|
|
5026
5294
|
}, {}),
|
|
5027
5295
|
}
|
|
5028
|
-
: {})), (((
|
|
5029
|
-
distinct: (
|
|
5296
|
+
: {})), (((_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _c === void 0 ? void 0 : _c.length) && {
|
|
5297
|
+
distinct: (_d = this.lastDistinct[tableFiltersNamed]) !== null && _d !== void 0 ? _d : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
|
|
5030
5298
|
var _a, _b;
|
|
5031
5299
|
const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
|
|
5032
5300
|
const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
|
|
5033
5301
|
return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
|
|
5034
5302
|
}, {})),
|
|
5035
5303
|
}));
|
|
5304
|
+
return findResult;
|
|
5036
5305
|
}
|
|
5037
5306
|
};
|
|
5038
5307
|
};
|
|
@@ -5074,7 +5343,7 @@ tslib.__decorate([
|
|
|
5074
5343
|
], ProductErrorsHasuraGraphQL.prototype, "product", void 0);
|
|
5075
5344
|
|
|
5076
5345
|
class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
5077
|
-
constructor({ endpoint, authOptions, interceptors, }) {
|
|
5346
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
5078
5347
|
super({
|
|
5079
5348
|
tableName: 'category_collection_children',
|
|
5080
5349
|
model: CategoryCollectionChildren,
|
|
@@ -5105,12 +5374,13 @@ class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGr
|
|
|
5105
5374
|
},
|
|
5106
5375
|
},
|
|
5107
5376
|
],
|
|
5377
|
+
cache,
|
|
5108
5378
|
});
|
|
5109
5379
|
}
|
|
5110
5380
|
}
|
|
5111
5381
|
|
|
5112
5382
|
class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
5113
|
-
constructor({ endpoint, authOptions, interceptors, }) {
|
|
5383
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
5114
5384
|
super({
|
|
5115
5385
|
tableName: 'category_filter',
|
|
5116
5386
|
model: CategoryFilter,
|
|
@@ -5192,6 +5462,7 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
|
|
|
5192
5462
|
},
|
|
5193
5463
|
},
|
|
5194
5464
|
],
|
|
5465
|
+
cache,
|
|
5195
5466
|
});
|
|
5196
5467
|
}
|
|
5197
5468
|
deleteByCategory(categoryId) {
|
|
@@ -5227,13 +5498,14 @@ tslib.__decorate([
|
|
|
5227
5498
|
], CategoryFilterHasuraGraphQLRepository.prototype, "deleteByCategoryAndFilter", null);
|
|
5228
5499
|
|
|
5229
5500
|
class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
5230
|
-
constructor({ endpoint, authOptions, interceptors, }, productRepository, categoryFilterRepository) {
|
|
5501
|
+
constructor({ endpoint, authOptions, interceptors, cache, }, productRepository, categoryFilterRepository) {
|
|
5231
5502
|
super({
|
|
5232
5503
|
tableName: 'category',
|
|
5233
5504
|
model: Category,
|
|
5234
5505
|
endpoint,
|
|
5235
5506
|
authOptions,
|
|
5236
5507
|
interceptors,
|
|
5508
|
+
cache,
|
|
5237
5509
|
fields: [
|
|
5238
5510
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
5239
5511
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -5330,6 +5602,17 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5330
5602
|
});
|
|
5331
5603
|
this.productRepository = productRepository;
|
|
5332
5604
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
5605
|
+
this.reorganizeMostRelevantsProducts = (products, mostRelevantsIds, limit) => {
|
|
5606
|
+
const mostRelevantWithouyStock = products.filter((product) => mostRelevantsIds.includes(product.id) && product.stock.quantity <= 0);
|
|
5607
|
+
const firstProducts = products
|
|
5608
|
+
.filter((product) => mostRelevantsIds.includes(product.id) && product.stock.quantity > 0)
|
|
5609
|
+
.sort((a, b) => mostRelevantsIds.indexOf(a.id) - mostRelevantsIds.indexOf(b.id));
|
|
5610
|
+
const lastProducts = products
|
|
5611
|
+
.filter((product) => !mostRelevantsIds.includes(product.id) && product.stock.quantity > 0)
|
|
5612
|
+
.concat(mostRelevantWithouyStock);
|
|
5613
|
+
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
5614
|
+
return limit ? categoryMostRelevants.slice(0, limit) : categoryMostRelevants;
|
|
5615
|
+
};
|
|
5333
5616
|
}
|
|
5334
5617
|
async create(params) {
|
|
5335
5618
|
const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
|
|
@@ -5349,11 +5632,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5349
5632
|
},
|
|
5350
5633
|
} }));
|
|
5351
5634
|
}
|
|
5352
|
-
async get(identifiers) {
|
|
5635
|
+
async get(identifiers, optionsCache) {
|
|
5353
5636
|
var _a;
|
|
5354
5637
|
return Number.isNaN(+identifiers.id)
|
|
5355
|
-
? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }))
|
|
5356
|
-
|
|
5638
|
+
? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, optionsCache))
|
|
5639
|
+
.data) === null || _a === void 0 ? void 0 : _a[0]
|
|
5640
|
+
: super.get(identifiers, optionsCache);
|
|
5357
5641
|
}
|
|
5358
5642
|
async update(params) {
|
|
5359
5643
|
const { products, id: checkId, metadatas, filters } = params, data = tslib.__rest(params, ["products", "id", "metadatas", "filters"]);
|
|
@@ -5365,7 +5649,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5365
5649
|
category.filters = filters && (await this.updateFilters(+id, { filters }));
|
|
5366
5650
|
return category;
|
|
5367
5651
|
}
|
|
5368
|
-
async getCategoryBySlug(slug, shop) {
|
|
5652
|
+
async getCategoryBySlug(slug, shop, optionsCache) {
|
|
5369
5653
|
if (!slug)
|
|
5370
5654
|
return null;
|
|
5371
5655
|
const { data } = await this.find({
|
|
@@ -5377,14 +5661,14 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5377
5661
|
options: {
|
|
5378
5662
|
enableCount: false,
|
|
5379
5663
|
},
|
|
5380
|
-
});
|
|
5664
|
+
}, optionsCache);
|
|
5381
5665
|
if (!data.length)
|
|
5382
5666
|
throw new NotFoundError(`Category with slug ${slug} not found`);
|
|
5383
5667
|
if (data.length > 1)
|
|
5384
5668
|
throw new DuplicatedResultsError('Query returned duplicated values');
|
|
5385
5669
|
return data.shift();
|
|
5386
5670
|
}
|
|
5387
|
-
async getCategoryByShop(shop) {
|
|
5671
|
+
async getCategoryByShop(shop, optionsCache) {
|
|
5388
5672
|
if (!shop)
|
|
5389
5673
|
return;
|
|
5390
5674
|
const { data } = await this.find({
|
|
@@ -5396,10 +5680,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5396
5680
|
options: {
|
|
5397
5681
|
enableCount: false,
|
|
5398
5682
|
},
|
|
5399
|
-
});
|
|
5683
|
+
}, optionsCache);
|
|
5400
5684
|
return data;
|
|
5401
5685
|
}
|
|
5402
|
-
async getCategoriesForHome(categoryIds, shop, limit = 4) {
|
|
5686
|
+
async getCategoriesForHome(categoryIds, shop, limit = 4, optionsCache) {
|
|
5403
5687
|
if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
|
|
5404
5688
|
return [];
|
|
5405
5689
|
const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
|
|
@@ -5407,83 +5691,86 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5407
5691
|
const categories = [];
|
|
5408
5692
|
if (categoriesFirestore.length)
|
|
5409
5693
|
categories.push(...(await this.find({
|
|
5410
|
-
filters: {
|
|
5411
|
-
|
|
5694
|
+
filters: {
|
|
5695
|
+
firestoreId: { operator: exports.Where.IN, value: categoriesFirestore.filter(Boolean) },
|
|
5696
|
+
published: true,
|
|
5697
|
+
},
|
|
5698
|
+
}, optionsCache).then(({ data }) => data)));
|
|
5412
5699
|
if (categoriesHasura.length)
|
|
5413
5700
|
categories.push(...(await this.find({
|
|
5414
5701
|
filters: {
|
|
5415
5702
|
id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) },
|
|
5416
5703
|
published: true,
|
|
5417
5704
|
},
|
|
5418
|
-
}).then(({ data }) => data)));
|
|
5705
|
+
}, optionsCache).then(({ data }) => data)));
|
|
5419
5706
|
if (!categories.length)
|
|
5420
5707
|
return [];
|
|
5421
5708
|
const homeSections = await Promise.all(categories.map(async (category) => ({
|
|
5422
5709
|
category,
|
|
5423
|
-
products: await this.mountCategory(category, shop, { limit, hasStock: true }),
|
|
5710
|
+
products: await this.mountCategory(category, shop, { limit, hasStock: true }, optionsCache),
|
|
5424
5711
|
})));
|
|
5425
5712
|
return homeSections;
|
|
5426
5713
|
}
|
|
5427
|
-
async mountCategory(category, shop, options) {
|
|
5714
|
+
async mountCategory(category, shop, options, optionsCache) {
|
|
5428
5715
|
var _a;
|
|
5429
5716
|
if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
|
|
5430
5717
|
return [];
|
|
5431
|
-
const
|
|
5432
|
-
|
|
5718
|
+
const fields = [
|
|
5719
|
+
'id',
|
|
5720
|
+
'name',
|
|
5721
|
+
'slug',
|
|
5722
|
+
'images',
|
|
5723
|
+
'miniatures',
|
|
5724
|
+
'price',
|
|
5725
|
+
'fullPrice',
|
|
5726
|
+
'subscriberDiscountPercentage',
|
|
5727
|
+
'subscriberPrice',
|
|
5728
|
+
'stock',
|
|
5729
|
+
'published',
|
|
5730
|
+
'CEST',
|
|
5731
|
+
'EAN',
|
|
5732
|
+
'NCM',
|
|
5733
|
+
'brand',
|
|
5734
|
+
'costPrice',
|
|
5735
|
+
'hasVariants',
|
|
5736
|
+
'isKit',
|
|
5737
|
+
'sku',
|
|
5738
|
+
'rate',
|
|
5739
|
+
'tags',
|
|
5740
|
+
'type',
|
|
5741
|
+
'shoppingCount',
|
|
5742
|
+
'gender',
|
|
5743
|
+
'createdAt',
|
|
5744
|
+
];
|
|
5433
5745
|
const products = [];
|
|
5434
|
-
const
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
'
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
'
|
|
5455
|
-
'costPrice',
|
|
5456
|
-
'hasVariants',
|
|
5457
|
-
'isKit',
|
|
5458
|
-
'sku',
|
|
5459
|
-
'rate',
|
|
5460
|
-
'tags',
|
|
5461
|
-
'type',
|
|
5462
|
-
'shoppingCount',
|
|
5463
|
-
'gender',
|
|
5464
|
-
'createdAt',
|
|
5465
|
-
],
|
|
5466
|
-
options: { enableCount: false },
|
|
5467
|
-
orderBy: {
|
|
5746
|
+
const mostRelevantsIds = category.getMostRelevantByShop(shop);
|
|
5747
|
+
if (mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length) {
|
|
5748
|
+
const { data: mostRelevants } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
|
|
5749
|
+
operator: exports.Where.IN,
|
|
5750
|
+
value: mostRelevantsIds,
|
|
5751
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
|
|
5752
|
+
stock: 'desc',
|
|
5753
|
+
shoppingCount: 'desc',
|
|
5754
|
+
rate: 'desc',
|
|
5755
|
+
name: 'asc',
|
|
5756
|
+
} }), shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5757
|
+
if (mostRelevants.length >= mostRelevantsIds.length)
|
|
5758
|
+
return this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
|
|
5759
|
+
products.push(...mostRelevants);
|
|
5760
|
+
}
|
|
5761
|
+
const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
|
|
5762
|
+
const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
|
|
5763
|
+
operator: exports.Where.IN,
|
|
5764
|
+
value: productIds,
|
|
5765
|
+
}, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
|
|
5766
|
+
stock: 'desc',
|
|
5468
5767
|
shoppingCount: 'desc',
|
|
5469
5768
|
rate: 'desc',
|
|
5470
|
-
stock: 'desc',
|
|
5471
5769
|
name: 'asc',
|
|
5472
|
-
},
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
5477
|
-
.sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
|
|
5478
|
-
const lastProducts = productsData
|
|
5479
|
-
.filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
5480
|
-
.concat(mostRelevantWithouyStock);
|
|
5481
|
-
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
5482
|
-
const resultFinal = categoryMostRelevants.slice(0, options.limit);
|
|
5483
|
-
products.push(...resultFinal);
|
|
5484
|
-
return products;
|
|
5485
|
-
}
|
|
5486
|
-
async getChildren(parentId) {
|
|
5770
|
+
} }), shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
|
|
5771
|
+
return this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
|
|
5772
|
+
}
|
|
5773
|
+
async getChildren(parentId, _optionsCache) {
|
|
5487
5774
|
const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
|
|
5488
5775
|
args: {
|
|
5489
5776
|
type: 'category_tree_args',
|
|
@@ -5621,31 +5908,31 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5621
5908
|
tslib.__decorate([
|
|
5622
5909
|
Log(),
|
|
5623
5910
|
tslib.__metadata("design:type", Function),
|
|
5624
|
-
tslib.__metadata("design:paramtypes", [String, String]),
|
|
5911
|
+
tslib.__metadata("design:paramtypes", [String, String, Object]),
|
|
5625
5912
|
tslib.__metadata("design:returntype", Promise)
|
|
5626
5913
|
], CategoryHasuraGraphQLRepository.prototype, "getCategoryBySlug", null);
|
|
5627
5914
|
tslib.__decorate([
|
|
5628
5915
|
Log(),
|
|
5629
5916
|
tslib.__metadata("design:type", Function),
|
|
5630
|
-
tslib.__metadata("design:paramtypes", [String]),
|
|
5917
|
+
tslib.__metadata("design:paramtypes", [String, Object]),
|
|
5631
5918
|
tslib.__metadata("design:returntype", Promise)
|
|
5632
5919
|
], CategoryHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
|
|
5633
5920
|
tslib.__decorate([
|
|
5634
5921
|
Log(),
|
|
5635
5922
|
tslib.__metadata("design:type", Function),
|
|
5636
|
-
tslib.__metadata("design:paramtypes", [Array, String, Object]),
|
|
5923
|
+
tslib.__metadata("design:paramtypes", [Array, String, Object, Object]),
|
|
5637
5924
|
tslib.__metadata("design:returntype", Promise)
|
|
5638
5925
|
], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
|
|
5639
5926
|
tslib.__decorate([
|
|
5640
5927
|
Log(),
|
|
5641
5928
|
tslib.__metadata("design:type", Function),
|
|
5642
|
-
tslib.__metadata("design:paramtypes", [Category, String, Object]),
|
|
5929
|
+
tslib.__metadata("design:paramtypes", [Category, String, Object, Object]),
|
|
5643
5930
|
tslib.__metadata("design:returntype", Promise)
|
|
5644
5931
|
], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
|
|
5645
5932
|
tslib.__decorate([
|
|
5646
5933
|
Log(),
|
|
5647
5934
|
tslib.__metadata("design:type", Function),
|
|
5648
|
-
tslib.__metadata("design:paramtypes", [Number]),
|
|
5935
|
+
tslib.__metadata("design:paramtypes", [Number, Object]),
|
|
5649
5936
|
tslib.__metadata("design:returntype", Promise)
|
|
5650
5937
|
], CategoryHasuraGraphQLRepository.prototype, "getChildren", null);
|
|
5651
5938
|
tslib.__decorate([
|
|
@@ -5656,7 +5943,7 @@ tslib.__decorate([
|
|
|
5656
5943
|
], CategoryHasuraGraphQLRepository.prototype, "isChild", null);
|
|
5657
5944
|
|
|
5658
5945
|
class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
5659
|
-
constructor({ endpoint, authOptions, interceptors, }) {
|
|
5946
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
5660
5947
|
super({
|
|
5661
5948
|
tableName: 'category_product',
|
|
5662
5949
|
model: CategoryProduct,
|
|
@@ -5664,6 +5951,7 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
|
|
|
5664
5951
|
authOptions,
|
|
5665
5952
|
interceptors,
|
|
5666
5953
|
fields: [{ productId: { columnName: 'product_id' } }, { categoryId: { columnName: 'category_id' } }, 'order'],
|
|
5954
|
+
cache,
|
|
5667
5955
|
});
|
|
5668
5956
|
}
|
|
5669
5957
|
async removeProductFromCategory(categoryId, productId) {
|
|
@@ -5690,7 +5978,7 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
|
|
|
5690
5978
|
}
|
|
5691
5979
|
|
|
5692
5980
|
class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
5693
|
-
constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
|
|
5981
|
+
constructor({ endpoint, authOptions, interceptors, cache, }, filterOptionRepository, categoryFilterRepository) {
|
|
5694
5982
|
super({
|
|
5695
5983
|
tableName: 'filter',
|
|
5696
5984
|
model: Filter,
|
|
@@ -5730,6 +6018,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
|
|
|
5730
6018
|
},
|
|
5731
6019
|
},
|
|
5732
6020
|
],
|
|
6021
|
+
cache,
|
|
5733
6022
|
});
|
|
5734
6023
|
this.filterOptionRepository = filterOptionRepository;
|
|
5735
6024
|
this.categoryFilterRepository = categoryFilterRepository;
|
|
@@ -5816,7 +6105,7 @@ tslib.__decorate([
|
|
|
5816
6105
|
], FilterHasuraGraphQLRepository.prototype, "deleteOptions", null);
|
|
5817
6106
|
|
|
5818
6107
|
class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
5819
|
-
constructor({ endpoint, authOptions, interceptors, }) {
|
|
6108
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
5820
6109
|
super({
|
|
5821
6110
|
tableName: 'filter_option',
|
|
5822
6111
|
model: FilterOption,
|
|
@@ -5830,18 +6119,20 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
|
|
|
5830
6119
|
{ createdAt: { columnName: 'created_at' } },
|
|
5831
6120
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
5832
6121
|
],
|
|
6122
|
+
cache,
|
|
5833
6123
|
});
|
|
5834
6124
|
}
|
|
5835
6125
|
}
|
|
5836
6126
|
|
|
5837
6127
|
class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
5838
|
-
constructor({ endpoint, authOptions, interceptors, }, productRepository) {
|
|
6128
|
+
constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
|
|
5839
6129
|
super({
|
|
5840
6130
|
tableName: 'product_errors',
|
|
5841
6131
|
model: ProductErrorsHasuraGraphQL,
|
|
5842
6132
|
endpoint,
|
|
5843
6133
|
authOptions,
|
|
5844
6134
|
interceptors,
|
|
6135
|
+
cache,
|
|
5845
6136
|
fields: [
|
|
5846
6137
|
{
|
|
5847
6138
|
productId: {
|
|
@@ -5928,7 +6219,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
5928
6219
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
5929
6220
|
];
|
|
5930
6221
|
}
|
|
5931
|
-
constructor({ endpoint, authOptions, interceptors, }) {
|
|
6222
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
5932
6223
|
super({
|
|
5933
6224
|
tableName: 'product',
|
|
5934
6225
|
model: ProductHasuraGraphQL,
|
|
@@ -5936,6 +6227,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
5936
6227
|
authOptions,
|
|
5937
6228
|
interceptors,
|
|
5938
6229
|
fields: [],
|
|
6230
|
+
cache,
|
|
5939
6231
|
});
|
|
5940
6232
|
this.bindReviewToModel = (plain) => ProductReview.toInstance(Object.assign(Object.assign({}, is(lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id']))), { createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at, updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at, personId: plain.person_id, orderId: plain.order_id }));
|
|
5941
6233
|
this.bindReviewToHasura = (review) => (Object.assign(Object.assign({}, is(lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId']))), { person_id: review.personId, order_id: review.orderId }));
|
|
@@ -6120,17 +6412,18 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6120
6412
|
}
|
|
6121
6413
|
return product;
|
|
6122
6414
|
}
|
|
6123
|
-
async get(identifiers) {
|
|
6415
|
+
async get(identifiers, options) {
|
|
6124
6416
|
var _a;
|
|
6125
6417
|
const product = Number.isNaN(+identifiers.id)
|
|
6126
|
-
? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }))
|
|
6127
|
-
|
|
6418
|
+
? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, options))
|
|
6419
|
+
.data) === null || _a === void 0 ? void 0 : _a[0]
|
|
6420
|
+
: await super.get(identifiers, options);
|
|
6128
6421
|
if (product.productId)
|
|
6129
6422
|
throw new NotFoundError('Product not found, it is a variant');
|
|
6130
|
-
product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id));
|
|
6423
|
+
product.reviews = product.reviews || (await this.findReviewsByProduct(+product.id, options));
|
|
6131
6424
|
return product;
|
|
6132
6425
|
}
|
|
6133
|
-
async find(params) {
|
|
6426
|
+
async find(params, optionsParams) {
|
|
6134
6427
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
6135
6428
|
const _o = params || {}, { filters, fields } = _o, options = tslib.__rest(_o, ["filters", "fields"]);
|
|
6136
6429
|
const bindFields = fields ||
|
|
@@ -6152,10 +6445,18 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6152
6445
|
'fullPrice',
|
|
6153
6446
|
]
|
|
6154
6447
|
: []),
|
|
6155
|
-
] }));
|
|
6448
|
+
] }), optionsParams);
|
|
6156
6449
|
}
|
|
6157
|
-
async getBySlug(slug) {
|
|
6158
|
-
var _a;
|
|
6450
|
+
async getBySlug(slug, options) {
|
|
6451
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6452
|
+
if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
|
|
6453
|
+
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
6454
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
6455
|
+
if (cachedData) {
|
|
6456
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
6457
|
+
return this.model.toInstance(JSON.parse(cachedData));
|
|
6458
|
+
}
|
|
6459
|
+
}
|
|
6159
6460
|
const result = await this.find({
|
|
6160
6461
|
filters: {
|
|
6161
6462
|
slug,
|
|
@@ -6167,8 +6468,17 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6167
6468
|
});
|
|
6168
6469
|
if (!result.data.length)
|
|
6169
6470
|
return null;
|
|
6170
|
-
const product = (
|
|
6471
|
+
const product = (_c = result === null || result === void 0 ? void 0 : result.data) === null || _c === void 0 ? void 0 : _c.shift();
|
|
6171
6472
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
6473
|
+
if (((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter) && ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.enabled) && product) {
|
|
6474
|
+
const cacheKey = `${this.model.name.toLowerCase()}:slug:${slug}`;
|
|
6475
|
+
await this.cache.cacheAdapter.set({
|
|
6476
|
+
key: cacheKey,
|
|
6477
|
+
data: JSON.stringify(product.toPlain()),
|
|
6478
|
+
expirationInSeconds: ((_f = options === null || options === void 0 ? void 0 : options.cache) === null || _f === void 0 ? void 0 : _f.ttl) || this.cache.ttlDefault,
|
|
6479
|
+
});
|
|
6480
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
6481
|
+
}
|
|
6172
6482
|
return product;
|
|
6173
6483
|
}
|
|
6174
6484
|
async update(params) {
|
|
@@ -6181,13 +6491,22 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6181
6491
|
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
6182
6492
|
return product;
|
|
6183
6493
|
}
|
|
6184
|
-
async fetchProductReviews() {
|
|
6494
|
+
async fetchProductReviews(filters, options) {
|
|
6495
|
+
var _a, _b, _c, _d, _e;
|
|
6496
|
+
if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
|
|
6497
|
+
const cacheKey = `${this.model.name.toLowerCase()}:all-reviews:${MD5GeneratorHelper.generateMD5(filters)}`;
|
|
6498
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
6499
|
+
if (cachedData) {
|
|
6500
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
6501
|
+
return JSON.parse(cachedData);
|
|
6502
|
+
}
|
|
6503
|
+
}
|
|
6185
6504
|
let data = [];
|
|
6186
6505
|
let count = 0;
|
|
6187
6506
|
let offset = 0;
|
|
6188
|
-
const limit = 500;
|
|
6507
|
+
const limit = (filters === null || filters === void 0 ? void 0 : filters.limit) || 500;
|
|
6189
6508
|
do {
|
|
6190
|
-
const result = await super.find(Object.assign({ fields: ['id', 'name', 'sku', 'reviews'] }, ({
|
|
6509
|
+
const result = await super.find(Object.assign({ fields: ['id', 'name', 'sku', 'reviews'] }, (limit && {
|
|
6191
6510
|
limits: {
|
|
6192
6511
|
offset,
|
|
6193
6512
|
limit,
|
|
@@ -6197,12 +6516,50 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6197
6516
|
count = result.data.length;
|
|
6198
6517
|
offset += limit;
|
|
6199
6518
|
} while (count === limit);
|
|
6200
|
-
|
|
6519
|
+
const reviews = data.reduce((reviews, product) => [
|
|
6201
6520
|
...reviews,
|
|
6202
6521
|
...product.reviews.map((review) => (Object.assign(Object.assign({}, review), { reviewStatus: this.getReviewStatus(review), productId: product.id, productName: product.name, productSku: product.sku }))),
|
|
6203
6522
|
], []);
|
|
6204
|
-
|
|
6205
|
-
|
|
6523
|
+
let filteredReviews = reviews;
|
|
6524
|
+
if (filters.sku) {
|
|
6525
|
+
filteredReviews = filteredReviews.filter((review) => review.productSku === filters.sku);
|
|
6526
|
+
}
|
|
6527
|
+
if (filters.status) {
|
|
6528
|
+
filteredReviews = filteredReviews.filter((review) => review.reviewStatus === filters.status);
|
|
6529
|
+
}
|
|
6530
|
+
if (filters.email) {
|
|
6531
|
+
filteredReviews = filteredReviews.filter((review) => review.email === filters.email);
|
|
6532
|
+
}
|
|
6533
|
+
if (filters.rate) {
|
|
6534
|
+
filteredReviews = filteredReviews.filter((review) => review.rate === filters.rate);
|
|
6535
|
+
}
|
|
6536
|
+
if (filters.period) {
|
|
6537
|
+
filteredReviews = filteredReviews.filter((review) => {
|
|
6538
|
+
const reviewDate = new Date(review.createdAt);
|
|
6539
|
+
return reviewDate >= filters.period.start && reviewDate <= filters.period.end;
|
|
6540
|
+
});
|
|
6541
|
+
}
|
|
6542
|
+
if (((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter) && ((_d = options === null || options === void 0 ? void 0 : options.cache) === null || _d === void 0 ? void 0 : _d.enabled)) {
|
|
6543
|
+
const cacheKey = `${this.model.name.toLowerCase()}:all-reviews:${MD5GeneratorHelper.generateMD5(filters)}`;
|
|
6544
|
+
await this.cache.cacheAdapter.set({
|
|
6545
|
+
key: cacheKey,
|
|
6546
|
+
data: JSON.stringify(filteredReviews),
|
|
6547
|
+
expirationInSeconds: ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl) || this.cache.ttlDefault,
|
|
6548
|
+
});
|
|
6549
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
6550
|
+
}
|
|
6551
|
+
return filteredReviews;
|
|
6552
|
+
}
|
|
6553
|
+
async fetchReviews(status, options) {
|
|
6554
|
+
var _a, _b, _c, _d, _e;
|
|
6555
|
+
if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
|
|
6556
|
+
const cacheKey = `${this.model.name.toLowerCase()}:reviews:${status}`;
|
|
6557
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
6558
|
+
if (cachedData) {
|
|
6559
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
6560
|
+
return JSON.parse(cachedData);
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6206
6563
|
const reviewsExpression = {
|
|
6207
6564
|
status: status === 'pending'
|
|
6208
6565
|
? { [HasuraGraphQLWhere.ISNULL]: true }
|
|
@@ -6211,7 +6568,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6211
6568
|
const { product: data } = await this.query('product', ['id', 'name', 'sku', { reviews: { columnName: 'reviews', fields: this.reviewsFields } }], {
|
|
6212
6569
|
where: { value: { reviews: reviewsExpression }, type: 'product_bool_exp', required: true },
|
|
6213
6570
|
});
|
|
6214
|
-
|
|
6571
|
+
const reviews = data.reduce((reviews, product) => [
|
|
6215
6572
|
...reviews,
|
|
6216
6573
|
...product.reviews
|
|
6217
6574
|
.filter((review) => (status === 'pending' && [undefined, null].includes(review.status)) ||
|
|
@@ -6219,9 +6576,20 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6219
6576
|
(status === 'rejected' && review.status === false))
|
|
6220
6577
|
.map((review) => (Object.assign(Object.assign({}, this.bindReviewToModel(review)), { productId: product.id, productName: product.name, productSku: product.sku }))),
|
|
6221
6578
|
], []);
|
|
6579
|
+
if (((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter) && ((_d = options === null || options === void 0 ? void 0 : options.cache) === null || _d === void 0 ? void 0 : _d.enabled)) {
|
|
6580
|
+
const cacheKey = `${this.model.name.toLowerCase()}:reviews:${status}`;
|
|
6581
|
+
await this.cache.cacheAdapter.set({
|
|
6582
|
+
key: cacheKey,
|
|
6583
|
+
data: JSON.stringify(reviews),
|
|
6584
|
+
expirationInSeconds: ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl) || this.cache.ttlDefault,
|
|
6585
|
+
});
|
|
6586
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
6587
|
+
}
|
|
6588
|
+
return reviews;
|
|
6222
6589
|
}
|
|
6223
|
-
async findCatalog(params, mainGender) {
|
|
6224
|
-
|
|
6590
|
+
async findCatalog(params, mainGender, options) {
|
|
6591
|
+
const result = await this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true }), orderBy: Object.assign(Object.assign({ hasStock: 'desc' }, (!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' })), lodash.omit(params.orderBy, ['hasStock', 'intGender'])) }), options);
|
|
6592
|
+
return result;
|
|
6225
6593
|
}
|
|
6226
6594
|
async cleanShoppingCountFromIds(ids) {
|
|
6227
6595
|
return await this.mutation('update_product', ['affected_rows'], {
|
|
@@ -6328,7 +6696,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6328
6696
|
return (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id;
|
|
6329
6697
|
throw new NotFoundError(`Product with id ${id} not found`);
|
|
6330
6698
|
}
|
|
6331
|
-
async findReviewsByProduct(productId) {
|
|
6699
|
+
async findReviewsByProduct(productId, options) {
|
|
6700
|
+
var _a, _b, _c, _d, _e;
|
|
6701
|
+
if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
|
|
6702
|
+
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
6703
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
6704
|
+
if (cachedData) {
|
|
6705
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
6706
|
+
return JSON.parse(cachedData);
|
|
6707
|
+
}
|
|
6708
|
+
}
|
|
6332
6709
|
const { product_review: data } = await this.query('product_review', this.reviewsFields, {
|
|
6333
6710
|
where: {
|
|
6334
6711
|
value: {
|
|
@@ -6338,7 +6715,17 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6338
6715
|
required: true,
|
|
6339
6716
|
},
|
|
6340
6717
|
});
|
|
6341
|
-
|
|
6718
|
+
const reviews = data && data.map((review) => this.bindReviewToModel(review));
|
|
6719
|
+
if (((_c = this.cache) === null || _c === void 0 ? void 0 : _c.cacheAdapter) && ((_d = options === null || options === void 0 ? void 0 : options.cache) === null || _d === void 0 ? void 0 : _d.enabled) && reviews) {
|
|
6720
|
+
const cacheKey = `${this.model.name.toLowerCase()}:reviews:product:${productId}`;
|
|
6721
|
+
await this.cache.cacheAdapter.set({
|
|
6722
|
+
key: cacheKey,
|
|
6723
|
+
data: JSON.stringify(reviews),
|
|
6724
|
+
expirationInSeconds: ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl) || this.cache.ttlDefault,
|
|
6725
|
+
});
|
|
6726
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
6727
|
+
}
|
|
6728
|
+
return reviews;
|
|
6342
6729
|
}
|
|
6343
6730
|
async findReview(review, productId) {
|
|
6344
6731
|
if (review.id)
|
|
@@ -6424,25 +6811,25 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
6424
6811
|
tslib.__decorate([
|
|
6425
6812
|
Log(),
|
|
6426
6813
|
tslib.__metadata("design:type", Function),
|
|
6427
|
-
tslib.__metadata("design:paramtypes", [String]),
|
|
6814
|
+
tslib.__metadata("design:paramtypes", [String, Object]),
|
|
6428
6815
|
tslib.__metadata("design:returntype", Promise)
|
|
6429
6816
|
], ProductHasuraGraphQLRepository.prototype, "getBySlug", null);
|
|
6430
6817
|
tslib.__decorate([
|
|
6431
6818
|
Log(),
|
|
6432
6819
|
tslib.__metadata("design:type", Function),
|
|
6433
|
-
tslib.__metadata("design:paramtypes", []),
|
|
6820
|
+
tslib.__metadata("design:paramtypes", [Object, Object]),
|
|
6434
6821
|
tslib.__metadata("design:returntype", Promise)
|
|
6435
6822
|
], ProductHasuraGraphQLRepository.prototype, "fetchProductReviews", null);
|
|
6436
6823
|
tslib.__decorate([
|
|
6437
6824
|
Log(),
|
|
6438
6825
|
tslib.__metadata("design:type", Function),
|
|
6439
|
-
tslib.__metadata("design:paramtypes", [String]),
|
|
6826
|
+
tslib.__metadata("design:paramtypes", [String, Object]),
|
|
6440
6827
|
tslib.__metadata("design:returntype", Promise)
|
|
6441
6828
|
], ProductHasuraGraphQLRepository.prototype, "fetchReviews", null);
|
|
6442
6829
|
tslib.__decorate([
|
|
6443
6830
|
Log(),
|
|
6444
6831
|
tslib.__metadata("design:type", Function),
|
|
6445
|
-
tslib.__metadata("design:paramtypes", [Object, Object]),
|
|
6832
|
+
tslib.__metadata("design:paramtypes", [Object, Object, Object]),
|
|
6446
6833
|
tslib.__metadata("design:returntype", Promise)
|
|
6447
6834
|
], ProductHasuraGraphQLRepository.prototype, "findCatalog", null);
|
|
6448
6835
|
tslib.__decorate([
|
|
@@ -6450,10 +6837,16 @@ tslib.__decorate([
|
|
|
6450
6837
|
tslib.__metadata("design:type", Function),
|
|
6451
6838
|
tslib.__metadata("design:paramtypes", [Array]),
|
|
6452
6839
|
tslib.__metadata("design:returntype", Promise)
|
|
6453
|
-
], ProductHasuraGraphQLRepository.prototype, "cleanShoppingCountFromIds", null);
|
|
6840
|
+
], ProductHasuraGraphQLRepository.prototype, "cleanShoppingCountFromIds", null);
|
|
6841
|
+
tslib.__decorate([
|
|
6842
|
+
Log(),
|
|
6843
|
+
tslib.__metadata("design:type", Function),
|
|
6844
|
+
tslib.__metadata("design:paramtypes", [Number, Object]),
|
|
6845
|
+
tslib.__metadata("design:returntype", Promise)
|
|
6846
|
+
], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
|
|
6454
6847
|
|
|
6455
6848
|
class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
6456
|
-
constructor({ endpoint, authOptions, interceptors, }) {
|
|
6849
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
6457
6850
|
super({
|
|
6458
6851
|
tableName: 'product_review',
|
|
6459
6852
|
model: ProductReview,
|
|
@@ -6477,6 +6870,7 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
|
|
|
6477
6870
|
{ createdAt: { columnName: 'created_at' } },
|
|
6478
6871
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
6479
6872
|
],
|
|
6873
|
+
cache,
|
|
6480
6874
|
});
|
|
6481
6875
|
}
|
|
6482
6876
|
async updateManyStatus(reviews) {
|
|
@@ -6518,13 +6912,14 @@ tslib.__decorate([
|
|
|
6518
6912
|
], ProductReviewHasuraGraphQLRepository.prototype, "disaproveReview", null);
|
|
6519
6913
|
|
|
6520
6914
|
class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
6521
|
-
constructor({ endpoint, authOptions, interceptors, }) {
|
|
6915
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
6522
6916
|
super({
|
|
6523
6917
|
tableName: 'product_stock_notification',
|
|
6524
6918
|
model: ProductStockNotification,
|
|
6525
6919
|
endpoint,
|
|
6526
6920
|
authOptions,
|
|
6527
6921
|
interceptors,
|
|
6922
|
+
cache,
|
|
6528
6923
|
fields: [
|
|
6529
6924
|
'id',
|
|
6530
6925
|
{ productId: { columnName: 'product_id' } },
|
|
@@ -6579,13 +6974,14 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
|
|
|
6579
6974
|
}
|
|
6580
6975
|
|
|
6581
6976
|
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
6582
|
-
constructor({ endpoint, authOptions, interceptors, }) {
|
|
6977
|
+
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
6583
6978
|
super({
|
|
6584
6979
|
tableName: 'product',
|
|
6585
6980
|
model: VariantHasuraGraphQL,
|
|
6586
6981
|
endpoint,
|
|
6587
6982
|
authOptions,
|
|
6588
6983
|
interceptors,
|
|
6984
|
+
cache,
|
|
6589
6985
|
fields: [
|
|
6590
6986
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
6591
6987
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -6692,13 +7088,14 @@ class WishlistHasuraGraphQL extends Wishlist {
|
|
|
6692
7088
|
}
|
|
6693
7089
|
|
|
6694
7090
|
class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
6695
|
-
constructor({ endpoint, authOptions, interceptors, }, categoryProductRepository) {
|
|
7091
|
+
constructor({ endpoint, authOptions, interceptors, cache, }, categoryProductRepository) {
|
|
6696
7092
|
super({
|
|
6697
7093
|
tableName: 'category',
|
|
6698
7094
|
model: WishlistHasuraGraphQL,
|
|
6699
7095
|
endpoint,
|
|
6700
7096
|
authOptions,
|
|
6701
7097
|
interceptors,
|
|
7098
|
+
cache,
|
|
6702
7099
|
fields: [
|
|
6703
7100
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
6704
7101
|
{ firestoreId: { columnName: 'firestore_id' } },
|
|
@@ -7651,8 +8048,6 @@ exports.ProductErrorsHasuraGraphQLRepository = ProductErrorsHasuraGraphQLReposit
|
|
|
7651
8048
|
exports.ProductFirestoreRepository = ProductFirestoreRepository;
|
|
7652
8049
|
exports.ProductHasuraGraphQL = ProductHasuraGraphQL;
|
|
7653
8050
|
exports.ProductHasuraGraphQLRepository = ProductHasuraGraphQLRepository;
|
|
7654
|
-
exports.ProductQueue = ProductQueue;
|
|
7655
|
-
exports.ProductQueueFirestoreRepository = ProductQueueFirestoreRepository;
|
|
7656
8051
|
exports.ProductReview = ProductReview;
|
|
7657
8052
|
exports.ProductReviewHasuraGraphQLRepository = ProductReviewHasuraGraphQLRepository;
|
|
7658
8053
|
exports.ProductStockNotification = ProductStockNotification;
|
|
@@ -7665,6 +8060,7 @@ exports.ReflectHelper = ReflectHelper;
|
|
|
7665
8060
|
exports.Register = Register;
|
|
7666
8061
|
exports.RegisterFirebaseAuthService = RegisterFirebaseAuthService;
|
|
7667
8062
|
exports.RequiredArgumentError = RequiredArgumentError;
|
|
8063
|
+
exports.RestCacheAdapter = RestCacheAdapter;
|
|
7668
8064
|
exports.RoundProductPricesHelper = RoundProductPricesHelper;
|
|
7669
8065
|
exports.Sequence = Sequence;
|
|
7670
8066
|
exports.SequenceFirestoreRepository = SequenceFirestoreRepository;
|