summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateus Cruz <mateuscolvr@gmail.com>2024-02-05 21:50:50 -0300
committerMateus Cruz <mateuscolvr@gmail.com>2024-02-05 21:50:50 -0300
commit00ade6066e9dd88c65b176bf4788eea4c3e1a15d (patch)
tree418c20c9edf2745bfcf38e44d9a5937ff0d382a5
parent81e194d07f6ddd653b8bef4d50ba454df41c2702 (diff)
fix: description length validation
-rw-r--r--lib/operation.ml6
-rw-r--r--script.sql2
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/operation.ml b/lib/operation.ml
index 3c8df2a..bce6ac2 100644
--- a/lib/operation.ml
+++ b/lib/operation.ml
@@ -49,5 +49,9 @@ let decoder : transaction_op Utils.Decoder.decoder =
(fun value transaction_type description -> transaction_type { value; description })
<$> ("valor" <: int)
<*> ("tipo" <: transaction_type_decoder)
- <*> ("descricao" <: string)
+ <*> ("descricao"
+ <: (string
+ >>= fun s ->
+ let len = String.length s in
+ if len <= 10 && len >= 1 then return s else fail))
;;
diff --git a/script.sql b/script.sql
index 9a2b3c2..a02895a 100644
--- a/script.sql
+++ b/script.sql
@@ -11,7 +11,7 @@ CREATE TABLE transactions (
client_id INTEGER REFERENCES clients,
value INTEGER NOT NULL,
type transaction_type NOT NULL,
- description VARCHAR(255) NOT NULL,
+ description VARCHAR(10) NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);