-
Notifications
You must be signed in to change notification settings - Fork 1
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
tomCollinson
wants to merge
2
commits into
medicaltracker:main
Choose a base branch
from
tomCollinson:feature/submission
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"cities": { | ||
"2641170": { | ||
"coord": { | ||
"lon": -1.1505, | ||
"lat": 52.9536 | ||
}, | ||
"weather": [ | ||
{ | ||
"id": 803, | ||
"main": "Clouds", | ||
"description": "broken clouds", | ||
"icon": "04d" | ||
} | ||
], | ||
"base": "stations", | ||
"main": { | ||
"temp": 286.18, | ||
"feels_like": 285.55, | ||
"temp_min": 284.38, | ||
"temp_max": 287.42, | ||
"pressure": 1018, | ||
"humidity": 77 | ||
}, | ||
"visibility": 10000, | ||
"wind": { | ||
"speed": 3.6, | ||
"deg": 220 | ||
}, | ||
"clouds": { | ||
"all": 75 | ||
}, | ||
"dt": 1716543390, | ||
"sys": { | ||
"type": 2, | ||
"id": 2093695, | ||
"country": "GB", | ||
"sunrise": 1716522812, | ||
"sunset": 1716581384 | ||
}, | ||
"timezone": 3600, | ||
"id": 2641170, | ||
"name": "Nottingham", | ||
"cod": 200 | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const express = require('express'); | ||
const logger = require('morgan'); | ||
|
||
const citiesRouter = require('./routes/index'); | ||
const { notFoundHandler, errorHandler } = require('./errorHandler'); | ||
|
||
const app = express(); | ||
// Middleware setup | ||
app.use(logger('dev')); | ||
app.use(express.json()); | ||
|
||
// Routes | ||
app.use('/api', citiesRouter); | ||
|
||
// Catch 404 and forward to error handler | ||
app.use(notFoundHandler); | ||
|
||
// Error handler | ||
app.use(errorHandler); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var app = require('../app'); | ||
var debug = require('debug')('server:server'); | ||
var http = require('http'); | ||
|
||
/** | ||
* Get port from environment and store in Express. | ||
*/ | ||
|
||
var port = normalizePort(process.env.PORT || '3000'); | ||
app.set('port', port); | ||
|
||
/** | ||
* Create HTTP server. | ||
*/ | ||
|
||
var server = http.createServer(app); | ||
|
||
/** | ||
* Listen on provided port, on all network interfaces. | ||
*/ | ||
|
||
server.listen(port); | ||
server.on('error', onError); | ||
server.on('listening', onListening); | ||
|
||
/** | ||
* Normalize a port into a number, string, or false. | ||
*/ | ||
|
||
function normalizePort(val) { | ||
var port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
// named pipe | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
// port number | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "error" event. | ||
*/ | ||
|
||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === 'string' | ||
? 'Pipe ' + port | ||
: 'Port ' + port; | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
console.error(bind + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error(bind + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "listening" event. | ||
*/ | ||
|
||
function onListening() { | ||
var addr = server.address(); | ||
var bind = typeof addr === 'string' | ||
? 'pipe ' + addr | ||
: 'port ' + addr.port; | ||
debug('Listening on ' + bind); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"cities": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const createError = require('http-errors'); | ||
|
||
const notFoundHandler = (req, res, next) => { | ||
next(createError(404)); | ||
}; | ||
|
||
const errorHandler = (err, req, res, next) => { | ||
// Set locals, only providing error in development | ||
res.locals.message = err.message; | ||
res.locals.error = req.app.get('env') === 'development' ? err : {}; | ||
|
||
// Render the error page | ||
res.status(err.status || 500); | ||
res.send(err.message); | ||
}; | ||
|
||
module.exports = { | ||
notFoundHandler, | ||
errorHandler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
preset: '@babel/preset-env', | ||
testEnvironment: 'node', | ||
testMatch: ["**/__tests__/**/*.test.js"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Middleware to load data | ||
const { readDataFromFile} = require('../utils/files.js'); | ||
|
||
async function loadData(req, res, next) { | ||
try { | ||
req.data = await readDataFromFile(); | ||
next(); | ||
} catch (error) { | ||
res.status(500).send('Failed to read data from file'); | ||
} | ||
} | ||
|
||
module.exports = loadData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Middleware to save data | ||
const { writeDataToFile } = require('../utils/files.js'); | ||
|
||
async function saveData(req, res, next) { | ||
try { | ||
await writeDataToFile(req.data); | ||
next(); | ||
} catch (error) { | ||
res.status(500).send('Failed to write data to file'); | ||
} | ||
} | ||
|
||
module.exports = saveData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function validateCityId(req, res, next) { | ||
const cityId = req.params.id || req.query.id; | ||
if (!cityId) { | ||
return res.status(400).send('City ID is required'); | ||
} | ||
req.cityId = cityId; | ||
next(); | ||
} | ||
|
||
module.exports = validateCityId; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
?