import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo'; import { check } from 'meteor/check'; import { TaskItems } from '../imports/api/tasks'; import { SysConfig } from '../imports/api/systemConfig'; import { Roles } from 'meteor/roles'; Meteor.methods({ async 'addToRole' (role) { try { let countOfUsers = await Meteor.users.find().countAsync(); const user = await Meteor.userAsync(); if (user) { let userId = user._id; if (countOfUsers > 1) { await Roles.addUsersToRolesAsync(userId, role); const result = await Meteor.callAsync('add.darkModePref', "light"); if (!result) { console.log(" ERROR: can't set user dark mode preference: " + err); } else { // console.log(" SUCCESSFULLY set user dark mode preference."); } } else if (countOfUsers == 1) { await Roles.addUsersToRolesAsync(userId, "systemadmin"); const result = await Meteor.callAsync('add.darkModePref', "light"); if (!result) { console.log(" ERROR: can't set user dark mode preference: " + err); } else { console.log(" SUCCESSFULLY set user dark mode preference."); } } else { console.log("The count of users didn't seem to work when adding a new user."); } } else { console.log(" ---- No user info found.") } } catch(error) { console.log(" ERROR getting user info on server: " + error); } }, async 'edit.userPass' (userId, newPassword) { check(userId, String); check(newPassword, String); return await Accounts.setPasswordAsync(userId, newPassword); }, async 'delete.userFromSys' (userId) { check(userId, String); return await Meteor.users.removeAsync({ _id: userId }); }, async 'update.userEmail' (userId, email) { check(userId, String); check(email, String); return await Meteor.users.updateAsync({ _id: userId }, { $set: { 'emails.0.address': email, } }); }, async 'edit.userRole' (userId, role) { check(userId, String); check(role, String); return await Roles.setUserRolesAsync(userId, role); }, });