Skip to content

Commit

Permalink
feat: commit after state management review
Browse files Browse the repository at this point in the history
  • Loading branch information
suschneider committed Nov 18, 2022
1 parent 5962e04 commit 3685ff8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TestBed } from '@angular/core/testing';
import { ProductNotificatioData } from './product-notification.interface';
import { ProductNotificatioMapper } from './product-notification.mapper';

describe('Product Notificatio Mapper', () => {
describe('Product Notification Mapper', () => {
let productNotificatioMapper: ProductNotificatioMapper;

beforeEach(() => {
Expand All @@ -19,6 +19,9 @@ describe('Product Notificatio Mapper', () => {
const data: ProductNotificatioData = {
incomingField: 'test',
otherField: false,
sku: 'product_sku',
notificationMailAddress: 'test@test.intershop.de',
price: { type: 'Money', value: 75, currencyMnemonic: 'USD', currency: 'USD' },
};
const mapped = productNotificatioMapper.fromData(data);
expect(mapped).toHaveProperty('id', 'test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h1>{{ 'account.notifications.heading' | translate }}</h1>

<h3>{{ 'account.notifications.price.heading' | translate }}</h3>
<ng-container *ngIf="productNotificationsPrice$ | async as productNotificationsPrice">
<ng-container *ngIf="productNotificationsPrice?.length > 0" class="list-body">
<ng-container *ngIf="productNotificationsPrice?.length">
<ng-container *ngFor="let productNotification of productNotificationsPrice">
<div>
{{ productNotification.sku }} | {{ productNotification.type }} |
Expand All @@ -15,7 +15,7 @@ <h3>{{ 'account.notifications.price.heading' | translate }}</h3>

<h3>{{ 'account.notifications.backinstock.heading' | translate }}</h3>
<ng-container *ngIf="productNotificationsInStock$ | async as productNotificationsInStock">
<ng-container *ngIf="productNotificationsInStock?.length > 0" class="list-body">
<ng-container *ngIf="productNotificationsInStock?.length">
<ng-container *ngFor="let productNotification of productNotificationsInStock">
<div>
{{ productNotification.sku }} | {{ productNotification.type }} |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { FeatureToggleGuard } from 'ish-core/feature-toggle.module';
import { AuthGuard } from 'ish-core/guards/auth.guard';

const routes: Routes = [
{
Expand All @@ -10,7 +11,7 @@ const routes: Routes = [
import('./account-product-notifications/account-product-notifications-page.module').then(
m => m.AccountProductNotificationsPageModule
),
canActivate: [FeatureToggleGuard],
canActivate: [FeatureToggleGuard, AuthGuard],
data: { feature: 'productNotifications' },
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export class ProductNotificationsService {

private currentCustomer$ = this.store.pipe(select(getLoggedInCustomer), whenTruthy(), take(1));

/**
* Get all product notifications of a specific type from a customer.
*
* @param notificationType The type of the product notifications.
* Possible types are 'price' (a specific product price is reached) and 'stock' (product is back in stock)
* @returns All product notifications of a specific type from the customer.
*/
getProductNotifications(notificationType: ProductNotificationType): Observable<ProductNotification[]> {
return this.currentCustomer$.pipe(
switchMap(customer =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const loadProductNotifications = createAction(
);

export const loadProductNotificationsSuccess = createAction(
'[ProductNotification] Load ProductNotifications Success',
'[ProductNotification API] Load ProductNotifications Success',
payload<{ productNotifications: ProductNotification[] }>()
);

export const loadProductNotificationsFail = createAction(
'[ProductNotification] Load ProductNotifications Fail',
'[ProductNotification API] Load ProductNotifications Fail',
httpError()
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { concatMap, map } from 'rxjs';

import { mapErrorToAction, mapToPayload } from 'ish-core/utils/operators';
import { mapErrorToAction, mapToPayloadProperty } from 'ish-core/utils/operators';

import { ProductNotificationsService } from '../../services/product-notifications/product-notifications.service';

Expand All @@ -19,8 +19,8 @@ export class ProductNotificationEffects {
loadProductNotifications$ = createEffect(() =>
this.actions$.pipe(
ofType(loadProductNotifications),
mapToPayload(),
concatMap(({ type }) =>
mapToPayloadProperty('type'),
concatMap(type =>
this.productNotificationsService.getProductNotifications(type).pipe(
map(productNotifications => loadProductNotificationsSuccess({ productNotifications })),
mapErrorToAction(loadProductNotificationsFail)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { NgModule } from '@angular/core';
import { Injectable, NgModule } from '@angular/core';
import { EffectsModule } from '@ngrx/effects';
import { ActionReducerMap, StoreModule } from '@ngrx/store';
import { ActionReducerMap, StoreConfig, StoreModule } from '@ngrx/store';
import { pick } from 'lodash-es';

import { resetOnLogoutMeta } from 'ish-core/utils/meta-reducers';

import { ProductNotificationEffects } from './product-notification/product-notification.effects';
import { productNotificationReducer } from './product-notification/product-notification.reducer';
import { ProductNotificationsState } from './product-notifications-store';
Expand All @@ -13,7 +15,11 @@ const productNotificationsReducers: ActionReducerMap<ProductNotificationsState>

const productNotificationsEffects = [ProductNotificationEffects];

// not-dead-code
@Injectable()
export class ProductNotificationsConfig implements StoreConfig<ProductNotificationsState> {
metaReducers = [resetOnLogoutMeta];
}

@NgModule({
imports: [
EffectsModule.forFeature(productNotificationsEffects),
Expand Down

0 comments on commit 3685ff8

Please sign in to comment.