diff --git a/app/src/api/controllers/buildingController.ts b/app/src/api/controllers/buildingController.ts index 269ea7b1..3993b619 100644 --- a/app/src/api/controllers/buildingController.ts +++ b/app/src/api/controllers/buildingController.ts @@ -1,5 +1,6 @@ import express from 'express'; +import { parseIntParam } from '../helpers'; import asyncController from '../routes/asyncController'; import * as buildingService from '../services/building'; import * as userService from '../services/user'; @@ -34,9 +35,10 @@ const getBuildingsByReference = asyncController(async (req: express.Request, res // GET individual building, POST building updates const getBuildingById = asyncController(async (req: express.Request, res: express.Response) => { - const { building_id } = req.params; + const buildingId = parseIntParam(req.params.building_id); + try { - const result = await buildingService.getBuildingById(building_id); + const result = await buildingService.getBuildingById(buildingId); res.send(result); } catch(error) { console.error(error); @@ -61,11 +63,12 @@ const updateBuildingById = asyncController(async (req: express.Request, res: exp }); async function updateBuilding(req: express.Request, res: express.Response, userId: string) { - const { building_id } = req.params; + const buildingId = parseIntParam(req.params.building_id); + const buildingUpdate = req.body; try { - const building = await buildingService.saveBuilding(building_id, buildingUpdate, userId); + const building = await buildingService.saveBuilding(buildingId, buildingUpdate, userId); if (typeof (building) === 'undefined') { return res.send({ error: 'Database error' }); @@ -81,9 +84,10 @@ async function updateBuilding(req: express.Request, res: express.Response, userI // GET building UPRNs const getBuildingUPRNsById = asyncController(async (req: express.Request, res: express.Response) => { - const { building_id } = req.params; + const buildingId = parseIntParam(req.params.building_id); + try { - const result = await buildingService.getBuildingUPRNsById(building_id); + const result = await buildingService.getBuildingUPRNsById(buildingId); if (typeof (result) === 'undefined') { return res.send({ error: 'Database error' }); @@ -100,9 +104,11 @@ const getBuildingLikeById = asyncController(async (req: express.Request, res: ex if (!req.session.user_id) { return res.send({ like: false }); // not logged in, so cannot have liked } - const { building_id } = req.params; + + const buildingId = parseIntParam(req.params.building_id); + try { - const like = await buildingService.getBuildingLikeById(building_id, req.session.user_id); + const like = await buildingService.getBuildingLikeById(buildingId, req.session.user_id); // any value returned means like res.send({ like: like }); @@ -112,9 +118,10 @@ const getBuildingLikeById = asyncController(async (req: express.Request, res: ex }); const getBuildingEditHistoryById = asyncController(async (req: express.Request, res: express.Response) => { - const { building_id } = req.params; + const buildingId = parseIntParam(req.params.building_id); + try { - const editHistory = await buildingService.getBuildingEditHistory(building_id); + const editHistory = await buildingService.getBuildingEditHistory(buildingId); res.send({ history: editHistory }); } catch(error) { @@ -127,13 +134,13 @@ const updateBuildingLikeById = asyncController(async (req: express.Request, res: return res.send({ error: 'Must be logged in' }); } - const { building_id } = req.params; + const buildingId = parseIntParam(req.params.building_id); const { like } = req.body; try { const building = like ? - await buildingService.likeBuilding(building_id, req.session.user_id) : - await buildingService.unlikeBuilding(building_id, req.session.user_id); + await buildingService.likeBuilding(buildingId, req.session.user_id) : + await buildingService.unlikeBuilding(buildingId, req.session.user_id); if (building.error) { return res.send(building); diff --git a/app/src/api/controllers/extractController.ts b/app/src/api/controllers/extractController.ts index 183c23d8..369459be 100644 --- a/app/src/api/controllers/extractController.ts +++ b/app/src/api/controllers/extractController.ts @@ -1,5 +1,6 @@ import express from 'express'; +import { parseIntParam } from '../helpers'; import asyncController from '../routes/asyncController'; import * as dataExtractService from '../services/dataExtract'; @@ -15,7 +16,7 @@ const getAllDataExtracts = asyncController(async function(req: express.Request, const getDataExtract = asyncController(async function(req: express.Request, res: express.Response) { try { - const extractId = req.params.extract_id; + const extractId = parseIntParam(req.params.extract_id); const extract = await dataExtractService.getDataExtractById(extractId); res.send({ extract: extract }); } catch (err) { diff --git a/app/src/api/helpers.ts b/app/src/api/helpers.ts new file mode 100644 index 00000000..4028248c --- /dev/null +++ b/app/src/api/helpers.ts @@ -0,0 +1,9 @@ +import { strictParseInt } from '../parse'; + +export function parseIntParam(param: string) { + const result = strictParseInt(param); + if (isNaN(result)) { + throw new Error('Invalid parameter format: not an integer'); + } + return result; +} diff --git a/app/src/frontend/pages/welcome.tsx b/app/src/frontend/pages/welcome.tsx index d031e141..d363dde1 100644 --- a/app/src/frontend/pages/welcome.tsx +++ b/app/src/frontend/pages/welcome.tsx @@ -6,13 +6,11 @@ import './welcome.css'; const Welcome = () => (

Welcome to Colouring London

-

- Colouring London is a knowledge exchange platform collecting information on every - building in London, to help make the city more sustainable. We're developing it at University College London. Can you help us? We're looking for volunteers of all ages and abilities to help test the site and colour the buildings in. + Colouring London is a knowledge exchange platform set up by University College London to help make the city more sustainable. It provides open statistical data on the characteristics of the city's buildings and on the dynamic behaviour of the stock. We're working to collate, collect, generate, verify over fifty types of data and to visualise many of these datasets.

- Our building data comes from many different sources. Though we are unable to vouch for their accuracy, we are currently experimenting with a range of features including 'data source', 'edit history', and 'entry verification', to assist you in checking reliability and judging how suitable the data are for your intended use. + Our information comes from many different sources. As we are unable to vouch for data accuracy, we are currently experimenting with a range of features including 'data source', 'edit history', and 'entry verification', to assist you in checking reliability and judging how suitable the data are for your intended use. Your help in checking and adding data is very much appreciated.

All data we collect are made openly available. We just ask you to credit Colouring London and read our data ethics policy when using or sharing our data, maps or code.