@@ -46,9 +46,9 @@ module.exports = {
46
46
// GET USER PROFILE
47
47
userProfile : async ( req , res , next ) => {
48
48
try {
49
- const id = req . params . id ? req . params . id : req . user . _id
49
+ const id = req . params . id || req . user . _id
50
50
const user = await User . findById ( { _id : id } )
51
- . populate ( 'followings' , [
51
+ . populate ( 'followings' , [
52
52
'name.firstName' ,
53
53
'name.lastName' ,
54
54
'info.about.designation' ,
@@ -255,16 +255,16 @@ module.exports = {
255
255
256
256
// ADD TO THE FOLLOWINGS LIST
257
257
addFollowing : async ( req , res , next ) => {
258
- const { followId } = req . body
258
+ const { id } = req . params
259
259
try {
260
- if ( followId === req . user . _id ) {
260
+ if ( id === req . user . _id ) {
261
261
return res . status ( HttpStatus . OK ) . json ( { msg : 'You can not follow yourself!' } )
262
262
}
263
263
const user = await User . findById ( req . user . id )
264
264
if ( ! user ) {
265
265
return res . status ( HttpStatus . BAD_REQUEST ) . json ( { msg : 'No such user exists!' } )
266
266
}
267
- user . followings . unshift ( followId )
267
+ user . followings . unshift ( id )
268
268
await user . save ( )
269
269
next ( )
270
270
} catch ( error ) {
@@ -274,9 +274,10 @@ module.exports = {
274
274
275
275
// ADD TO FOLLOWERS LIST
276
276
addFollower : async ( req , res , next ) => {
277
- const { followId } = req . body
277
+ console . log ( 'follow request!' )
278
+ const { id } = req . params
278
279
try {
279
- const user = await User . findById ( followId )
280
+ const user = await User . findById ( id )
280
281
if ( ! user ) {
281
282
return res . status ( HttpStatus . BAD_REQUEST ) . json ( { msg : 'No such user exists!' } )
282
283
}
@@ -305,15 +306,15 @@ module.exports = {
305
306
306
307
// REMOVE FROM FOLLOWINGS LIST
307
308
removeFollowing : async ( req , res , next ) => {
308
- const { followId } = req . body
309
+ const { id } = req . params
309
310
try {
310
311
const user = await User . findById ( req . user . _id )
311
312
if ( ! user ) {
312
313
return res . status ( HttpStatus . OK ) . json ( { msg : 'No such user exists!' } )
313
314
}
314
315
// check if followId is in following list or not
315
316
const followingIdArray = user . followings . map ( followingId => followingId . _id )
316
- const isFollowingIdIndex = followingIdArray . indexOf ( followId )
317
+ const isFollowingIdIndex = followingIdArray . indexOf ( id )
317
318
if ( isFollowingIdIndex === - 1 ) {
318
319
return res . status ( HttpStatus . OK ) . json ( { msg : 'You haven\'t followed the user!' } )
319
320
} else {
@@ -329,9 +330,9 @@ module.exports = {
329
330
330
331
// REMOVE FROM FOLLOWERS LIST
331
332
removeFollower : async ( req , res , next ) => {
332
- const { followId } = req . body
333
+ const { id } = req . params
333
334
try {
334
- const user = await User . findById ( followId )
335
+ const user = await User . findById ( id )
335
336
if ( ! user ) {
336
337
return res . status ( HttpStatus . NOT_FOUND ) . json ( { msg : 'No such user exists!' } )
337
338
}
0 commit comments