Updates for async and await - still

This commit is contained in:
Brian McGonagill 2025-07-22 13:50:49 -05:00
parent febb36d75f
commit 706c5dc3ef
18 changed files with 220 additions and 233 deletions

View file

@ -6,66 +6,63 @@ import { SysConfig } from '../imports/api/systemConfig';
import { Roles } from 'meteor/roles';
Meteor.methods({
'addToRole' (role) {
const getUserInfo = async() => {
try {
let countOfUsers = await Meteor.users.find().countAsync();
const user = await Meteor.userAsync();
if (user) {
let userId = user._id;
if (countOfUsers > 1) {
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) {
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.");
}
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("The count of users didn't seem to work when adding a new user.");
// 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(" ---- No user info found.")
console.log("The count of users didn't seem to work when adding a new user.");
}
} catch(error) {
console.log(" ERROR getting user info on server: " + error);
} else {
console.log(" ---- No user info found.")
}
} catch(error) {
console.log(" ERROR getting user info on server: " + error);
}
getUserInfo();
},
'edit.userPass' (userId, newPassword) {
async 'edit.userPass' (userId, newPassword) {
check(userId, String);
check(newPassword, String);
return Accounts.setPasswordAsync(userId, newPassword);
return await Accounts.setPasswordAsync(userId, newPassword);
},
'delete.userFromSys' (userId) {
async 'delete.userFromSys' (userId) {
check(userId, String);
return Meteor.users.removeAsync({ _id: userId });
return await Meteor.users.removeAsync({ _id: userId });
},
'update.userEmail' (userId, email) {
async 'update.userEmail' (userId, email) {
check(userId, String);
check(email, String);
return Meteor.users.updateAsync({ _id: userId }, {
return await Meteor.users.updateAsync({ _id: userId }, {
$set: {
'emails.0.address': email,
}
});
},
'edit.userRole' (userId, role) {
async 'edit.userRole' (userId, role) {
check(userId, String);
check(role, String);
return Roles.setUserRolesAsync(userId, role);
return await Roles.setUserRolesAsync(userId, role);
},
});