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',