Reduces conde duplication assimbling response vody for RPC

This commit is contained in:
Diogo Biazus
2015-10-18 20:02:33 -04:00
parent 8b5f4e8556
commit f56efeb039
+4 -3
View File
@@ -176,9 +176,10 @@ app dbstructure conf reqBody req =
asJson (callProc qi $ fromMaybe M.empty (decode reqBody))
bodyJson :: Maybe (Identity Value) <- H.maybeEx call
return $ responseLBS status200 [jsonH]
(if hasPrefer "return=jwt"
then ("{\"token\":\"" <> (cs $ tokenJWT jwtSecret $ fromMaybe "[]" $ runIdentity <$> bodyJson) <> "\"}")
else (cs $ encode $ fromMaybe emptyArray $ runIdentity <$> bodyJson))
(let body = fromMaybe emptyArray $ runIdentity <$> bodyJson in
if hasPrefer "return=jwt"
then ("{\"token\":\"" <> (cs $ tokenJWT jwtSecret $ body) <> "\"}")
else (cs $ encode $ body))
else return $ responseLBS status404 [] ""
-- check that proc exists