logger = (require 'logging').default '/decks/list'
# session storage (volatile data)
session = (require '../../session')
# fftcg.db (persistent data)
fftcgdb = (require '../../db')
module.exports =
url: '/decks/list'
method: 'POST'
# schema: (require './info.schema')
handler: (request, reply) ->
session.check request.body.session ? ""
.then (userid) ->
# active session found, get associated user
fftcgdb.getDecks (userid)
.then (decks) ->
logger.debug "OK '#{userid}' got decks"
reply.send
success: true
decks: decks
.catch (err) ->
# couldnt get user details
logger.warn "FAIL '#{err}' for user id '#{userid}'"
success: false
.catch ->
# no session found
logger.info "FAIL '#{request.body.session}' session not found"