Skip to content

Commit 0477cfe

Browse files
committed
modified user's api
1 parent 8f92e6b commit 0477cfe

File tree

8 files changed

+39
-13
lines changed

8 files changed

+39
-13
lines changed

app/controllers/event.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ module.exports = {
184184

185185
getAllEventByUser: async (req, res, next) => {
186186
try {
187-
const events = await Event.find({ createdBy: req.user._id }, {}, helper.paginate(req))
187+
const { id } = req.params
188+
const events = await Event.find({ createdBy: id }, {}, helper.paginate(req))
188189
.sort({ eventDate: -1 })
189190
.populate('createdBy', '_id name.firstName name.lastName')
190191
.exec()

app/controllers/post.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module.exports = {
167167
getPostByUser: async (req, res, next) => {
168168
try {
169169
const posts = await PostModel.find(
170-
{ userId: req.user._id },
170+
{ userId: req.params.id },
171171
{},
172172
helper.paginate(req)
173173
)

app/controllers/project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module.exports = {
105105
},
106106
projectCreatedByUser: async (req, res, next) => {
107107
try {
108-
const { id } = req.user
108+
const { id } = req.params
109109
const projects = await Project.find({ createdBy: id }, {}, helper.paginate(req))
110110
.populate('createdBy', '_id name.firstName name.lastName email')
111111
.sort({ updatedAt: -1 })

app/controllers/user.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,30 @@ module.exports = {
4646
// GET USER PROFILE
4747
userProfile: async (req, res, next) => {
4848
try {
49-
const user = req.user
49+
const { id } = req.params
50+
const user = await User.findById({ _id: id })
51+
.populate('followings', [
52+
'name.firstName',
53+
'name.lastName',
54+
'info.about.designation',
55+
'_id',
56+
'isAdmin'
57+
])
58+
.populate('followers', [
59+
'name.firstName',
60+
'name.lastName',
61+
'info.about.designation',
62+
'_id',
63+
'isAdmin'
64+
])
65+
.populate('blocked', [
66+
'name.firstName',
67+
'name.lastName',
68+
'info.about.designation',
69+
'_id',
70+
'isAdmin'
71+
])
72+
.exec()
5073
if (!user) {
5174
return res.status(HttpStatus.NOT_FOUND).json({ msg: 'No such user exist!' })
5275
}
@@ -81,11 +104,13 @@ module.exports = {
81104
}
82105

83106
try {
107+
const { id } = req.params
108+
const user = await User.findById(id)
84109
updates.forEach((update) => {
85-
req.user[update] = req.body[update]
110+
user[update] = req.body[update]
86111
})
87-
await req.user.save()
88-
return res.status(HttpStatus.OK).json({ data: req.user })
112+
await user.save()
113+
return res.status(HttpStatus.OK).json({ data: user })
89114
} catch (error) {
90115
return res.status(HttpStatus.BAD_REQUEST).json({ error })
91116
}

app/routes/event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ router.delete(
5858

5959
// GET ALL EVENT POSTED BY A USER
6060
router.get(
61-
'/me/all',
61+
'/:id/all',
6262
isUnderMaintenance,
6363
auth,
6464
eventController.getAllEventByUser

app/routes/post.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ router.patch(
5858

5959
// GET POST PER USER
6060
router.get(
61-
'/me/all',
61+
'/:id/all',
6262
auth,
6363
postController.getPostByUser
6464
)

app/routes/project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ router.delete(
4646

4747
// GET PROJECTS CREATED BY A USER
4848
router.get(
49-
'/me/all',
49+
'/:id/all',
5050
isUnderMaintenance,
5151
auth,
5252
projectController.projectCreatedByUser

app/routes/user.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ router.post(
1515

1616
// get user profile
1717
router.get(
18-
'/me',
18+
'/:id',
1919
isUnderMaintenance,
2020
auth,
2121
userController.userProfile
2222
)
2323

2424
// update user info
2525
router.patch(
26-
'/me',
26+
'/:id',
2727
isUnderMaintenance,
2828
auth,
2929
userController.userProfileUpdate
@@ -116,7 +116,7 @@ router.patch(
116116

117117
// GET PERSONAL OVERVIEW
118118
router.get(
119-
'/overview',
119+
'/me/overview',
120120
isUnderMaintenance,
121121
auth,
122122
userController.getPersonalOverview

0 commit comments

Comments
 (0)