@infrab4a/connect 0.4.5 → 0.4.7-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.
- package/bundles/infrab4a-connect.umd.js +79 -1
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/esm2015/lib/domain/catalog/repositories/category.repository.js +1 -1
- package/esm2015/lib/errors/duplicated-results.error.js +7 -0
- package/esm2015/lib/errors/index.js +2 -1
- package/esm2015/lib/infra/firebase/firestore/repositories/catalog/category-firestore.repository.js +39 -1
- package/esm2015/lib/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.js +2 -2
- package/fesm2015/infrab4a-connect.js +45 -2
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/lib/domain/catalog/repositories/category.repository.d.ts +7 -0
- package/lib/errors/duplicated-results.error.d.ts +4 -0
- package/lib/errors/index.d.ts +1 -0
- package/lib/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +6 -1
- package/package.json +1 -1
|
@@ -986,6 +986,16 @@
|
|
|
986
986
|
return NotFoundError;
|
|
987
987
|
}(Error));
|
|
988
988
|
|
|
989
|
+
var DuplicatedResultsError = /** @class */ (function (_super) {
|
|
990
|
+
__extends(DuplicatedResultsError, _super);
|
|
991
|
+
function DuplicatedResultsError(message) {
|
|
992
|
+
var _this = _super.call(this, message) || this;
|
|
993
|
+
_this.message = message;
|
|
994
|
+
return _this;
|
|
995
|
+
}
|
|
996
|
+
return DuplicatedResultsError;
|
|
997
|
+
}(Error));
|
|
998
|
+
|
|
989
999
|
var withFirestore = function (MixinBase) {
|
|
990
1000
|
return /** @class */ (function (_super) {
|
|
991
1001
|
__extends(class_1, _super);
|
|
@@ -1443,6 +1453,73 @@
|
|
|
1443
1453
|
_this.model = Category;
|
|
1444
1454
|
return _this;
|
|
1445
1455
|
}
|
|
1456
|
+
CategoryFirestoreRepository.prototype.getCategoryBySlug = function (slug, shop) {
|
|
1457
|
+
return this.collection(this.collectionName)
|
|
1458
|
+
.where("slug", "==", slug)
|
|
1459
|
+
.where("shop", "==", shop)
|
|
1460
|
+
.where("published", "==", true)
|
|
1461
|
+
.get().then(function (snap) {
|
|
1462
|
+
if (snap.size > 1)
|
|
1463
|
+
throw new DuplicatedResultsError("Query returned duplicated values");
|
|
1464
|
+
if (snap.empty)
|
|
1465
|
+
throw new NotFoundError("Document with slug " + slug + " not found");
|
|
1466
|
+
return snap.docs[0].data();
|
|
1467
|
+
}).catch(function (error) { return error; });
|
|
1468
|
+
};
|
|
1469
|
+
CategoryFirestoreRepository.prototype.getCategoriesForHome = function (categoryIds) {
|
|
1470
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1471
|
+
var categorySnap, categories, homeSections, categories_1, categories_1_1, category, productSnap, products, e_1_1;
|
|
1472
|
+
var e_1, _a;
|
|
1473
|
+
return __generator(this, function (_b) {
|
|
1474
|
+
switch (_b.label) {
|
|
1475
|
+
case 0: return [4 /*yield*/, this.collection(this.collectionName)
|
|
1476
|
+
.where("id", "in", categoryIds)
|
|
1477
|
+
.where("published", "==", true)
|
|
1478
|
+
.get()];
|
|
1479
|
+
case 1:
|
|
1480
|
+
categorySnap = _b.sent();
|
|
1481
|
+
if (categorySnap.empty)
|
|
1482
|
+
throw new NotFoundError("Categories not found");
|
|
1483
|
+
categories = categorySnap.docs.map(function (doc) { return doc.data(); });
|
|
1484
|
+
homeSections = [];
|
|
1485
|
+
_b.label = 2;
|
|
1486
|
+
case 2:
|
|
1487
|
+
_b.trys.push([2, 7, 8, 9]);
|
|
1488
|
+
categories_1 = __values(categories), categories_1_1 = categories_1.next();
|
|
1489
|
+
_b.label = 3;
|
|
1490
|
+
case 3:
|
|
1491
|
+
if (!!categories_1_1.done) return [3 /*break*/, 6];
|
|
1492
|
+
category = categories_1_1.value;
|
|
1493
|
+
return [4 /*yield*/, this.collection("products")
|
|
1494
|
+
.where("categories", "array-contains", category.id)
|
|
1495
|
+
.where("published", "==", true)
|
|
1496
|
+
.where("stock.quantity", ">", 1)
|
|
1497
|
+
.limit(4)
|
|
1498
|
+
.get()];
|
|
1499
|
+
case 4:
|
|
1500
|
+
productSnap = _b.sent();
|
|
1501
|
+
products = productSnap.docs.map(function (doc) { return doc.data(); });
|
|
1502
|
+
homeSections.push({ title: category.name, products: products });
|
|
1503
|
+
_b.label = 5;
|
|
1504
|
+
case 5:
|
|
1505
|
+
categories_1_1 = categories_1.next();
|
|
1506
|
+
return [3 /*break*/, 3];
|
|
1507
|
+
case 6: return [3 /*break*/, 9];
|
|
1508
|
+
case 7:
|
|
1509
|
+
e_1_1 = _b.sent();
|
|
1510
|
+
e_1 = { error: e_1_1 };
|
|
1511
|
+
return [3 /*break*/, 9];
|
|
1512
|
+
case 8:
|
|
1513
|
+
try {
|
|
1514
|
+
if (categories_1_1 && !categories_1_1.done && (_a = categories_1.return)) _a.call(categories_1);
|
|
1515
|
+
}
|
|
1516
|
+
finally { if (e_1) throw e_1.error; }
|
|
1517
|
+
return [7 /*endfinally*/];
|
|
1518
|
+
case 9: return [2 /*return*/, homeSections];
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
});
|
|
1522
|
+
};
|
|
1446
1523
|
return CategoryFirestoreRepository;
|
|
1447
1524
|
}(withCrudFirestore(withHelpers(withFirestore(Base)))));
|
|
1448
1525
|
|
|
@@ -1464,7 +1541,7 @@
|
|
|
1464
1541
|
var _this = _super.call(this) || this;
|
|
1465
1542
|
_this.firestore = firestore;
|
|
1466
1543
|
_this.parentRepository = parentRepository;
|
|
1467
|
-
_this.collectionName = '
|
|
1544
|
+
_this.collectionName = 'variants';
|
|
1468
1545
|
_this.parentIdField = 'productId';
|
|
1469
1546
|
_this.model = Variant;
|
|
1470
1547
|
return _this;
|
|
@@ -1663,6 +1740,7 @@
|
|
|
1663
1740
|
exports.CheckoutSubscriptionFirestoreRepository = CheckoutSubscriptionFirestoreRepository;
|
|
1664
1741
|
exports.Coupon = Coupon;
|
|
1665
1742
|
exports.CouponFirestoreRepository = CouponFirestoreRepository;
|
|
1743
|
+
exports.DuplicatedResultsError = DuplicatedResultsError;
|
|
1666
1744
|
exports.Edition = Edition;
|
|
1667
1745
|
exports.FinancialCoupon = FinancialCoupon;
|
|
1668
1746
|
exports.Home = Home;
|