import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { HTTP } from 'meteor/http';
import { Accounts } from "meteor/accounts-base";



Meteor.methods({
    'createUser1' (item) {
        this.unblock();
        if (this.userId) {
            try {
                debugger;
                let userExists = Meteor.users.findOne({ username: item.username });
                if (userExists == undefined || userExists == null)
                    Accounts.createUser({
                        username: item.username,
                        password: item.password
                    });

                return true
            } catch (e) {
                // Got a network error, timeout, or HTTP error in the 400 or 500 range.
                console.log(e);
                return false;
            }
        }
    },
    "editUser1" (item) {
        this.unblock();
        if (this.userId) {
            try {
                debugger;
                Accounts.setPassword(item._id, item.password, { logout: true })
                return true
            } catch (e) {
                // Got a network error, timeout, or HTTP error in the 400 or 500 range.
                console.log(e);
                return false;
            }
        }
    },
    "deleteUser1" (item) {
        debugger
        this.unblock();
        if (this.userId) {
            try {
                debugger;
                Meteor.users.remove({ _id: item._id });
                return true
            } catch (e) {
                // Got a network error, timeout, or HTTP error in the 400 or 500 range.
                console.log(e);
                return false;
            }
        }
    },
});