From 39be3507a2e49f98ecb6780b9d94464a11f0f281 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Fri, 7 Jun 2019 14:01:48 +0100 Subject: [PATCH] Include edit history in building data from API --- app/src/api/building.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/api/building.js b/app/src/api/building.js index a2569a92..97b47a93 100644 --- a/app/src/api/building.js +++ b/app/src/api/building.js @@ -79,12 +79,31 @@ function getBuildingById(id) { return db.one( 'SELECT * FROM buildings WHERE building_id = $1', [id] - ).catch(function (error) { + ).then((building) => { + return getBuildingEditHistory(id).then((edit_history) => { + building.edit_history = edit_history + return building + }) + }).catch(function (error) { console.error(error); return undefined; }); } +function getBuildingEditHistory(id) { + return db.manyOrNone( + `SELECT log_id as revision_id, forward_patch, reverse_patch, date_trunc('minute', log_timestamp), username + FROM logs, users + WHERE building_id = $1 AND logs.user_id = users.user_id`, + [id] + ).then((data) => { + return data + }).catch(function (error) { + console.error(error); + return [] + }); +} + function getBuildingLikeById(buildingId, userId) { return db.oneOrNone( 'SELECT true as like FROM building_user_likes WHERE building_id = $1 and user_id = $2 LIMIT 1',