Skip to content

Commit

Permalink
Implementado remoção de mentor, após promoção
Browse files Browse the repository at this point in the history
Feito Lint
  • Loading branch information
Rocsantos authored and estevaoreis25 committed Nov 20, 2020
1 parent aa23f29 commit 7bb4e07
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions server/controllers/LearnerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module.exports = {
if (!learner.mentor) throw new Error('Learner does not have a mentor');
await Mentor.findByIdAndUpdate(learner.mentor, {
$pull: { learners: learner._id },
$push: { noAssociations: learner._id},
$push: { noAssociations: learner._id },
isAvailable: false,
});
const oldMentor = learner.mentor;
Expand All @@ -103,13 +103,24 @@ module.exports = {
const hasLearnerCertificate = reqUser.courseCertificates.length > 0;

if (!hasLearnerCertificate) throw new Error('User did not conclude Tutorial');

const user = await User.findOneAndUpdate(
{ _id },
{ $set: { userType: 'Mentor' } }, { new: true },
if (reqUser.mentor) {
await User.findOneAndUpdate({ _id }, {
$pull: { learners: reqUser._id },
$push: { noAssociations: reqUser._id },
isAvailable: false,
});
reqUser.noAssociations.push(reqUser.mentor);
reqUser.mentor = null;
reqUser.save();
}
const user = await User.findByIdAndUpdate(
_id,
{
$set: { userType: 'Mentor' },
mentor_request: false,
}, { new: true },
);
user.isValidated = true;
user.mentor_request = false;
user.save();
const data = mail.learnerPromotion(user.email, user.name);
await transport.sendMail(data);
Expand Down

0 comments on commit 7bb4e07

Please sign in to comment.