All files / src/app/extensions/rating/facades product-reviews.facade.ts

33.33% Statements 4/12
75% Branches 3/4
0% Functions 0/5
33.33% Lines 4/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 392x 2x     2x                     2x                                              
import { Injectable } from '@angular/core';
import { Store, select } from '@ngrx/store';
 
import { ProductReview, ProductReviewCreationType } from '../models/product-reviews/product-review.model';
import {
  createProductReview,
  deleteProductReview,
  getProductReviewsBySku,
  getProductReviewsError,
  getProductReviewsLoading,
  loadProductReviews,
  resetProductReviewError,
} from '../store/product-reviews';
 
@Injectable({ providedIn: 'root' })
export class ProductReviewsFacade {
  constructor(private store: Store) {}
 
  productReviewsError$ = this.store.pipe(select(getProductReviewsError));
  productReviewsLoading$ = this.store.pipe(select(getProductReviewsLoading));
 
  getProductReviews$(sku: string) {
    this.store.dispatch(loadProductReviews({ sku }));
    return this.store.pipe(select(getProductReviewsBySku(sku)));
  }
 
  createProductReview(sku: string, review: ProductReviewCreationType) {
    this.store.dispatch(createProductReview({ sku, review }));
  }
 
  deleteProductReview(sku: string, review: ProductReview): void {
    this.store.dispatch(deleteProductReview({ sku, review }));
  }
 
  resetProductReviewError() {
    this.store.dispatch(resetProductReviewError());
  }
}