Add edit history route/controller

This commit is contained in:
Maciej Ziarkowski 2019-10-21 16:29:44 +01:00
parent c63f42f921
commit aa59067d9e
3 changed files with 19 additions and 3 deletions

View File

@ -110,6 +110,17 @@ const getBuildingLikeById = asyncController(async (req: express.Request, res: ex
}
});
const getBuildingEditHistoryById = asyncController(async (req: express.Request, res: express.Response) => {
const { building_id } = req.params;
try {
const editHistory = await buildingService.getBuildingEditHistory(building_id);
res.send({ history: editHistory });
} catch(error) {
res.send({ error: 'Database error' });
}
});
const updateBuildingLikeById = asyncController(async (req: express.Request, res: express.Response) => {
if (!req.session.user_id) {
return res.send({ error: 'Must be logged in' });
@ -142,5 +153,6 @@ export default {
updateBuildingById,
getBuildingUPRNsById,
getBuildingLikeById,
updateBuildingLikeById
};
updateBuildingLikeById,
getBuildingEditHistoryById
};

View File

@ -29,4 +29,7 @@ router.route('/:building_id/like.json')
.get(buildingController.getBuildingLikeById)
.post(buildingController.updateBuildingLikeById);
export default router;
router.route('/:building_id/history.json')
.get(buildingController.getBuildingEditHistoryById);
export default router;

View File

@ -409,6 +409,7 @@ export {
queryBuildingsByReference,
getBuildingById,
getBuildingLikeById,
getBuildingEditHistory,
getBuildingUPRNsById,
saveBuilding,
likeBuilding,