@infrab4a/connect 3.2.0 → 3.2.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.
@@ -2684,10 +2684,35 @@
2684
2684
  function OrderFirestoreRepository(firestore) {
2685
2685
  var _this = _super.call(this) || this;
2686
2686
  _this.firestore = firestore;
2687
+ _this.orderFromFirestore = function (order, id) {
2688
+ var _a;
2689
+ var modifiedOrder = _this.model.toInstance(Object.assign(Object.assign({}, order), { id: id }));
2690
+ if (!!((_a = modifiedOrder === null || modifiedOrder === void 0 ? void 0 : modifiedOrder.lineItems) === null || _a === void 0 ? void 0 : _a.length)) {
2691
+ modifiedOrder.lineItems = modifiedOrder.lineItems.map(function (lineItem) {
2692
+ if (!!lineItem.price[modifiedOrder.shop]) {
2693
+ var shopPrice = lineItem['price'][modifiedOrder.shop];
2694
+ lineItem['price'] = shopPrice;
2695
+ }
2696
+ return lineItem;
2697
+ });
2698
+ }
2699
+ return modifiedOrder;
2700
+ };
2687
2701
  _this.collectionName = 'orders';
2688
2702
  _this.model = Order;
2689
2703
  return _this;
2690
2704
  }
2705
+ OrderFirestoreRepository.prototype.buildModelInstance = function () {
2706
+ var _this = this;
2707
+ var _b = _super.prototype.buildModelInstance.call(this), fromFirestore = _b.fromFirestore, toFirestore = _b.toFirestore;
2708
+ return {
2709
+ toFirestore: function (data) { return toFirestore((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data); },
2710
+ fromFirestore: function (snap) {
2711
+ var instance = fromFirestore(snap);
2712
+ return _this.orderFromFirestore(instance, snap.id);
2713
+ },
2714
+ };
2715
+ };
2691
2716
  return OrderFirestoreRepository;
2692
2717
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2693
2718
 
@@ -4543,13 +4568,13 @@
4543
4568
  if (review.id)
4544
4569
  return [2 /*return*/, review];
4545
4570
  if (!review.personId) return [3 /*break*/, 2];
4546
- return [4 /*yield*/, this.getReviewByPersonId(review.personId, productId)];
4571
+ return [4 /*yield*/, this.getReviewByPersonId(review.personId, productId, review.orderId)];
4547
4572
  case 1:
4548
4573
  loadedReview = _c.sent();
4549
4574
  _c.label = 2;
4550
4575
  case 2:
4551
4576
  if (!(!loadedReview && review.author && review.email)) return [3 /*break*/, 4];
4552
- return [4 /*yield*/, this.getReviewByAuthorAndEmail(review.author, review.email, productId)];
4577
+ return [4 /*yield*/, this.getReviewByAuthorAndEmail(review.author, review.email, productId, review.orderId)];
4553
4578
  case 3:
4554
4579
  loadedReview = _c.sent();
4555
4580
  _c.label = 4;
@@ -4558,17 +4583,14 @@
4558
4583
  });
4559
4584
  });
4560
4585
  };
4561
- ProductHasuraGraphQLRepository.prototype.getReviewByPersonId = function (personId, productId) {
4586
+ ProductHasuraGraphQLRepository.prototype.getReviewByPersonId = function (personId, productId, orderId) {
4562
4587
  return __awaiter(this, void 0, void 0, function () {
4563
4588
  var data;
4564
4589
  return __generator(this, function (_c) {
4565
4590
  switch (_c.label) {
4566
4591
  case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
4567
4592
  where: {
4568
- value: {
4569
- product_id: { _eq: productId },
4570
- person_id: { _eq: personId },
4571
- },
4593
+ value: Object.assign({ product_id: { _eq: productId }, person_id: { _eq: personId } }, (orderId && { order_id: { _eq: orderId } })),
4572
4594
  type: "product_review_bool_exp",
4573
4595
  required: true,
4574
4596
  },
@@ -4580,18 +4602,14 @@
4580
4602
  });
4581
4603
  });
4582
4604
  };
4583
- ProductHasuraGraphQLRepository.prototype.getReviewByAuthorAndEmail = function (author, email, productId) {
4605
+ ProductHasuraGraphQLRepository.prototype.getReviewByAuthorAndEmail = function (author, email, productId, orderId) {
4584
4606
  return __awaiter(this, void 0, void 0, function () {
4585
4607
  var data;
4586
4608
  return __generator(this, function (_c) {
4587
4609
  switch (_c.label) {
4588
4610
  case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
4589
4611
  where: {
4590
- value: {
4591
- product_id: { _eq: productId },
4592
- author: { _eq: author },
4593
- email: { _eq: email },
4594
- },
4612
+ value: Object.assign({ product_id: { _eq: productId }, author: { _eq: author }, email: { _eq: email } }, (orderId && { order_id: { _eq: orderId } })),
4595
4613
  type: "product_review_bool_exp",
4596
4614
  required: true,
4597
4615
  },