diff options
author | Mateus Cruz <mateuscolvr@gmail.com> | 2024-02-06 01:47:46 -0300 |
---|---|---|
committer | Mateus Cruz <mateuscolvr@gmail.com> | 2024-02-06 01:47:46 -0300 |
commit | 7c92898c8f0adb4a6014ce5f434a7d862a0cdc57 (patch) | |
tree | 0694f18ef7b8b97b025aabbf3c77a464acc2f4e0 | |
parent | aae0f0595061ad32960541c532930be0e5af51f2 (diff) |
add transaction value constraint
-rw-r--r-- | lib/handler.ml | 1 | ||||
-rw-r--r-- | lib/operation.ml | 2 |
2 files changed, 2 insertions, 1 deletions
diff --git a/lib/handler.ml b/lib/handler.ml index 4babe6e..c02ed71 100644 --- a/lib/handler.ml +++ b/lib/handler.ml @@ -78,6 +78,7 @@ let get_balance client_id (db_pool : Query.pool) (_request : Request.t) = `Assoc [ "total", total; "data_extrato", date; "limite", limit ] in let t = + (* NOTE: Talvez isso aqui não seja uma boa ideia *) Result.fold ~ok:Fun.id ~error:(fun _ -> []) @@ Query.transactions client_id conn in diff --git a/lib/operation.ml b/lib/operation.ml index bce6ac2..54962fd 100644 --- a/lib/operation.ml +++ b/lib/operation.ml @@ -47,7 +47,7 @@ let decoder : transaction_op Utils.Decoder.decoder = <|> literal "d" *> return (fun p -> `Debit p) in (fun value transaction_type description -> transaction_type { value; description }) - <$> ("valor" <: int) + <$> ("valor" <: (int >>= fun x -> if x >= 0 then return x else fail)) <*> ("tipo" <: transaction_type_decoder) <*> ("descricao" <: (string |