import { AuthActions , TAuthActions } from './auth.actions' ; import { IUserModel , User } from '@app/shared/models/users/users.model' ; export interface ICurrentUserState extends IUserModel { } export const intitialState = null ; export function reducer ( state = intitialState , action ) { switch ( action . type ) { case AuthActions . LOGIN_SUCCESS : { return Object . assign ( { } , state ) ; } case AuthActions . CHECK_AUTH_SUCCESS : { if ( ! action . payload . user ) { return state ; } const user = new User ( Object . assign ( { } , action . payload . user ) ) ; return Object . assign ( { } , state , user ) ; } case AuthActions . LOGOUT_SUCCESS : { return intitialState ; } case AuthActions . CREATE_SUCCESS : { return new User ( Object . assign ( { } , action . payload . user ) ) ; } case AuthActions . CHECK_AUTH_NO_USER : { return intitialState ; } default : { return < ICurrentUserState > state ; } } }