@infrab4a/connect 0.16.10 → 0.17.0-beta.0

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.
@@ -1543,7 +1543,7 @@
1543
1543
  ];
1544
1544
  return [4 /*yield*/, this.adapter.query('products/_search', Object.assign({ _source: fields, query: {
1545
1545
  bool: {
1546
- filter: __spreadArray([
1546
+ filter: __spreadArray(__spreadArray([
1547
1547
  {
1548
1548
  terms: {
1549
1549
  _id: ids,
@@ -1554,7 +1554,7 @@
1554
1554
  _a[publishedField] = true,
1555
1555
  _a),
1556
1556
  }
1557
- ], __read((options.hasStock
1557
+ ], __read((options.hasStock && !options.stock
1558
1558
  ? [
1559
1559
  {
1560
1560
  range: {
@@ -1564,6 +1564,16 @@
1564
1564
  },
1565
1565
  },
1566
1566
  ]
1567
+ : []))), __read((options.stock
1568
+ ? [
1569
+ {
1570
+ range: {
1571
+ 'stock.quantity': {
1572
+ gte: options.stock,
1573
+ },
1574
+ },
1575
+ },
1576
+ ]
1567
1577
  : []))),
1568
1578
  },
1569
1579
  } }, (options.size ? { size: options.size } : {})))];
@@ -2162,9 +2172,10 @@
2162
2172
 
2163
2173
  var CategoryFirestoreRepository = /** @class */ (function (_super) {
2164
2174
  __extends(CategoryFirestoreRepository, _super);
2165
- function CategoryFirestoreRepository(firestore) {
2175
+ function CategoryFirestoreRepository(firestore, productsIndex) {
2166
2176
  var _this = _super.call(this) || this;
2167
2177
  _this.firestore = firestore;
2178
+ _this.productsIndex = productsIndex;
2168
2179
  _this.collectionName = 'categories';
2169
2180
  _this.model = Category;
2170
2181
  return _this;
@@ -2184,8 +2195,8 @@
2184
2195
  })
2185
2196
  .catch(function (error) { return error; });
2186
2197
  };
2187
- CategoryFirestoreRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
2188
- if (limit === void 0) { limit = 4; }
2198
+ CategoryFirestoreRepository.prototype.getCategoriesForHome = function (categoryIds, _a) {
2199
+ var _b = _a === void 0 ? {} : _a, limit = _b.limit, stock = _b.stock;
2189
2200
  return __awaiter(this, void 0, void 0, function () {
2190
2201
  var categorySnap, categories, homeSections;
2191
2202
  var _this = this;
@@ -2208,7 +2219,7 @@
2208
2219
  _a = {
2209
2220
  category: category
2210
2221
  };
2211
- return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
2222
+ return [4 /*yield*/, this.mountCategory(category, { limit: limit, stock: stock, hasStock: true })];
2212
2223
  case 1: return [2 /*return*/, (_a.products = _b.sent(),
2213
2224
  _a)];
2214
2225
  }
@@ -2223,58 +2234,15 @@
2223
2234
  };
2224
2235
  CategoryFirestoreRepository.prototype.mountCategory = function (category, options) {
2225
2236
  return __awaiter(this, void 0, void 0, function () {
2226
- var chunks, products, publishedField, chunks_1, chunks_1_1, productIds, query, productSnap, e_1_1;
2227
- var e_1, _a;
2228
- return __generator(this, function (_b) {
2229
- switch (_b.label) {
2230
- case 0:
2231
- if (!category.products)
2232
- throw new RequiredArgumentError(['Category products is empty']);
2233
- chunks = lodash.chunk(category.products, 10);
2234
- products = [];
2235
- publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
2236
- _b.label = 1;
2237
- case 1:
2238
- _b.trys.push([1, 7, 8, 9]);
2239
- chunks_1 = __values(chunks), chunks_1_1 = chunks_1.next();
2240
- _b.label = 2;
2241
- case 2:
2242
- if (!!chunks_1_1.done) return [3 /*break*/, 6];
2243
- productIds = chunks_1_1.value;
2244
- if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
2245
- return [3 /*break*/, 6];
2246
- return [4 /*yield*/, this.collection('productsErpVitrine')
2247
- .where(publishedField, '==', true)
2248
- .where('id', 'in', productIds)];
2249
- case 3:
2250
- query = _b.sent();
2251
- if (options === null || options === void 0 ? void 0 : options.hasStock)
2252
- query = query.where('stock.quantity', '>', 0);
2253
- if (options === null || options === void 0 ? void 0 : options.limit)
2254
- query = query.limit(options === null || options === void 0 ? void 0 : options.limit);
2255
- return [4 /*yield*/, query.get()];
2256
- case 4:
2257
- productSnap = _b.sent();
2258
- if (productSnap.empty)
2259
- return [3 /*break*/, 5];
2260
- products.push.apply(products, __spreadArray([], __read(productSnap.docs.map(function (doc) { return doc.data(); }))));
2261
- _b.label = 5;
2262
- case 5:
2263
- chunks_1_1 = chunks_1.next();
2264
- return [3 /*break*/, 2];
2265
- case 6: return [3 /*break*/, 9];
2266
- case 7:
2267
- e_1_1 = _b.sent();
2268
- e_1 = { error: e_1_1 };
2269
- return [3 /*break*/, 9];
2270
- case 8:
2271
- try {
2272
- if (chunks_1_1 && !chunks_1_1.done && (_a = chunks_1.return)) _a.call(chunks_1);
2273
- }
2274
- finally { if (e_1) throw e_1.error; }
2275
- return [7 /*endfinally*/];
2276
- case 9: return [2 /*return*/, products];
2277
- }
2237
+ return __generator(this, function (_a) {
2238
+ if (!category.products)
2239
+ throw new RequiredArgumentError(['Category products is empty']);
2240
+ return [2 /*return*/, this.productsIndex.findById(category.products, {
2241
+ hasStock: options === null || options === void 0 ? void 0 : options.hasStock,
2242
+ size: options === null || options === void 0 ? void 0 : options.limit,
2243
+ stock: options.stock,
2244
+ shop: category.shop,
2245
+ })];
2278
2246
  });
2279
2247
  });
2280
2248
  };
@@ -2286,7 +2254,7 @@
2286
2254
  function ProductFirestoreRepository(firestore) {
2287
2255
  var _this = _super.call(this) || this;
2288
2256
  _this.firestore = firestore;
2289
- _this.collectionName = 'productsErpVitrine';
2257
+ _this.collectionName = 'products';
2290
2258
  _this.model = Product;
2291
2259
  return _this;
2292
2260
  }