{"size": 928, "ext": "js", "max_stars_repo_path": "frontend/hospital/src/utils/withAPI.js", "max_stars_repo_name": "psychonetic/betfinder", "max_stars_repo_stars_event_min_datetime": "2020-03-22T22:07:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-27T14:18:59.000Z", "max_issues_repo_path": "frontend/hospital/src/utils/withAPI.js", "max_issues_repo_name": "psychonetic/betfinder", "max_issues_repo_issues_event_min_datetime": "2021-03-10T11:53:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T01:39:40.000Z", "max_forks_repo_path": "frontend/hospital/src/utils/withAPI.js", "max_forks_repo_name": "psychonetic/betfinder", "max_forks_repo_forks_event_min_datetime": "2020-03-23T06:11:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-23T06:11:32.000Z"}
{"max_stars_count": 6, "max_issues_count": 11, "max_forks_count": 1, "avg_line_length": 26.5142857143, "max_line_length": 102, "alphanum_fraction": 0.59375}
import { create } from 'axios';

export const API = create({
  baseURL: process.env.GATSBY_API_URL || 'https://api.olezierau.de/api',
  headers: {
    'X-Requested-With': 'XMLHttpRequest',
    'Content-Type': 'application/json'
  }
})


export function withAPI() {
  return {
    searchHospitals({ lat, lng, distance, postal_code, city }) {
      return API.get(`/hospitals`, {params: { lat, lng, distance, postal_code, city, with: 'info' }});
    },
    getHospital(hid) {
      return API.get(`/hospitals/${hid}`);
    },
    getHospitalInfo(hid) {
      return API.get(`/hospitals/${hid}/beds/info`);
    },
    blockBed(type, hid) {
      return API.patch(`/hospitals/${hid || '1'}/beds/reserve`, type)
    },
    releaseBed(type, hid) {
      return API.patch(`/hospitals/${hid || '1'}/beds/free`, type)
    },
    createBedBatch(type, hid) {
      return API.post(`/hospitals/${hid || '1'}/beds/btach`, type)
    }
  }
}

