@infrab4a/connect-angular 5.4.0-alpha.0 → 5.4.0-alpha.1

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,50 +2984,77 @@ 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: {
2996
3012
  email: email,
2997
3013
  },
2998
3014
  status: OrderStatus.ENTREGUE,
3015
+ createdAt: {
3016
+ operator: Where.GTE,
3017
+ value: new Date(2024, 0, 0, 0, 0, 0).getTime(),
3018
+ },
2999
3019
  },
3000
3020
  orderBy: {
3001
3021
  createdAt: 'desc',
3002
3022
  },
3003
3023
  });
3004
- if (orders.length) {
3005
- for (const order of orders) {
3006
- const lineItems = order.lineItems.filter((item) => !item.isGift);
3007
- for (const item of lineItems) {
3008
- const productReview = await this.productReviewRepository
3009
- .find({
3010
- filters: {
3011
- orderId: order.id,
3012
- productId: item.id,
3013
- status: { operator: Where.ISNULL },
3014
- },
3015
- })
3016
- .then((res) => res.data.at(0));
3017
- products.push(this.buildProductReview(order, item, productReview));
3018
- }
3019
- }
3020
- }
3021
- 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;
3022
3046
  }
3023
3047
  buildProductReview(order, item, review) {
3024
3048
  return {
3025
3049
  id: item.id,
3050
+ orderId: order.id,
3051
+ orderNumber: order.orderNumber,
3026
3052
  isEdition: false,
3027
3053
  name: item.name,
3028
3054
  image: item.image,
3029
3055
  deliveryDate: order.deliveredAt || null,
3030
3056
  evaluationInAnalysis: review ? true : false,
3057
+ rating: review ? review.rate : null,
3031
3058
  shopProductSlug: item.slug,
3032
3059
  };
3033
3060
  }
@@ -3047,7 +3074,7 @@ class OrderProductReviewService {
3047
3074
  }));
3048
3075
  }
3049
3076
  }
3050
- 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 });
3051
3078
  OrderProductReviewService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderProductReviewService });
3052
3079
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderProductReviewService, decorators: [{
3053
3080
  type: Injectable
@@ -3057,6 +3084,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
3057
3084
  }] }, { type: undefined, decorators: [{
3058
3085
  type: Inject,
3059
3086
  args: ['ProductReviewRepository']
3087
+ }] }, { type: undefined, decorators: [{
3088
+ type: Inject,
3089
+ args: ['VariantRepository']
3060
3090
  }] }]; } });
3061
3091
 
3062
3092
  class OrderService {