2017-10-07 00:10:23 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2021-04-07 03:32:04 +08:00
|
|
|
import updateRole from '/imports/api/users-persistent-data/server/modifiers/updateRole';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-10-07 00:10:23 +08:00
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
export default async function changeRole(role, userId, meetingId, changedBy) {
|
2017-10-07 00:10:23 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
2019-06-29 04:52:19 +08:00
|
|
|
role,
|
2017-10-07 00:10:23 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
2023-03-15 21:18:31 +08:00
|
|
|
const numberAffected = await Users.updateAsync(selector, modifier);
|
2017-10-07 00:10:23 +08:00
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
if (numberAffected) {
|
2023-03-20 21:21:34 +08:00
|
|
|
await updateRole(userId, meetingId, role);
|
2020-11-23 21:13:46 +08:00
|
|
|
Logger.info(`Changed user role=${role} id=${userId} meeting=${meetingId}`
|
|
|
|
+ `${changedBy ? ` changedBy=${changedBy}` : ''}`);
|
2017-10-07 00:10:23 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Changed user role: ${err}`);
|
|
|
|
}
|
2017-10-07 00:10:23 +08:00
|
|
|
}
|