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

declare let settings:TSettings;

export class AppCommands implements IAppCommands {

    public editObject(key:string, formData:any):Promise<any>
    {
        let token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
        return axios.post(
            settings.editObjUrl,
            {
                _token:token,
                id:settings.item.id,
                key:key,
                object:formData,
            }
        )
        .then((resp:any)=>{
            return Promise.resolve(resp.data);
        })
        .catch((error:any)=>{
            return Promise.reject(error.response.data);
        });
    }

}