@infrab4a/connect 4.3.10-beta.0 → 4.3.10-beta.2
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 +41 -8
- package/index.esm.js +41 -8
- package/package.json +1 -1
- package/src/domain/catalog/repositories/product.repository.d.ts +13 -0
- package/src/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +3 -1
- package/src/infra/hasura-graphql/mixins/helpers/filter-option.helper.d.ts +1 -1
- package/src/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +2 -0
package/index.cjs.js
CHANGED
|
@@ -3169,6 +3169,9 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
3169
3169
|
});
|
|
3170
3170
|
this.reviews = {};
|
|
3171
3171
|
}
|
|
3172
|
+
fetchProductReviews(filters) {
|
|
3173
|
+
throw new Error('Method not implemented.');
|
|
3174
|
+
}
|
|
3172
3175
|
async getBySlug(slug) {
|
|
3173
3176
|
var _a;
|
|
3174
3177
|
const result = await this.find({
|
|
@@ -3210,6 +3213,9 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
3210
3213
|
findCatalog(params) {
|
|
3211
3214
|
return this.find(params);
|
|
3212
3215
|
}
|
|
3216
|
+
async fetchPaginatedReviews() {
|
|
3217
|
+
return Promise.resolve([]);
|
|
3218
|
+
}
|
|
3213
3219
|
}
|
|
3214
3220
|
|
|
3215
3221
|
class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
|
|
@@ -3559,17 +3565,20 @@ FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
|
|
|
3559
3565
|
return false;
|
|
3560
3566
|
const converter = fieldOption.to
|
|
3561
3567
|
? fieldOption.to
|
|
3562
|
-
: (value) =>
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
: newValue;
|
|
3567
|
-
};
|
|
3568
|
-
return Array.isArray(filter.value) && !fieldOption.fields && [exports.Where.IN, exports.Where.NOTIN].includes(filter.operator)
|
|
3568
|
+
: (value) => filter.operator === exports.Where.LIKE && !Array.isArray(filter.value) && value.indexOf('%') < 0
|
|
3569
|
+
? `%${value}%`
|
|
3570
|
+
: value;
|
|
3571
|
+
const converterResult = Array.isArray(filter.value) && !fieldOption.fields && [exports.Where.IN, exports.Where.NOTIN].includes(filter.operator)
|
|
3569
3572
|
? filter.value.map((fieldValue) => converter(fieldValue))
|
|
3570
3573
|
: converter(filter.value);
|
|
3574
|
+
const newValue = filter.ignoreCase && !filter.ignoreAccent && !Array.isArray(filter.value) && converterResult.indexOf('%') < 0
|
|
3575
|
+
? `%${converterResult}%`
|
|
3576
|
+
: converterResult;
|
|
3577
|
+
return filter.ignoreAccent && !Array.isArray(filter.value)
|
|
3578
|
+
? FilterOptionHelper.buildInsensitiveSentence(newValue)
|
|
3579
|
+
: newValue;
|
|
3571
3580
|
};
|
|
3572
|
-
FilterOptionHelper.
|
|
3581
|
+
FilterOptionHelper.buildInsensitiveSentence = (value) => {
|
|
3573
3582
|
const valueWithoutAccents = FilterOptionHelper.removeAccents(value);
|
|
3574
3583
|
let result = '';
|
|
3575
3584
|
for (const char of valueWithoutAccents) {
|
|
@@ -5063,6 +5072,30 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
5063
5072
|
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
5064
5073
|
return product;
|
|
5065
5074
|
}
|
|
5075
|
+
async fetchProductReviews() {
|
|
5076
|
+
let data = [];
|
|
5077
|
+
let count = 0;
|
|
5078
|
+
let offset = 0;
|
|
5079
|
+
const limit = 500;
|
|
5080
|
+
do {
|
|
5081
|
+
const result = await super.find(Object.assign({ fields: ['id', 'name', 'sku', 'reviews'] }, ({
|
|
5082
|
+
limits: {
|
|
5083
|
+
offset,
|
|
5084
|
+
limit,
|
|
5085
|
+
},
|
|
5086
|
+
})));
|
|
5087
|
+
data = data.concat(result.data);
|
|
5088
|
+
count = result.data.length;
|
|
5089
|
+
offset += limit;
|
|
5090
|
+
} while (count === limit);
|
|
5091
|
+
return data.reduce((reviews, product) => [
|
|
5092
|
+
...reviews,
|
|
5093
|
+
...product.reviews.map((review) => (Object.assign(Object.assign({}, review), { reviewStatus: this.getReviewStatus(review), productId: product.id, productName: product.name, productSku: product.sku }))),
|
|
5094
|
+
], []);
|
|
5095
|
+
}
|
|
5096
|
+
getReviewStatus(review) {
|
|
5097
|
+
return review.status === true ? 'approved' : review.status === false ? 'rejected' : 'pending';
|
|
5098
|
+
}
|
|
5066
5099
|
async fetchReviews(status) {
|
|
5067
5100
|
const reviewsExpression = {
|
|
5068
5101
|
status: status === 'pending'
|
package/index.esm.js
CHANGED
|
@@ -3163,6 +3163,9 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
3163
3163
|
});
|
|
3164
3164
|
this.reviews = {};
|
|
3165
3165
|
}
|
|
3166
|
+
fetchProductReviews(filters) {
|
|
3167
|
+
throw new Error('Method not implemented.');
|
|
3168
|
+
}
|
|
3166
3169
|
async getBySlug(slug) {
|
|
3167
3170
|
var _a;
|
|
3168
3171
|
const result = await this.find({
|
|
@@ -3204,6 +3207,9 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
3204
3207
|
findCatalog(params) {
|
|
3205
3208
|
return this.find(params);
|
|
3206
3209
|
}
|
|
3210
|
+
async fetchPaginatedReviews() {
|
|
3211
|
+
return Promise.resolve([]);
|
|
3212
|
+
}
|
|
3207
3213
|
}
|
|
3208
3214
|
|
|
3209
3215
|
class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
|
|
@@ -3553,17 +3559,20 @@ FilterOptionHelper.GetValueFromFilter = (filter, fieldOption) => {
|
|
|
3553
3559
|
return false;
|
|
3554
3560
|
const converter = fieldOption.to
|
|
3555
3561
|
? fieldOption.to
|
|
3556
|
-
: (value) =>
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
: newValue;
|
|
3561
|
-
};
|
|
3562
|
-
return Array.isArray(filter.value) && !fieldOption.fields && [Where.IN, Where.NOTIN].includes(filter.operator)
|
|
3562
|
+
: (value) => filter.operator === Where.LIKE && !Array.isArray(filter.value) && value.indexOf('%') < 0
|
|
3563
|
+
? `%${value}%`
|
|
3564
|
+
: value;
|
|
3565
|
+
const converterResult = Array.isArray(filter.value) && !fieldOption.fields && [Where.IN, Where.NOTIN].includes(filter.operator)
|
|
3563
3566
|
? filter.value.map((fieldValue) => converter(fieldValue))
|
|
3564
3567
|
: converter(filter.value);
|
|
3568
|
+
const newValue = filter.ignoreCase && !filter.ignoreAccent && !Array.isArray(filter.value) && converterResult.indexOf('%') < 0
|
|
3569
|
+
? `%${converterResult}%`
|
|
3570
|
+
: converterResult;
|
|
3571
|
+
return filter.ignoreAccent && !Array.isArray(filter.value)
|
|
3572
|
+
? FilterOptionHelper.buildInsensitiveSentence(newValue)
|
|
3573
|
+
: newValue;
|
|
3565
3574
|
};
|
|
3566
|
-
FilterOptionHelper.
|
|
3575
|
+
FilterOptionHelper.buildInsensitiveSentence = (value) => {
|
|
3567
3576
|
const valueWithoutAccents = FilterOptionHelper.removeAccents(value);
|
|
3568
3577
|
let result = '';
|
|
3569
3578
|
for (const char of valueWithoutAccents) {
|
|
@@ -5057,6 +5066,30 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
5057
5066
|
product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
|
|
5058
5067
|
return product;
|
|
5059
5068
|
}
|
|
5069
|
+
async fetchProductReviews() {
|
|
5070
|
+
let data = [];
|
|
5071
|
+
let count = 0;
|
|
5072
|
+
let offset = 0;
|
|
5073
|
+
const limit = 500;
|
|
5074
|
+
do {
|
|
5075
|
+
const result = await super.find(Object.assign({ fields: ['id', 'name', 'sku', 'reviews'] }, ({
|
|
5076
|
+
limits: {
|
|
5077
|
+
offset,
|
|
5078
|
+
limit,
|
|
5079
|
+
},
|
|
5080
|
+
})));
|
|
5081
|
+
data = data.concat(result.data);
|
|
5082
|
+
count = result.data.length;
|
|
5083
|
+
offset += limit;
|
|
5084
|
+
} while (count === limit);
|
|
5085
|
+
return data.reduce((reviews, product) => [
|
|
5086
|
+
...reviews,
|
|
5087
|
+
...product.reviews.map((review) => (Object.assign(Object.assign({}, review), { reviewStatus: this.getReviewStatus(review), productId: product.id, productName: product.name, productSku: product.sku }))),
|
|
5088
|
+
], []);
|
|
5089
|
+
}
|
|
5090
|
+
getReviewStatus(review) {
|
|
5091
|
+
return review.status === true ? 'approved' : review.status === false ? 'rejected' : 'pending';
|
|
5092
|
+
}
|
|
5060
5093
|
async fetchReviews(status) {
|
|
5061
5094
|
const reviewsExpression = {
|
|
5062
5095
|
status: status === 'pending'
|
package/package.json
CHANGED
|
@@ -6,10 +6,23 @@ export type ReviewWithProductData = ProductReview & {
|
|
|
6
6
|
productId: string;
|
|
7
7
|
productName: string;
|
|
8
8
|
productSku: string;
|
|
9
|
+
reviewStatus?: 'pending' | 'approved' | 'rejected';
|
|
10
|
+
};
|
|
11
|
+
export type PaginatedReviewFilters = {
|
|
12
|
+
sku?: string;
|
|
13
|
+
status: ReviewStatusParams;
|
|
14
|
+
email?: string;
|
|
15
|
+
rate?: number;
|
|
16
|
+
period?: {
|
|
17
|
+
start: Date;
|
|
18
|
+
end: Date;
|
|
19
|
+
};
|
|
20
|
+
limit?: number;
|
|
9
21
|
};
|
|
10
22
|
export interface ProductRepository extends CrudRepository<Product> {
|
|
11
23
|
getBySlug(slug: string): Promise<Product>;
|
|
12
24
|
fetchReviews(status: ReviewStatusParams): Promise<ReviewWithProductData[]>;
|
|
25
|
+
fetchProductReviews(filters: PaginatedReviewFilters): Promise<ReviewWithProductData[]>;
|
|
13
26
|
cleanShoppingCountFromIds(ids: string[]): Promise<any>;
|
|
14
27
|
findCatalog(params: FindRepositoryParams<Product>, mainGender?: Extract<ProductGender, 'female' | 'male' | 'unisex'>): Promise<RepositoryFindResult<Product>>;
|
|
15
28
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { FindRepositoryParams, Product, ProductRepository, RepositoryFindResult, ReviewStatusParams, ReviewWithProductData } from '../../../../../domain';
|
|
1
|
+
import { FindRepositoryParams, PaginatedReviewFilters, Product, ProductRepository, RepositoryFindResult, ReviewStatusParams, ReviewWithProductData } from '../../../../../domain';
|
|
2
2
|
import { FirestoreConstructorParams } from '../../mixins';
|
|
3
3
|
declare const ProductFirestoreRepository_base: import("../../../../../utils").MixinCtor<import("../..").FirestoreRepository<Product> & import("../../../../../domain").CrudRepository<Product, import("../../../../../domain").CrudParams<Product>> & import("../..").FirestoreHelpers, [FirestoreConstructorParams<Product>, ...any[]]>;
|
|
4
4
|
export declare class ProductFirestoreRepository extends ProductFirestoreRepository_base implements ProductRepository {
|
|
5
5
|
private reviews;
|
|
6
6
|
constructor({ firestore, interceptors }: Pick<FirestoreConstructorParams<Product>, 'firestore' | 'interceptors'>);
|
|
7
|
+
fetchProductReviews(filters: PaginatedReviewFilters): Promise<ReviewWithProductData[]>;
|
|
7
8
|
getBySlug(slug: string): Promise<Product>;
|
|
8
9
|
fetchReviews(status: ReviewStatusParams): Promise<ReviewWithProductData[]>;
|
|
9
10
|
cleanShoppingCountFromIds(): Promise<void>;
|
|
10
11
|
findCatalog(params: FindRepositoryParams<Product>): Promise<RepositoryFindResult<Product>>;
|
|
12
|
+
fetchPaginatedReviews(): Promise<ReviewWithProductData[]>;
|
|
11
13
|
}
|
|
12
14
|
export {};
|
|
@@ -3,6 +3,6 @@ import { ColumnOptions } from '../../types';
|
|
|
3
3
|
export declare class FilterOptionHelper {
|
|
4
4
|
static CheckIfIsFilterOption: <Model extends ModelBaseStructure>(filter: any) => filter is RepositoryFindFieltersOptions<Model, any>;
|
|
5
5
|
static GetValueFromFilter: <Model extends ModelBaseStructure<Model>>(filter: RepositoryFindFieltersOptions<Model, any>, fieldOption: ColumnOptions<any, any>) => any;
|
|
6
|
-
private static
|
|
6
|
+
private static buildInsensitiveSentence;
|
|
7
7
|
private static removeAccents;
|
|
8
8
|
}
|
package/src/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare class ProductHasuraGraphQLRepository extends ProductHasuraGraphQL
|
|
|
12
12
|
find(params?: FindRepositoryParams<ProductHasuraGraphQL>): Promise<RepositoryFindResult<ProductHasuraGraphQL>>;
|
|
13
13
|
getBySlug(slug: string): Promise<ProductHasuraGraphQL>;
|
|
14
14
|
update(params: UpdateRepositoryParams<ProductHasuraGraphQL>): Promise<ProductHasuraGraphQL>;
|
|
15
|
+
fetchProductReviews(): Promise<ReviewWithProductData[]>;
|
|
16
|
+
private getReviewStatus;
|
|
15
17
|
fetchReviews(status: ReviewStatusParams): Promise<ReviewWithProductData[]>;
|
|
16
18
|
findCatalog(params: FindRepositoryParams<ProductHasuraGraphQL>, mainGender?: Extract<ProductGender, 'female' | 'male'>): Promise<RepositoryFindResult<ProductHasuraGraphQL>>;
|
|
17
19
|
private updateCategories;
|