Skip to content

Commit

Permalink
Merge pull request #57 from Skill-Sync/SS-1.4-Medhat
Browse files Browse the repository at this point in the history
Ss 1.4 medhat
  • Loading branch information
MAES-Pyramids authored Sep 15, 2023
2 parents 10f449e + 78b6bbb commit 311763d
Show file tree
Hide file tree
Showing 9 changed files with 595 additions and 171 deletions.
Binary file added dump.rdb
Binary file not shown.
88 changes: 88 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"nodemailer": "^6.9.5",
"nodemon": "^3.0.1",
"pm2": "^5.3.0",
"redis": "^4.6.8",
"socket.io": "^4.7.2",
"ts-jest": "^29.1.1",
"validator": "^13.11.0",
Expand Down
5 changes: 4 additions & 1 deletion src/controllers/meeting.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ exports.createMeeting = catchAsyncError(async (req, res, next) => {
exports.getMeeting = catchAsyncError(async (req, res, next) => {
const meeting = await Meeting.find({
mentor: req.params.id
});
})
.populate({ path: 'user', select: 'name email' })
.populate({ path: 'mentor', select: 'name email' });

if (!meeting)
return next(new AppError('No meeting found with that ID', 404));

Expand Down
84 changes: 43 additions & 41 deletions src/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,63 @@ const AppError = require('../utils/appErrorsClass');
const catchAsyncError = require('../utils/catchAsyncErrors');
//------------handler functions ------------//
const filterObj = (obj, ...allowedFields) => {
const returnedFiled = {};
Object.keys(obj).forEach(key => {
if (allowedFields.includes(key)) returnedFiled[key] = obj[key];
});
return returnedFiled;
const returnedFiled = {};
Object.keys(obj).forEach(key => {
if (allowedFields.includes(key)) returnedFiled[key] = obj[key];
});
return returnedFiled;
};
// ---------- User Operations ---------//
exports.getMe = (req, res, next) => {
req.params.id = res.locals.userId;
next();
req.params.id = res.locals.userId;
next();
};

exports.UpdateMe = catchAsyncError(async (req, res, next) => {
if (req.body.pass || req.body.passConfirm) {
return next(new AppError('This route is not for password updates.', 400));
}
if (req.body.pass || req.body.passConfirm) {
return next(
new AppError('This route is not for password updates.', 400)
);
}

const filteredBody = filterObj(
req.body,
'name',
'email',
'about',
'isEmployed',
'skillsToLearn',
'skillsLearned'
);
const filteredBody = filterObj(
req.body,
'name',
'email',
'about',
'isEmployed',
'skillsToLearn',
'skillsLearned'
);

const updatedUser = await User.findById(req.params.id);
Object.keys(filteredBody).forEach(key => {
updatedUser[key] = filteredBody[key];
});
await updatedUser.save({ runValidators: true });
const updatedUser = await User.findById(req.params.id);
Object.keys(filteredBody).forEach(key => {
updatedUser[key] = filteredBody[key];
});
await updatedUser.save({ runValidators: true });

res.status(res.locals.statusCode || 200).json({
status: 'success',
data: updatedUser
});
res.status(res.locals.statusCode || 200).json({
status: 'success',
data: updatedUser
});
});

exports.getRelevantMentors = catchAsyncError(async (req, res, next) => {
const user = await User.findById(res.locals.userId);
const user = await User.findById(res.locals.userId);

const mentors = await Mentor.find({
skill: {
$in: user.skillsToLearn.map(skill => skill._id)
}
}).populate({
path: 'skill',
select: 'name'
});
const mentors = await Mentor.find({
skill: {
$in: user.skillsToLearn.map(skill => skill._id)
}
}).populate({
path: 'skill',
select: 'name'
});

res.status(res.locals.statusCode || 200).json({
status: 'success',
data: mentors
});
res.status(res.locals.statusCode || 200).json({
status: 'success',
data: mentors
});
});

// exports.deactivateUser = factory.deactivateOne(User);
Expand Down
Loading

0 comments on commit 311763d

Please sign in to comment.