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

Meteor.methods({
    'createDevicemap' (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}/devicemap/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;
            }
        }
    },
    "editDevicemap" (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}/devicemap/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;
            }
        }
    },
    "deleteDevicemap" (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}/devicemap/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;
            }
        }
    },
});