35 lines
952 B
CoffeeScript
35 lines
952 B
CoffeeScript
|
logger = (require 'logging').default '/decks/delete'
|
||
|
|
||
|
# session storage (volatile data)
|
||
|
session = (require '../../session')
|
||
|
# fftcg.db (persistent data)
|
||
|
fftcgdb = (require '../../db')
|
||
|
|
||
|
module.exports =
|
||
|
url: '/decks/delete'
|
||
|
method: 'POST'
|
||
|
# schema: (require './modify.schema')
|
||
|
|
||
|
handler: (request, reply) ->
|
||
|
session.check request.body.session ? ""
|
||
|
.then (userid) ->
|
||
|
# active session found, get associated user
|
||
|
fftcgdb.delDeck (userid), (request.body.deckID)
|
||
|
.then (deckID) ->
|
||
|
logger.info "OK user '#{userid}' deleted deck '#{deckID}'"
|
||
|
reply.send
|
||
|
success: true
|
||
|
deck: deckID
|
||
|
|
||
|
.catch (err) ->
|
||
|
# couldnt get user details
|
||
|
logger.warn "FAIL '#{err}' for user id '#{userid}'"
|
||
|
reply.send
|
||
|
success: false
|
||
|
|
||
|
.catch ->
|
||
|
# no session found
|
||
|
logger.info "FAIL '#{request.body.session}' session not found"
|
||
|
reply.send
|
||
|
success: false
|