summaryrefslogtreecommitdiff
path: root/lib/serializer.ml
blob: 102476708b019f3d97a271e58e145181c683b05b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
let transaction (t : Operation.transaction) =
  let transaction_type =
    match t.transaction_type with
    | `Credit -> "c"
    | `Debit -> "d"
  in
  let value = "valor", `Int t.value in
  let transaction_type = "tipo", `String transaction_type in
  let description = "descricao", `String t.description in
  let created_at =
    let formatted_date =
      Format.asprintf "%a" (Ptime.pp_rfc3339 ~tz_offset_s:(-10800) ()) t.created_at
    in
    "realizada_em", `String formatted_date
  in
  `Assoc [ value; transaction_type; description; created_at ]
;;

let bank_statement time client transactions =
  let date =
    `String (Format.asprintf "%a" (Ptime.pp_rfc3339 ~tz_offset_s:(-10800) ()) time)
  in
  let limit = `Int client.Operation.mov_limit in
  let total = `Int client.balance in
  let balance = `Assoc [ "total", total; "data_extrato", date; "limite", limit ] in
  let last_transactions = `List (List.map transaction transactions) in
  `Assoc [ "saldo", balance; "ultimas_transacoes", last_transactions ]
;;