mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Add deteacher script
This commit is contained in:
parent
b0ad8b2573
commit
673c608d5a
1 changed files with 38 additions and 0 deletions
38
scripts/mongodb/deteacher.js
Normal file
38
scripts/mongodb/deteacher.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
// Unset someone with a teacher role. Remove trial requests, set role to student or nothing
|
||||
// depending on if they're in any classrooms.
|
||||
|
||||
// Usage
|
||||
// ---------------
|
||||
// In mongo shell
|
||||
//
|
||||
// > db.loadServerScripts();
|
||||
// > deteacher('some@email.com');
|
||||
|
||||
var deteacher = function deteacher(email) {
|
||||
var user = db.users.findOne({emailLower: email.toLowerCase()});
|
||||
if (!user) {
|
||||
print('User not found');
|
||||
return;
|
||||
}
|
||||
print('Found user', user.name, user.email, user.role, user._id);
|
||||
var trialRequests = db.trial.requests.find({applicant: user._id}).toArray();
|
||||
for (var index in trialRequests) {
|
||||
var trialRequest = trialRequests[index];
|
||||
print('Delete trial request', JSON.stringify(trialRequest, null, ' '), db.trial.requests.remove({_id: trialRequest._id}, true));
|
||||
}
|
||||
var classroomCount = db.classrooms.count({members: user._id});
|
||||
if (classroomCount > 0) {
|
||||
print('Set to student', db.users.update({_id: user._id}, {$set: {role: 'student'}}));
|
||||
}
|
||||
else {
|
||||
print('Unset role', db.users.update({_id: user._id}, {$unset: {role: ''}}));
|
||||
}
|
||||
}
|
||||
|
||||
db.system.js.save(
|
||||
{
|
||||
_id: 'deteacher',
|
||||
value: deteacher
|
||||
}
|
||||
)
|
Loading…
Reference in a new issue