diff --git a/src/api/v1/follow.ts b/src/api/v1/follow.ts index 1a557f0..4e90cb1 100644 --- a/src/api/v1/follow.ts +++ b/src/api/v1/follow.ts @@ -139,10 +139,10 @@ router.get('/', async (request: express.Request, response: express.Response) => } const follows = result.map(data => data.dataValues[target]); - + response.json({ follows: follows, - pageToken: follows.length > 0 ? follows[follows.length - 1].id : null + pageToken: follows.length > 0 ? result[result.length-1].dataValues.id : parseInt(request.query.pageToken as string) }); return; diff --git a/src/api/v1/logoffedPostList.ts b/src/api/v1/logoffedPostList.ts index 5ffd4cf..ea02250 100644 --- a/src/api/v1/logoffedPostList.ts +++ b/src/api/v1/logoffedPostList.ts @@ -40,11 +40,14 @@ router.get('/recent-videos', async (request: express.Request, response: express. return; } + const videoListResponse: VideoListResponse = { videoList: videos.map((video) => video.toVideoResponse()), - pageToken: videos.length > 0 ? videos[videos.length - 1].id : null + pageToken: videos.length > 0 ? videos[videos.length - 1].id : parseInt(request.query.pageToken as string) }; + response.json(videoListResponse); + return; }); diff --git a/src/api/v1/user.ts b/src/api/v1/user.ts index 199970f..fcf7247 100644 --- a/src/api/v1/user.ts +++ b/src/api/v1/user.ts @@ -90,9 +90,39 @@ router.put('/profile-image', async (request: express.Request, response: express. }); -router.get('/user-info', async (request: express.Request, response: express.Response) => { +router.get('/login-user-info', async (request: express.Request, response: express.Response) => { const userId = request.body.userInfo ? request.body.userInfo.userId : null; + + if(!userId){ + errorSend(response, 'require_body_parameter_userId', null); + return; + } + + const userInfo = await User.findByPk(userId); + + if(!userInfo){ + errorSend(response, 'no_user_found', 'No corresponding user for given token'); + return; + } + response.json({ + id: userInfo.id, + email: userInfo.email, + nickname: userInfo.nickname, + imagePath: userInfo.imagePath, + aboutMe: userInfo.aboutMe + }); + return; +}); + + +router.get('/user-info/:userId', async (request: express.Request, response: express.Response) => { + let userId = request.params.userId; + + if(userId == null){ + userId = request.body.userInfo ? request.body.userInfo.userId : null; + } + if(!userId){ errorSend(response, 'require_body_parameter_userId', null); return; diff --git a/src/api/v1/video.ts b/src/api/v1/video.ts index 80187c3..5131a86 100644 --- a/src/api/v1/video.ts +++ b/src/api/v1/video.ts @@ -80,11 +80,14 @@ router.get('/user-videos/:userId', async (request: express.Request, response: ex return; } + const videoListResponse: VideoListResponse = { videoList: videos.map((video) => video.toVideoResponse()), - pageToken: videos.length > 0 ? videos[videos.length - 1].id : null + pageToken: videos.length > 0 ? videos[videos.length - 1].id : parseInt(request.query.pageToken as string) }; + response.json(videoListResponse); + return; });