Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix #96: Add ability to retrieve timing history #132

Merged

Conversation

jossperdomo
Copy link
Collaborator

Fix #96

Description:

  • Added endpoint to get last 3 timing giving the questionNo and userId.
  • Integrated endpoint to UI.
  • Refactored history.js

Copy link
Collaborator

@vegetabill vegetabill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! It worked perfectly for me locally. I just added a few suggested revisions and it's ready to merge.

routes/routes.js Outdated
Comment on lines 44 to 46
User.findOne({
where: {id: req.query.userId}
}).then(user => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually don't need to fetch the user in this case, you can just skip right to the second query.

routes/routes.js Outdated
Comment on lines 55 to 57
return res.status(200).json({
previousTimingMs: userAnswers.map(userAnswer => userAnswer.elapsed_time_ms)
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since 200 is the default response code, you don't need to specify it unless the code would be confusing otherwise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes (when I skip typing the answer) it returns 304.

routes/routes.js Outdated
})
}).catch(error => {
console.log(error);
return res.status(400).json(error.errors) // TODO: handle better error messages
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't know what the cause of the error was, we should probably use code 500 as it could be a bug on the server.

Comment on lines 6 to 9
let params = {
userId: 'guest' // TODO: get actual userId
}
url.search = new URLSearchParams(params).toString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server will know the user id of the user making the API request so you don't have to include it explicitly here, but will have to so the query works on the server so the TODO can go there.

routes/routes.js Outdated
@@ -38,5 +38,31 @@ router.post('/user/answers/question/:questionNumber', (req, res) => {
})
})

router.get('/user/answers/question/:questionNumber', (req, res) => {
let pageSize = 3; // TODO: define it in more stadarized way
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a uppercase constant in the file in case any other routes need it.

Not sure the best name to use, maybe ANSWER_HISTORY_LIMIT ?

@jossperdomo
Copy link
Collaborator Author

@vegetabill My latest commit fixes all the comments you left 😊

Copy link
Collaborator

@vegetabill vegetabill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noted one revision you missed but everything else looks great. It's nearly ready to merge!

Comment on lines 6 to 9
let params = {
userId: 'guest'
}
url.search = new URLSearchParams(params).toString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed this suggested revision. Let's move this to the server, which is where the real logic will be.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I forgot to add it because I didn't understand very well. After this comment, I got it and updated the PR

Copy link
Collaborator

@vegetabill vegetabill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM let's merge it @alodahl

@vegetabill vegetabill merged commit 0d29991 into Techtonica:backend Oct 21, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to retrieve timing history for a single question
2 participants