import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { HTTP } from 'meteor/http';
import DeviceCode from '../collections/devicecode.js';
Meteor.methods({
    'getDeviceCodes' () {
        this.unblock();
        if (this.userId) {
            try {
                const result = HTTP.call('GET', `${Meteor.settings.worklistUrl}/HISIntegration.svc/rest/getdevicecodes`);
                let deviceCodeHttpResult = JSON.parse(result.content);
                DeviceCode.remove({});
                deviceCodeHttpResult.Devices.forEach((device) => {
                    DeviceCode.insert({
                        ...device
                    });
                });
                return true
            } catch (e) {
                // Got a network error, timeout, or HTTP error in the 400 or 500 range.
                return false;
            }
        }
    }
});