Merge branch 'develop' into feature/api-helpers
This commit is contained in:
commit
00c77bfca7
@ -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);
|
||||
|
@ -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) {
|
||||
|
9
app/src/api/helpers.ts
Normal file
9
app/src/api/helpers.ts
Normal file
@ -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;
|
||||
}
|
@ -6,13 +6,11 @@ import './welcome.css';
|
||||
const Welcome = () => (
|
||||
<div className="jumbotron welcome-float">
|
||||
<h1 className="h1">Welcome to Colouring London</h1>
|
||||
|
||||
<p className="lead">
|
||||
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.
|
||||
</p>
|
||||
<p className="lead">
|
||||
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.
|
||||
</p>
|
||||
<p className="lead">
|
||||
All data we collect are made <Link to="/data-extracts.html">openly available</Link>. We just ask you to credit Colouring London and read our <a href="https://www.pages.colouring.london/data-ethics">data ethics policy</a> when using or sharing our data, maps or <a href="https://github.com/tomalrussell/colouring-london">code</a>.
|
||||
|
Loading…
Reference in New Issue
Block a user