From a0fadf931003f91dc0cb3531408c6df2037d1f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Tue, 29 Oct 2024 14:58:27 +0100 Subject: [PATCH] fix: handle no results on get votes query --- govtool/backend/src/VVA/DRep.hs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/govtool/backend/src/VVA/DRep.hs b/govtool/backend/src/VVA/DRep.hs index 98c05ae5..730814e4 100644 --- a/govtool/backend/src/VVA/DRep.hs +++ b/govtool/backend/src/VVA/DRep.hs @@ -107,17 +107,23 @@ getVotes :: m ([Vote], [Proposal]) getVotes drepId selectedProposals = withPool $ \conn -> do results <- liftIO $ SQL.query conn getVotesSql (SQL.Only drepId) - let proposalsToSelect = if null selectedProposals - then [ govActionId | (_, govActionId, _, _, _, _, _, _, _) <- results] - else selectedProposals - proposals <- Proposal.getProposals (Just proposalsToSelect) - let proposalMap = M.fromList $ map (\x -> (proposalId x, x)) proposals - timeZone <- liftIO getCurrentTimeZone - return - ([ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash' - | (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results - , govActionId' `elem` proposalsToSelect - ], proposals) + + if null results + then return ([], []) + else do + let proposalsToSelect = if null selectedProposals + then [ govActionId | (_, govActionId, _, _, _, _, _, _, _) <- results] + else selectedProposals + proposals <- if null proposalsToSelect + then return [] + else Proposal.getProposals (Just proposalsToSelect) + let proposalMap = M.fromList $ map (\x -> (proposalId x, x)) proposals + timeZone <- liftIO getCurrentTimeZone + let votes = [ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash' + | (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results + , govActionId' `elem` proposalsToSelect + ] + return (votes, proposals) getDRepInfoSql :: SQL.Query getDRepInfoSql = sqlFrom $(embedFile "sql/get-drep-info.sql")