Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified user's api #168

Merged
merged 2 commits into from
Aug 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/event.js
Original file line number Diff line number Diff line change
@@ -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()
16 changes: 16 additions & 0 deletions app/controllers/organization.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
2 changes: 1 addition & 1 deletion app/controllers/post.js
Original file line number Diff line number Diff line change
@@ -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)
)
2 changes: 1 addition & 1 deletion app/controllers/project.js
Original file line number Diff line number Diff line change
@@ -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 })
33 changes: 29 additions & 4 deletions app/controllers/user.js
Original file line number Diff line number Diff line change
@@ -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 })
}
2 changes: 1 addition & 1 deletion app/routes/event.js
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ router.delete(

// GET ALL EVENT POSTED BY A USER
router.get(
'/me/all',
'/:id/all',
isUnderMaintenance,
auth,
eventController.getAllEventByUser
7 changes: 7 additions & 0 deletions app/routes/organisation.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/routes/post.js
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ router.patch(

// GET POST PER USER
router.get(
'/me/all',
'/:id/all',
auth,
postController.getPostByUser
)
2 changes: 1 addition & 1 deletion app/routes/project.js
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ router.delete(

// GET PROJECTS CREATED BY A USER
router.get(
'/me/all',
'/:id/all',
isUnderMaintenance,
auth,
projectController.projectCreatedByUser
8 changes: 4 additions & 4 deletions app/routes/user.js
Original file line number Diff line number Diff line change
@@ -15,15 +15,15 @@ router.post(

// get user profile
router.get(
'/me',
'/:id',
isUnderMaintenance,
auth,
userController.userProfile
)

// 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