Introduce service repository
[arvados.git] / src / store / auth / auth-action.ts
index a6e6f79794db27bc64178b6f53626c6e688c3865..8b268cce5d5cb83b68f7a73e9a4b66936f4dd8c3 100644 (file)
@@ -4,10 +4,11 @@
 
 import { ofType, default as unionize, UnionOf } from "unionize";
 import { Dispatch } from "redux";
-import { authService } from "../../services/services";
 import { User } from "../../models/user";
+import { RootState } from "../store";
+import { ServiceRepository } from "../../services/services";
 
-const actions = unionize({
+export const authActions = unionize({
     SAVE_API_TOKEN: ofType<string>(),
     LOGIN: {},
     LOGOUT: {},
@@ -19,14 +20,12 @@ const actions = unionize({
     value: 'payload'
 });
 
-export const getUserDetails = () => (dispatch: Dispatch): Promise<User> => {
-    dispatch(actions.USER_DETAILS_REQUEST());
-    return authService.getUserDetails().then(details => {
-        dispatch(actions.USER_DETAILS_SUCCESS(details));
+export const getUserDetails = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<User> => {
+    dispatch(authActions.USER_DETAILS_REQUEST());
+    return services.authService.getUserDetails().then(details => {
+        dispatch(authActions.USER_DETAILS_SUCCESS(details));
         return details;
     });
 };
 
-
-export type AuthAction = UnionOf<typeof actions>;
-export default actions;
+export type AuthAction = UnionOf<typeof authActions>;