From 7c92898c8f0adb4a6014ce5f434a7d862a0cdc57 Mon Sep 17 00:00:00 2001 From: Mateus Cruz Date: Tue, 6 Feb 2024 01:47:46 -0300 Subject: add transaction value constraint --- lib/handler.ml | 1 + lib/operation.ml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.3