2022-12-19 13:23:13 +01:00
|
|
|
import {pStations} from '../lib/db-stations.js'
|
2020-05-01 18:10:21 +02:00
|
|
|
|
|
|
|
const err404 = (msg) => {
|
|
|
|
const err = new Error(msg)
|
|
|
|
err.statusCode = 404
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const stationRoute = (req, res, next) => {
|
|
|
|
const id = req.params.id.trim()
|
|
|
|
|
|
|
|
pStations
|
|
|
|
.then(({data, timeModified}) => {
|
|
|
|
const station = data[id]
|
|
|
|
if (!station) {
|
|
|
|
next(err404('Station not found.'))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res.setHeader('Last-Modified', timeModified.toUTCString())
|
|
|
|
res.json(station)
|
|
|
|
})
|
|
|
|
.catch(next)
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:24:13 +01:00
|
|
|
stationRoute.openapiPaths = {
|
|
|
|
'/stations/{id}': {
|
|
|
|
get: {
|
|
|
|
summary: 'Returns a stop/station from `db-stations`.',
|
|
|
|
description: `\
|
2022-11-22 15:38:58 +01:00
|
|
|
Returns a stop/station from [\`db-stations@3\`](https://github.com/derhuerst/db-stations/tree/3.0.1).`,
|
2021-02-04 19:24:13 +01:00
|
|
|
parameters: [{
|
|
|
|
name: 'id',
|
|
|
|
in: 'path',
|
|
|
|
description: 'Stop/station ID.',
|
|
|
|
required: true,
|
|
|
|
schema: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
responses: {
|
|
|
|
'2XX': {
|
2022-11-22 15:38:58 +01:00
|
|
|
description: 'A stop/station, in the [`db-stations@3` format](https://github.com/derhuerst/db-stations/blob/3.0.1/readme.md).',
|
2021-02-04 19:24:13 +01:00
|
|
|
content: {
|
|
|
|
'application/json': {
|
|
|
|
schema: {
|
|
|
|
type: 'object', // todo
|
|
|
|
},
|
|
|
|
// todo: example(s)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-19 13:07:00 +01:00
|
|
|
// todo: non-2xx response
|
2021-02-04 19:24:13 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-12-19 13:23:13 +01:00
|
|
|
export {
|
|
|
|
stationRoute as route,
|
|
|
|
}
|