import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { HTTP } from 'meteor/http';

Meteor.methods({
    'createClient' (item) {

        this.unblock();
        if (this.userId) {
            try {
                let options = {
                    data: item,
                    headers: {
                        'content-type': 'application/json',
                        'Accept': 'application/json'
                    }
                }
                const result = HTTP.call("POST", `${Meteor.settings.databusUrl}/clients/create`, options);
                return true
            } catch (e) {
                // Got a network error, timeout, or HTTP error in the 400 or 500 range.
                console.log(e);
                return false;
            }
        }
    },
    "editClient" (item) {
        this.unblock();
        if (this.userId) {
            try {
                let options = {
                    data: item,
                    headers: {
                        'content-type': 'application/json',
                        'Accept': 'application/json'
                    }
                }
                const result = HTTP.call("POST", `${Meteor.settings.databusUrl}/clients/update`, options);
                return true
            } catch (e) {
                // Got a network error, timeout, or HTTP error in the 400 or 500 range.
                console.log(e);
                return false;
            }
        }
    },
    "deleteClient" (item) {
        this.unblock();
        if (this.userId) {
            try {
                let options = {
                    data: item,
                    headers: {
                        'content-type': 'application/json',
                        'Accept': 'application/json'
                    }
                }
                const result = HTTP.call("POST", `${Meteor.settings.databusUrl}/clients/delete`, options);
                return true
            } catch (e) {
                // Got a network error, timeout, or HTTP error in the 400 or 500 range.
                console.log(e);
                return false;
            }
        }
    },
});