All files / actions login.ts

70.59% Statements 12/17
100% Branches 2/2
16.67% Functions 1/6
70.59% Lines 12/17
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77          2x 2x 2x 2x 2x 2x 2x                                                               2x             2x             2x           2x             2x            
 
import { History } from 'history';
import { UserInfo } from '../userProfile';
import { ErrorAction } from './action.types';
 
export enum Actions {
  logIn = 'login.logIn',
  logOut = 'login.logOut',
  error = 'login.error',
  getUser = 'login.getUser',
  getUserResult = 'login.getUserResult',
  setAccessToken = 'login.setAccessToken'
}
 
//tslint:disable:no-reserved-keywords
export interface LoginAction extends ErrorAction {
  type: Actions.logIn;
  history: History;
}
 
export interface LogoutAction extends ErrorAction {
  type: Actions.logOut;
  user?: UserInfo;
}
 
export interface GetLoggedInUser extends ErrorAction {
  type: Actions.getUser;
}
 
export interface GetLoggedInUserSucceeded extends ErrorAction {
  type: Actions.getUserResult;
  user: UserInfo;
}
 
export interface SetAccessTokenAction extends ErrorAction {
  type: Actions.setAccessToken;
  token: string;
}
 
export type LoginActions = LoginAction | LogoutAction |
  GetLoggedInUser | GetLoggedInUserSucceeded |
  SetAccessTokenAction;
 
export function login(history): LoginAction {
  return {
    type: Actions.logIn,
    history
  };
}
 
export function logout(user?: UserInfo): LogoutAction {
  return {
    type: Actions.logOut,
    user
  };
}
 
export function getLoggedInUser(): GetLoggedInUser {
  return {
    type: Actions.getUser
  };
}
 
export function getLoggedInUserSucceeded(user: UserInfo): GetLoggedInUserSucceeded {
  return {
    type: Actions.getUserResult,
    user
  };
}
 
export function setAccessToken(token: string): SetAccessTokenAction {
  return {
    type: Actions.setAccessToken,
    token
  };
}