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

Feature/submission #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tomCollinson
Copy link

Final submission for the Medical Tracker test.

All endpoints have been implemented and a test created for each.

Increased test coverage would be something to add in future given more time but all routes have coverage.

Copy link
Contributor

@philp philp left a comment

Choose a reason for hiding this comment

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

Thanks for this. Most of my comments are just for my understanding, or about stylistic choices.

Good, readable code. I could clearly understand what each module/function is doing, and I hvae a high-level of confidence that this will work, without having to install and start it.

* Module dependencies.
*/

var app = require('../app');
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of var in this file makes me think it is copy/pasted boilerplate 😉. I have no problem with that, and appreciate that this is supposed to be a quick. But just for info: I would usually be asking for this to be changed, before reviewing the rest of the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

That said: since this is intended to be a bin file: you could have a good reason to use var?

const saveData = require('../middleware/saveData.js')

// Route to add a new city
router.post('/cities', validateCityId, loadData, async (req, res, next) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I really like the way that you've composed middleware in your routes — really good separation of concerns, and makes it very readable.

return response.data;
} catch (error) {
console.error('Error fetching weather data from API:', error);
throw new Error('Failed to fetch weather data');
Copy link
Contributor

Choose a reason for hiding this comment

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

Good. Let middleware handle this.

req.data.cities[cityId] = cityWeatherData;
next();
} catch (error) {
res.status(500).send(error.message);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to understand why errors are being handled in individual routes, rather than letting middleware catch them. From what I recall, Express allows you to call next(error) and it will take care of any issues with asynchronsity?

// Utility function to read data from file
function readDataFromFile() {
try {
const data = fs.readFileSync(datastore, 'utf8');
Copy link
Contributor

Choose a reason for hiding this comment

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

I might be able to learn something here: are there advantages to using the blocking versions of readFileSync and writeFileSync over the standard async readFile and writeFlie?

const data = fs.readFileSync(datastore, 'utf8');
return JSON.parse(data);
} catch (error) {
console.error('Error reading data from file:', error);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not saying this is wrong, but interested to know reasons for letting this function fail silently, rather than just letting it throw?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants