@infrab4a/connect 0.14.5-beta.0 → 0.14.5
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 +66 -71
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/esm2015/lib/domain/shopping/models/coupons/financial-coupon.js +1 -1
- package/esm2015/lib/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +6 -8
- package/esm2015/lib/infra/firebase/firestore/repositories/catalog/category-firestore.repository.js +19 -23
- package/fesm2015/infrab4a-connect.js +23 -29
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/lib/domain/shopping/models/coupons/financial-coupon.d.ts +0 -1
- package/lib/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +4 -1
- package/package.json +1 -1
|
@@ -1579,23 +1579,20 @@
|
|
|
1579
1579
|
var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
|
|
1580
1580
|
_this.makeFirestoreWhere = function (queryReference, filter) { return Object.keys(filter).reduce(function (query, fieldName) { return _this.buildWhereSentence(query, fieldName, filter[fieldName]); }, queryReference); };
|
|
1581
1581
|
_this.buildWhereSentence = function (queryReference, fieldName, options) {
|
|
1582
|
-
var _b;
|
|
1583
1582
|
if (_this.isSubCollection(_this) && fieldName === _this.parentIdField)
|
|
1584
1583
|
return queryReference;
|
|
1585
|
-
var plainInstance = new _this.model((_b = {}, _b[fieldName] = options === null || options === void 0 ? void 0 : options.value, _b)).toPlain();
|
|
1586
|
-
var firestoreFieldName = Object.keys(plainInstance).find(function (key) { return plainInstance[key] === (options === null || options === void 0 ? void 0 : options.value); });
|
|
1587
1584
|
if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.LIKE) {
|
|
1588
1585
|
if (Array.isArray(options === null || options === void 0 ? void 0 : options.value))
|
|
1589
|
-
return queryReference.where(
|
|
1590
|
-
queryReference = queryReference.where(
|
|
1591
|
-
queryReference = queryReference.where(
|
|
1586
|
+
return queryReference.where(fieldName.toString(), 'array-contains-any', options.value);
|
|
1587
|
+
queryReference = queryReference.where(fieldName.toString(), '>=', options.value);
|
|
1588
|
+
queryReference = queryReference.where(fieldName.toString(), '<=', options.value + "~");
|
|
1592
1589
|
return queryReference;
|
|
1593
1590
|
}
|
|
1594
1591
|
if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.IN && Array.isArray(options === null || options === void 0 ? void 0 : options.value))
|
|
1595
|
-
return queryReference.where(
|
|
1592
|
+
return queryReference.where(fieldName.toString(), 'array-contains', options.value);
|
|
1596
1593
|
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))
|
|
1597
1594
|
return Object.keys(options).reduce(function (queryReferenceWithWhere, key) { return _this.buildWhereSentence(queryReferenceWithWhere, fieldName + "." + key, options[key]); }, queryReference);
|
|
1598
|
-
return queryReference.where(
|
|
1595
|
+
return queryReference.where(fieldName.toString(), (options === null || options === void 0 ? void 0 : options.operator) || '==', (options === null || options === void 0 ? void 0 : options.value) || options);
|
|
1599
1596
|
};
|
|
1600
1597
|
return _this;
|
|
1601
1598
|
}
|
|
@@ -2084,39 +2081,79 @@
|
|
|
2084
2081
|
CategoryFirestoreRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
|
|
2085
2082
|
if (limit === void 0) { limit = 4; }
|
|
2086
2083
|
return __awaiter(this, void 0, void 0, function () {
|
|
2087
|
-
var categorySnap, categories, homeSections
|
|
2088
|
-
var
|
|
2089
|
-
return __generator(this, function (
|
|
2090
|
-
switch (
|
|
2084
|
+
var categorySnap, categories, homeSections;
|
|
2085
|
+
var _this = this;
|
|
2086
|
+
return __generator(this, function (_a) {
|
|
2087
|
+
switch (_a.label) {
|
|
2091
2088
|
case 0: return [4 /*yield*/, this.collection(this.collectionName)
|
|
2092
2089
|
.where('id', 'in', categoryIds)
|
|
2093
2090
|
.where('published', '==', true)
|
|
2094
2091
|
.get()];
|
|
2095
2092
|
case 1:
|
|
2096
|
-
categorySnap =
|
|
2093
|
+
categorySnap = _a.sent();
|
|
2097
2094
|
if (categorySnap.empty)
|
|
2098
2095
|
throw new NotFoundError('Categories not found');
|
|
2099
2096
|
categories = categorySnap.docs.map(function (doc) { return doc.data(); });
|
|
2100
|
-
|
|
2097
|
+
return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
2098
|
+
var _a;
|
|
2099
|
+
return __generator(this, function (_b) {
|
|
2100
|
+
switch (_b.label) {
|
|
2101
|
+
case 0:
|
|
2102
|
+
_a = {
|
|
2103
|
+
category: category
|
|
2104
|
+
};
|
|
2105
|
+
return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
|
|
2106
|
+
case 1: return [2 /*return*/, (_a.products = _b.sent(),
|
|
2107
|
+
_a)];
|
|
2108
|
+
}
|
|
2109
|
+
});
|
|
2110
|
+
}); }))];
|
|
2111
|
+
case 2:
|
|
2112
|
+
homeSections = _a.sent();
|
|
2113
|
+
return [2 /*return*/, homeSections];
|
|
2114
|
+
}
|
|
2115
|
+
});
|
|
2116
|
+
});
|
|
2117
|
+
};
|
|
2118
|
+
CategoryFirestoreRepository.prototype.mountCategory = function (category, options) {
|
|
2119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2120
|
+
var chunks, products, publishedField, chunks_1, chunks_1_1, productIds, query, productSnap, e_1_1;
|
|
2121
|
+
var e_1, _a;
|
|
2122
|
+
return __generator(this, function (_b) {
|
|
2123
|
+
switch (_b.label) {
|
|
2124
|
+
case 0:
|
|
2125
|
+
if (!category.products)
|
|
2126
|
+
throw new RequiredArgumentError(['Category products is empty']);
|
|
2127
|
+
chunks = lodash.chunk(category.products, 10);
|
|
2128
|
+
products = [];
|
|
2129
|
+
publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
|
|
2130
|
+
_b.label = 1;
|
|
2131
|
+
case 1:
|
|
2132
|
+
_b.trys.push([1, 7, 8, 9]);
|
|
2133
|
+
chunks_1 = __values(chunks), chunks_1_1 = chunks_1.next();
|
|
2101
2134
|
_b.label = 2;
|
|
2102
2135
|
case 2:
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2136
|
+
if (!!chunks_1_1.done) return [3 /*break*/, 6];
|
|
2137
|
+
productIds = chunks_1_1.value;
|
|
2138
|
+
if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
|
|
2139
|
+
return [3 /*break*/, 6];
|
|
2140
|
+
return [4 /*yield*/, this.collection('products').where(publishedField, '==', true).where('id', 'in', productIds)];
|
|
2106
2141
|
case 3:
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2142
|
+
query = _b.sent();
|
|
2143
|
+
if (options === null || options === void 0 ? void 0 : options.hasStock)
|
|
2144
|
+
query = query.where('stock.quantity', '>', 0);
|
|
2145
|
+
if (options === null || options === void 0 ? void 0 : options.limit)
|
|
2146
|
+
query = query.limit(options === null || options === void 0 ? void 0 : options.limit);
|
|
2147
|
+
return [4 /*yield*/, query.get()];
|
|
2110
2148
|
case 4:
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
});
|
|
2149
|
+
productSnap = _b.sent();
|
|
2150
|
+
if (productSnap.empty)
|
|
2151
|
+
return [3 /*break*/, 5];
|
|
2152
|
+
products.push.apply(products, __spreadArray([], __read(productSnap.docs.map(function (doc) { return doc.data(); }))));
|
|
2116
2153
|
_b.label = 5;
|
|
2117
2154
|
case 5:
|
|
2118
|
-
|
|
2119
|
-
return [3 /*break*/,
|
|
2155
|
+
chunks_1_1 = chunks_1.next();
|
|
2156
|
+
return [3 /*break*/, 2];
|
|
2120
2157
|
case 6: return [3 /*break*/, 9];
|
|
2121
2158
|
case 7:
|
|
2122
2159
|
e_1_1 = _b.sent();
|
|
@@ -2124,53 +2161,11 @@
|
|
|
2124
2161
|
return [3 /*break*/, 9];
|
|
2125
2162
|
case 8:
|
|
2126
2163
|
try {
|
|
2127
|
-
if (
|
|
2164
|
+
if (chunks_1_1 && !chunks_1_1.done && (_a = chunks_1.return)) _a.call(chunks_1);
|
|
2128
2165
|
}
|
|
2129
2166
|
finally { if (e_1) throw e_1.error; }
|
|
2130
2167
|
return [7 /*endfinally*/];
|
|
2131
|
-
case 9: return [2 /*return*/,
|
|
2132
|
-
}
|
|
2133
|
-
});
|
|
2134
|
-
});
|
|
2135
|
-
};
|
|
2136
|
-
CategoryFirestoreRepository.prototype.mountCategory = function (category) {
|
|
2137
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2138
|
-
var chunks, products, publishedField;
|
|
2139
|
-
var _this = this;
|
|
2140
|
-
return __generator(this, function (_a) {
|
|
2141
|
-
switch (_a.label) {
|
|
2142
|
-
case 0:
|
|
2143
|
-
if (!category.products)
|
|
2144
|
-
throw new RequiredArgumentError(['Category products is empty']);
|
|
2145
|
-
chunks = category.products.reduce(function (resultArray, item, index) {
|
|
2146
|
-
var chunkIndex = Math.floor(index / 10);
|
|
2147
|
-
if (!resultArray[chunkIndex])
|
|
2148
|
-
resultArray[chunkIndex] = [];
|
|
2149
|
-
resultArray[chunkIndex].push(item);
|
|
2150
|
-
return resultArray;
|
|
2151
|
-
}, []);
|
|
2152
|
-
products = [];
|
|
2153
|
-
publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
|
|
2154
|
-
return [4 /*yield*/, Promise.all(chunks.map(function (productIds) { return __awaiter(_this, void 0, void 0, function () {
|
|
2155
|
-
var productSnap;
|
|
2156
|
-
return __generator(this, function (_a) {
|
|
2157
|
-
switch (_a.label) {
|
|
2158
|
-
case 0: return [4 /*yield*/, this.collection('products')
|
|
2159
|
-
.where(publishedField, '==', true)
|
|
2160
|
-
.where('id', 'in', productIds)
|
|
2161
|
-
.get()];
|
|
2162
|
-
case 1:
|
|
2163
|
-
productSnap = _a.sent();
|
|
2164
|
-
if (productSnap.empty)
|
|
2165
|
-
return [2 /*return*/];
|
|
2166
|
-
products.push.apply(products, __spreadArray([], __read(productSnap.docs.map(function (doc) { return doc.data(); }))));
|
|
2167
|
-
return [2 /*return*/];
|
|
2168
|
-
}
|
|
2169
|
-
});
|
|
2170
|
-
}); }))];
|
|
2171
|
-
case 1:
|
|
2172
|
-
_a.sent();
|
|
2173
|
-
return [2 /*return*/, products];
|
|
2168
|
+
case 9: return [2 /*return*/, products];
|
|
2174
2169
|
}
|
|
2175
2170
|
});
|
|
2176
2171
|
});
|