2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-20 16:19:40 +02:00
|
|
|
import alt from '../alt';
|
|
|
|
import UserFetcher from '../fetchers/user_fetcher';
|
|
|
|
|
2015-05-20 16:44:45 +02:00
|
|
|
|
2015-05-20 16:19:40 +02:00
|
|
|
class UserActions {
|
|
|
|
constructor() {
|
|
|
|
this.generateActions(
|
2015-06-20 16:43:18 +02:00
|
|
|
'updateCurrentUser',
|
|
|
|
'deleteCurrentUser'
|
2015-05-20 16:19:40 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchCurrentUser() {
|
2015-07-21 15:05:42 +02:00
|
|
|
return UserFetcher.fetchOne()
|
2015-05-20 16:19:40 +02:00
|
|
|
.then((res) => {
|
2015-06-05 11:06:36 +02:00
|
|
|
this.actions.updateCurrentUser(res.users[0]);
|
2015-05-20 16:19:40 +02:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
2015-07-17 15:41:09 +02:00
|
|
|
console.logGlobal(err);
|
2015-07-16 19:12:18 +02:00
|
|
|
this.actions.updateCurrentUser({});
|
2015-05-20 16:19:40 +02:00
|
|
|
});
|
|
|
|
}
|
2015-08-03 10:41:51 +02:00
|
|
|
|
2015-06-20 16:43:18 +02:00
|
|
|
logoutCurrentUser() {
|
2015-07-17 18:53:04 +02:00
|
|
|
return UserFetcher.logout()
|
2015-06-20 16:43:18 +02:00
|
|
|
.then(() => {
|
|
|
|
this.actions.deleteCurrentUser();
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2015-07-17 15:41:09 +02:00
|
|
|
console.logGlobal(err);
|
2015-06-20 16:43:18 +02:00
|
|
|
});
|
|
|
|
}
|
2015-06-05 11:06:36 +02:00
|
|
|
}
|
2015-05-20 16:19:40 +02:00
|
|
|
|
|
|
|
export default alt.createActions(UserActions);
|