From c1679a0c35520ababe9fce36cbe5c4b7dcedf9e5 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Thu, 12 Aug 2021 21:11:52 +0100 Subject: [PATCH] Handle likes database count as integer --- app/src/api/dataAccess/like.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/api/dataAccess/like.ts b/app/src/api/dataAccess/like.ts index a9b91174..bb386125 100644 --- a/app/src/api/dataAccess/like.ts +++ b/app/src/api/dataAccess/like.ts @@ -5,8 +5,10 @@ import { DatabaseError, InvalidOperationError } from '../errors/general'; export async function getBuildingLikeCount(buildingId: number, t?: ITask): Promise { try { + // assume that there won't be more likes than Postgres int range and cast to int + // otherwise the count is return as a bigint which has less support in noode-postgres const result = await (t || db).one( - 'SELECT count(*) as likes FROM building_user_likes WHERE building_id = $1;', + 'SELECT count(*)::int as likes FROM building_user_likes WHERE building_id = $1;', [buildingId] );