30 lines
729 B
Gleam
30 lines
729 B
Gleam
import birl.{type Time}
|
|
import gleam/dynamic/decode.{type Decoder}
|
|
import gleam/option.{type Option}
|
|
import models/account_id.{type AccountId}
|
|
import utils/api
|
|
|
|
pub type Account {
|
|
Account(
|
|
id: AccountId,
|
|
email: Option(String),
|
|
token: Option(String),
|
|
created_at: Time,
|
|
)
|
|
}
|
|
|
|
pub fn decoder() -> Decoder(Account) {
|
|
use id <- decode.field("id", account_id.decoder())
|
|
use email <- decode.optional_field(
|
|
"email",
|
|
option.None,
|
|
decode.optional(decode.string),
|
|
)
|
|
use token <- decode.optional_field(
|
|
"token",
|
|
option.None,
|
|
decode.optional(decode.string),
|
|
)
|
|
use created_at <- decode.field("createdAt", api.time_decoder())
|
|
decode.success(Account(id:, email:, token:, created_at:))
|
|
}
|