import axios from 'axios';
import {IAppCommands} from '../interfaces/commands/IAppCommands';
import {TUser} from '../types/TUser';
import {TSettings} from '../types/TSettings';

declare let settings:TSettings;

export class AppCommands implements IAppCommands {

    public request(data:TUser):Promise<any>
    {
        let token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
        return axios.post(
            settings.requestUrl,
            {
                _token:token,
                id:data.id || '',
                email:data.email || '',
                password:data.password || '',
            }
        )
        .then((resp:any)=>{
            return Promise.resolve(resp.data);
        })
        .catch((error:any)=>{
            return Promise.reject(error.response.data);
        });
    }

}