Revised fix for issue #216 Reduce log noise (my previous attempt was incorrect). Switched to db.oneOrNone

This commit is contained in:
Martin-dJ 2019-03-14 17:02:26 +00:00
parent c83f2bc0c2
commit 29f3bff0d5

View File

@ -84,19 +84,14 @@ function getBuildingById(id) {
} }
function getBuildingLikeById(building_id, user_id) { function getBuildingLikeById(building_id, user_id) {
return db.one( return db.oneOrNone(
"SELECT true as like FROM building_user_likes WHERE building_id = $1 and user_id = $2 LIMIT 1", "SELECT true as like FROM building_user_likes WHERE building_id = $1 and user_id = $2 LIMIT 1",
[building_id, user_id] [building_id, user_id]
).then(res => { ).then(res => {
return res && res.like return res && res.like
}).catch(function (error) { }).catch(function (error) {
if (error instanceof pgp.errors.QueryResultError && error.message.includes("No data returned from the query")) {
// user hasn't liked building yet
return { error: 'It looks like you have not liked this building yet!' };
} else {
return undefined
console.error(error); console.error(error);
} return undefined;
}); });
} }