From 6f54971a163ee3fabb03a1ce6bb223a6e273c992 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sun, 1 May 2016 13:28:54 +0300 Subject: [PATCH] Decouple api/accounts into a separate module --- src/components/user/actions.js | 6 +++--- src/services/api/accounts.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/services/api/accounts.js diff --git a/src/components/user/actions.js b/src/components/user/actions.js index ad99a83..78d9ebc 100644 --- a/src/components/user/actions.js +++ b/src/components/user/actions.js @@ -1,4 +1,5 @@ import request from 'services/request'; +import accounts from 'services/api/accounts'; export const UPDATE = 'USER_UPDATE'; /** @@ -26,7 +27,7 @@ export function logout() { export function fetchUserData() { return (dispatch) => - request.get('/api/accounts/current') + accounts.current() .then((resp) => { dispatch(updateUser(resp)); }) @@ -51,8 +52,7 @@ export function changePassword({ logoutAll = true, }) { return (dispatch) => - request.post( - '/api/accounts/change-password', + accounts.changePassword( {password, newPassword, newRePassword, logoutAll} ) .then((resp) => { diff --git a/src/services/api/accounts.js b/src/services/api/accounts.js new file mode 100644 index 0000000..67eb43d --- /dev/null +++ b/src/services/api/accounts.js @@ -0,0 +1,19 @@ +import request from 'services/request'; + +export default { + current() { + return request.get('/api/accounts/current'); + }, + + changePassword({ + password = '', + newPassword = '', + newRePassword = '', + logoutAll = true + }) { + return request.post( + '/api/accounts/change-password', + {password, newPassword, newRePassword, logoutAll} + ); + } +};