diff --git a/app/controllers/event.js b/app/controllers/event.js index ebc17fa..b7e48ea 100644 --- a/app/controllers/event.js +++ b/app/controllers/event.js @@ -184,7 +184,8 @@ module.exports = { getAllEventByUser: async (req, res, next) => { try { - const events = await Event.find({ createdBy: req.user._id }, {}, helper.paginate(req)) + const { id } = req.params + const events = await Event.find({ createdBy: id }, {}, helper.paginate(req)) .sort({ eventDate: -1 }) .populate('createdBy', '_id name.firstName name.lastName') .exec() diff --git a/app/controllers/organization.js b/app/controllers/organization.js index f6c2ecc..1791547 100644 --- a/app/controllers/organization.js +++ b/app/controllers/organization.js @@ -9,6 +9,7 @@ const Project = require('../models/Project') const Event = require('../models/Event') const permission = require('../utils/permission') const TAGS = require('../utils/notificationTags') +const Organisation = require('../models/Organisation') const notification = { heading: '', content: '', @@ -326,5 +327,20 @@ module.exports = { } catch (error) { HANDLER.handleError(res, error) } + }, + + // GET ORG LOGIN OPTIONS + getOrgLoginOptions: async (req, res, next) => { + try { + const org = await Organisation.find({}) + .lean() + .exec() + if (org.length == 0) { + return res.status(HttpStatus.NOT_FOUND).json({ error: 'No such organization exists!' }) + } + return res.status(HttpStatus.OK).json({ methods: org[0].options.authentication }) + } catch(error) { + HANDLER.handleError(res, error) + } } } diff --git a/app/controllers/post.js b/app/controllers/post.js index 5177ffd..f96a9f4 100644 --- a/app/controllers/post.js +++ b/app/controllers/post.js @@ -167,7 +167,7 @@ module.exports = { getPostByUser: async (req, res, next) => { try { const posts = await PostModel.find( - { userId: req.user._id }, + { userId: req.params.id }, {}, helper.paginate(req) ) diff --git a/app/controllers/project.js b/app/controllers/project.js index 39770ab..203dc8f 100644 --- a/app/controllers/project.js +++ b/app/controllers/project.js @@ -105,7 +105,7 @@ module.exports = { }, projectCreatedByUser: async (req, res, next) => { try { - const { id } = req.user + const { id } = req.params const projects = await Project.find({ createdBy: id }, {}, helper.paginate(req)) .populate('createdBy', '_id name.firstName name.lastName email') .sort({ updatedAt: -1 }) diff --git a/app/controllers/user.js b/app/controllers/user.js index 5cc134d..d581b7d 100644 --- a/app/controllers/user.js +++ b/app/controllers/user.js @@ -46,7 +46,30 @@ module.exports = { // GET USER PROFILE userProfile: async (req, res, next) => { try { - const user = req.user + const id = req.params.id ? req.params.id : req.user._id + const user = await User.findById({ _id: id }) + .populate('followings', [ + 'name.firstName', + 'name.lastName', + 'info.about.designation', + '_id', + 'isAdmin' + ]) + .populate('followers', [ + 'name.firstName', + 'name.lastName', + 'info.about.designation', + '_id', + 'isAdmin' + ]) + .populate('blocked', [ + 'name.firstName', + 'name.lastName', + 'info.about.designation', + '_id', + 'isAdmin' + ]) + .exec() if (!user) { return res.status(HttpStatus.NOT_FOUND).json({ msg: 'No such user exist!' }) } @@ -81,11 +104,13 @@ module.exports = { } try { + const { id } = req.params + const user = await User.findById(id) updates.forEach((update) => { - req.user[update] = req.body[update] + user[update] = req.body[update] }) - await req.user.save() - return res.status(HttpStatus.OK).json({ data: req.user }) + await user.save() + return res.status(HttpStatus.OK).json({ data: user }) } catch (error) { return res.status(HttpStatus.BAD_REQUEST).json({ error }) } diff --git a/app/routes/event.js b/app/routes/event.js index 0d0dc02..30efa12 100644 --- a/app/routes/event.js +++ b/app/routes/event.js @@ -58,7 +58,7 @@ router.delete( // GET ALL EVENT POSTED BY A USER router.get( - '/me/all', + '/:id/all', isUnderMaintenance, auth, eventController.getAllEventByUser diff --git a/app/routes/organisation.js b/app/routes/organisation.js index a69abc9..80b7ba7 100644 --- a/app/routes/organisation.js +++ b/app/routes/organisation.js @@ -84,4 +84,11 @@ router.patch( OrgController.removeAdmin ) +// GET ORG LOGIN OPTIONS (CALLED JUST BEFORE LOGIN) +router.get( + '/login/options', + isUnderMaintenance, + OrgController.getOrgLoginOptions +) + module.exports = router diff --git a/app/routes/post.js b/app/routes/post.js index 0208282..3839bec 100644 --- a/app/routes/post.js +++ b/app/routes/post.js @@ -58,7 +58,7 @@ router.patch( // GET POST PER USER router.get( - '/me/all', + '/:id/all', auth, postController.getPostByUser ) diff --git a/app/routes/project.js b/app/routes/project.js index 178a3f6..c6d7026 100644 --- a/app/routes/project.js +++ b/app/routes/project.js @@ -46,7 +46,7 @@ router.delete( // GET PROJECTS CREATED BY A USER router.get( - '/me/all', + '/:id/all', isUnderMaintenance, auth, projectController.projectCreatedByUser diff --git a/app/routes/user.js b/app/routes/user.js index ee6f609..76de54c 100644 --- a/app/routes/user.js +++ b/app/routes/user.js @@ -15,7 +15,7 @@ router.post( // get user profile router.get( - '/me', + '/:id', isUnderMaintenance, auth, userController.userProfile @@ -23,7 +23,7 @@ router.get( // update user info router.patch( - '/me', + '/:id', isUnderMaintenance, auth, userController.userProfileUpdate @@ -45,7 +45,7 @@ router.patch( // get invite link (for sender) router.get( - '/invite', + '/link/invite', isUnderMaintenance, auth, userController.getInviteLink @@ -116,7 +116,7 @@ router.patch( // GET PERSONAL OVERVIEW router.get( - '/overview', + '/me/overview', isUnderMaintenance, auth, userController.getPersonalOverview