@infrab4a/connect-angular 5.3.1-beta.7 → 5.3.1-beta.8

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.
@@ -2984,12 +2984,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
2984
2984
  }], ctorParameters: function () { return [{ type: HomeShopRepositoriesFacade }, { type: ConfigurationFacade }]; } });
2985
2985
 
2986
2986
  class OrderProductReviewService {
2987
- constructor(orderRepository, productReviewRepository) {
2987
+ constructor(orderRepository, productReviewRepository, variantRepository) {
2988
2988
  this.orderRepository = orderRepository;
2989
2989
  this.productReviewRepository = productReviewRepository;
2990
+ this.variantRepository = variantRepository;
2990
2991
  }
2991
2992
  async getPendingReviewsByEmail(email) {
2992
2993
  const products = [];
2994
+ const orders = await this.getOrdersByEmail(email);
2995
+ if (orders.length) {
2996
+ for (const order of orders) {
2997
+ const lineItems = order.lineItems.filter((item) => !item.isGift);
2998
+ for (const item of lineItems) {
2999
+ const productReview = await this.getProductReview(order, item);
3000
+ if (productReview?.status != null)
3001
+ continue;
3002
+ products.push(this.buildProductReview(order, item, productReview));
3003
+ }
3004
+ }
3005
+ }
3006
+ return products;
3007
+ }
3008
+ async getOrdersByEmail(email) {
2993
3009
  const { data: orders } = await this.orderRepository.find({
2994
3010
  filters: {
2995
3011
  user: {
@@ -3005,25 +3021,28 @@ class OrderProductReviewService {
3005
3021
  createdAt: 'desc',
3006
3022
  },
3007
3023
  });
3008
- if (orders.length) {
3009
- for (const order of orders) {
3010
- const lineItems = order.lineItems.filter((item) => !item.isGift);
3011
- for (const item of lineItems) {
3012
- const productReview = await this.productReviewRepository
3013
- .find({
3014
- filters: {
3015
- orderId: { operator: Where.IN, value: [order.id, order.orderNumber].filter(Boolean) },
3016
- productId: item.id,
3017
- },
3018
- })
3019
- .then((res) => res.data.at(0));
3020
- if (productReview?.status != null)
3021
- continue;
3022
- products.push(this.buildProductReview(order, item, productReview));
3023
- }
3024
- }
3025
- }
3026
- return products;
3024
+ return orders;
3025
+ }
3026
+ async getProductReview(order, item) {
3027
+ const products = [item.id];
3028
+ const isVariant = await this.variantRepository
3029
+ .find({
3030
+ filters: {
3031
+ id: item.id,
3032
+ },
3033
+ })
3034
+ .then((res) => res.data.at(0));
3035
+ if (isVariant)
3036
+ products.push(isVariant.productId);
3037
+ const productReview = await this.productReviewRepository
3038
+ .find({
3039
+ filters: {
3040
+ orderId: { operator: Where.IN, value: [order.id, order.orderNumber].filter(Boolean) },
3041
+ productId: { operator: Where.IN, value: products },
3042
+ },
3043
+ })
3044
+ .then((res) => res.data.at(0));
3045
+ return productReview;
3027
3046
  }
3028
3047
  buildProductReview(order, item, review) {
3029
3048
  return {
@@ -3055,7 +3074,7 @@ class OrderProductReviewService {
3055
3074
  }));
3056
3075
  }
3057
3076
  }
3058
- OrderProductReviewService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderProductReviewService, deps: [{ token: 'OrderRepository' }, { token: 'ProductReviewRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
3077
+ OrderProductReviewService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderProductReviewService, deps: [{ token: 'OrderRepository' }, { token: 'ProductReviewRepository' }, { token: 'VariantRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
3059
3078
  OrderProductReviewService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderProductReviewService });
3060
3079
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderProductReviewService, decorators: [{
3061
3080
  type: Injectable
@@ -3065,6 +3084,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
3065
3084
  }] }, { type: undefined, decorators: [{
3066
3085
  type: Inject,
3067
3086
  args: ['ProductReviewRepository']
3087
+ }] }, { type: undefined, decorators: [{
3088
+ type: Inject,
3089
+ args: ['VariantRepository']
3068
3090
  }] }]; } });
3069
3091
 
3070
3092
  class OrderService {