@infrab4a/connect 1.0.0-beta.20 → 1.0.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/infrab4a-connect.umd.js +68 -6
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/domain/catalog/repositories/product.repository.d.ts +8 -1
- package/domain/generic/repository/types/repository-find-filters.type.d.ts +1 -1
- package/esm2015/domain/catalog/repositories/product.repository.js +1 -1
- package/esm2015/domain/generic/repository/types/repository-find-filters.type.js +1 -1
- package/esm2015/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +4 -4
- package/esm2015/infra/firebase/firestore/mixins/with-firestore.mixin.js +2 -2
- package/esm2015/infra/firebase/firestore/repositories/catalog/product-firestore.repository.js +30 -2
- package/esm2015/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.js +2 -2
- package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +23 -3
- package/esm2015/infra/hasura-graphql/types/hasura-graphql-fields.type.js +1 -1
- package/fesm2015/infrab4a-connect.js +54 -6
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +3 -1
- package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +2 -1
- package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1114,7 +1114,7 @@ const withFirestore = (MixinBase) => {
|
|
|
1114
1114
|
fromFirestore: (snap) => {
|
|
1115
1115
|
const data = snap.data();
|
|
1116
1116
|
Object.keys(data).forEach((key) => {
|
|
1117
|
-
if (typeof data[key] === 'object' && '_seconds' in data[key]) {
|
|
1117
|
+
if (data[key] && typeof data[key] === 'object' && '_seconds' in data[key]) {
|
|
1118
1118
|
data[key] = data[key].toDate();
|
|
1119
1119
|
}
|
|
1120
1120
|
});
|
|
@@ -1199,10 +1199,10 @@ const withFindFirestore = (MixinBase) => {
|
|
|
1199
1199
|
return queryReference.where(firestoreFieldName, (options === null || options === void 0 ? void 0 : options.operator) || '==', (options === null || options === void 0 ? void 0 : options.value) || options);
|
|
1200
1200
|
};
|
|
1201
1201
|
}
|
|
1202
|
-
find({ filters, limits, orderBy, }) {
|
|
1202
|
+
find({ filters, limits, orderBy, } = {}) {
|
|
1203
1203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1204
|
-
let query = this.collection(this.buildCollectionPathForFind(filters));
|
|
1205
|
-
query = this.makeFirestoreWhere(query, filters);
|
|
1204
|
+
let query = this.collection(this.buildCollectionPathForFind(filters || {}));
|
|
1205
|
+
query = this.makeFirestoreWhere(query, filters || {});
|
|
1206
1206
|
Object.keys(orderBy || {}).forEach((fieldName) => (query = query.orderBy(fieldName, orderBy[fieldName])));
|
|
1207
1207
|
query = yield this.defineLimits(query, filters, limits);
|
|
1208
1208
|
const docs = yield query.get();
|
|
@@ -1570,6 +1570,7 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
1570
1570
|
constructor(firestore) {
|
|
1571
1571
|
super();
|
|
1572
1572
|
this.firestore = firestore;
|
|
1573
|
+
this.reviews = {};
|
|
1573
1574
|
this.collectionName = 'products';
|
|
1574
1575
|
this.model = Product;
|
|
1575
1576
|
}
|
|
@@ -1585,6 +1586,33 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
1585
1586
|
return (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
|
|
1586
1587
|
});
|
|
1587
1588
|
}
|
|
1589
|
+
fetchReviews(status) {
|
|
1590
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1591
|
+
const { data: products } = yield this.find();
|
|
1592
|
+
products.forEach((product) => {
|
|
1593
|
+
var _a;
|
|
1594
|
+
if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
|
|
1595
|
+
return;
|
|
1596
|
+
const productInfo = {
|
|
1597
|
+
productId: product.id,
|
|
1598
|
+
productName: product.name,
|
|
1599
|
+
productSku: product.sku,
|
|
1600
|
+
};
|
|
1601
|
+
this.reviews.pending = [];
|
|
1602
|
+
this.reviews.approved = [];
|
|
1603
|
+
this.reviews.rejected = [];
|
|
1604
|
+
product.reviews.forEach((review) => {
|
|
1605
|
+
if ([null, undefined].includes(review.status))
|
|
1606
|
+
return this.reviews.pending.push(Object.assign(Object.assign({}, review), productInfo));
|
|
1607
|
+
if (review.status === false)
|
|
1608
|
+
return this.reviews.rejected.push(Object.assign(Object.assign({}, review), productInfo));
|
|
1609
|
+
if (!!review.status)
|
|
1610
|
+
return this.reviews.approved.push(Object.assign(Object.assign({}, review), productInfo));
|
|
1611
|
+
});
|
|
1612
|
+
});
|
|
1613
|
+
return this.reviews[status];
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1588
1616
|
}
|
|
1589
1617
|
|
|
1590
1618
|
class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Product) {
|
|
@@ -2105,7 +2133,7 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
|
|
|
2105
2133
|
const getValueByAction = (options) => {
|
|
2106
2134
|
if (options instanceof BaseModel)
|
|
2107
2135
|
return options.toPlain();
|
|
2108
|
-
if (isNil(options.action))
|
|
2136
|
+
if (isNil(options === null || options === void 0 ? void 0 : options.action))
|
|
2109
2137
|
return options;
|
|
2110
2138
|
if ([UpdateOptionActions.REMOVE_FIELD.toString(), UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
2111
2139
|
return null;
|
|
@@ -2443,7 +2471,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2443
2471
|
authOptions,
|
|
2444
2472
|
fields: [],
|
|
2445
2473
|
});
|
|
2446
|
-
this.bindReviewToModel = (plain) => (Object.assign(Object.assign({}, omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])), { createdAt: plain.created_at, updatedAt: plain.updated_at, personId: plain.person_id, orderId: plain.order_id }));
|
|
2474
|
+
this.bindReviewToModel = (plain) => (Object.assign(Object.assign({}, omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])), { createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at, updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at, personId: plain.person_id, orderId: plain.order_id }));
|
|
2447
2475
|
this.bindReviewToHasura = (review) => (Object.assign(Object.assign({}, omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])), { person_id: review.personId, order_id: review.orderId }));
|
|
2448
2476
|
const commonFields = [
|
|
2449
2477
|
{ id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
|
|
@@ -2620,6 +2648,26 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
2620
2648
|
return product;
|
|
2621
2649
|
});
|
|
2622
2650
|
}
|
|
2651
|
+
fetchReviews(status) {
|
|
2652
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2653
|
+
const reviews = {
|
|
2654
|
+
status: status === 'pending'
|
|
2655
|
+
? { [HasuraGraphQLWhere.ISNULL]: true }
|
|
2656
|
+
: { [HasuraGraphQLWhere.EQUALS]: status === 'approved' },
|
|
2657
|
+
};
|
|
2658
|
+
const { product: data } = yield this.query('product', ['id', 'name', 'sku', { reviews: { columnName: 'reviews', fields: this.reviewsFields } }], {
|
|
2659
|
+
where: { value: { reviews }, type: 'product_bool_exp', required: true },
|
|
2660
|
+
});
|
|
2661
|
+
return data.reduce((reviews, product) => [
|
|
2662
|
+
...reviews,
|
|
2663
|
+
...product.reviews
|
|
2664
|
+
.filter((review) => (status === 'pending' && [undefined, null].includes(review.status)) ||
|
|
2665
|
+
(status === 'approved' && review.status === true) ||
|
|
2666
|
+
(status === 'rejected' && review.status === false))
|
|
2667
|
+
.map((review) => (Object.assign(Object.assign({}, this.bindReviewToModel(review)), { productId: product.id, productName: product.name, productSku: product.sku }))),
|
|
2668
|
+
], []);
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2623
2671
|
updateCategories(productId, { categories }) {
|
|
2624
2672
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2625
2673
|
const plainData = this.paramsToPlain({ categories });
|