mentorenwahl/backend/src/backend/api/schema/token.cr

35 lines
658 B
Crystal

module Backend::Api::Schema
@[GraphQL::Object]
# Token model
class Token < GraphQL::BaseObject
include Helpers
def initialize(@model : Db::Token)
end
@[GraphQL::Field]
# Token ID / JTI
def id : Scalars::UUID
Scalars::UUID.new(@model.id)
end
@[GraphQL::Field]
# Time the token was issued at
def iat : Scalars::Time
Scalars::Time.new(@model.iat)
end
@[GraphQL::Field]
# Time for the token to expire
def exp : Scalars::Time
Scalars::Time.new(@model.exp)
end
@[GraphQL::Field]
# Token is expired
def expired : Bool
@model.exp > Time.utc
end
end
end