backend: populated routes

This commit is contained in:
muerwre 2018-11-30 16:06:52 +07:00
parent 723ab51eef
commit 6ffdca22d7
5 changed files with 25 additions and 9 deletions

View file

@ -8,7 +8,7 @@ export const DEFAULT_USER = {
place_types: {},
random_url: '',
role: ROLES.guest,
routes: [],
routes: {},
success: false,
id: null,
token: null,

View file

@ -2,9 +2,16 @@ import axios from 'axios/index';
import { API } from '$constants/api';
const arrayToObject = (array, key) => array.reduce((obj, el) => ({ ...obj, [el[key]]: el }));
export const checkUserToken = ({ id, token }) => axios.get(API.CHECK_TOKEN, {
params: { id, token }
}).then(result => (result && result.data && { ...result.data, id, token }));
}).then(result => (result && result.data && {
...result.data,
id,
token,
routes: (result.data.routes && result.data.routes.length > 0 && arrayToObject(result.data.routes, '_id')) || {},
}));
export const getGuestToken = () => axios.get(API.GET_GUEST).then(result => (result && result.data));