import axios from 'axios';

export class Service {

    constructor(path){
        this.base_url = 'http://204.48.25.93:8081'
        this.url =  this.base_url + path
        // this.base_url = 'http://psicoadmin.ditca.org:8081'
        // this.api =  'http://204.48.25.93:8081/user?user=patrik&password=12345'
        // this.api =  'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345'
    }

    async get(token){
        return axios.get(this.url, {
            headers: {
                'Authorization': `Bearer ${token}`
            }
        })
        .then((res) => {
            return res;
        })
        .catch((error) => {
            return error;
        })
    }

    async post(body, token){

        if(!token){
            let response = await axios({
                method: "POST",
                url: this.url,
                headers:{
                    'Content-Type': 'application/json',
                },
                data :body
            })
            return await response.data; 
        }


        const MyHeaders ={
            'Authorization': 'Bearer '+ token,
        }
        
        let response = await axios({
            method: "POST",
            url : this.url,
            headers: MyHeaders,
            data: body
        })
        console.log('response', response)

        return await response.data; 

    }
    
    
}

