text: import { URLS } from '../constants'
  import { parentHeader } from '../../helpers';
  
  export const parentService = {
    getChild,
    getSessionsFrom
  };
  
  function getChild(id) {
    const requestOptions = {
      method: 'GET',
      headers: parentHeader(),
    };
  
    return fetch(`${URLS.ROOT_PARENT}/child/${id}`, requestOptions).then(handleResponse);
  }
  
  function getSessionsFrom(id) {
    const requestOptions = {
      method: 'GET',
      headers: parentHeader(),
    };
  
    return fetch(`${URLS.ROOT_PARENT}/sessions-from/${id}`, requestOptions).then(handleResponse);
  }
  
  function handleResponse(response) {
    return response.text().then(text => {
      const data = text && JSON.parse(text);
      if (!response.ok) {
        if (response.status === 401) {
          // auto logout if 401 response returned from api
          // logout();
          // location.reload(true)
        }
        const error = (data && data.message) || response.statusText;
        return Promise.reject(error);
      }
      return data;
    });
  }