/decks/list route (schema missing)

This commit is contained in:
Jörn-Michael Miehe 2019-05-10 14:09:49 +02:00
parent 6dcb5a4963
commit 9d1e790a0d
4 changed files with 56 additions and 3 deletions

View file

@ -199,10 +199,10 @@ class FFTCGDB
stmt.all [user], (err, rows) -> stmt.all [user], (err, rows) ->
stmt.finalize() stmt.finalize()
if err if err
logger.warn "getDeck: FAIL db '#{err.code}' for '#{deckID}'" logger.warn "getDeck: FAIL db '#{err.code}' for '#{user}'"
reject messages.db reject messages.db
else else
logger.debug "getDeck: OK '#{deckID}'" logger.debug "getDeck: OK '#{user}'"
resolve (id: row.deck, content: JSON.parse row.json for row, i in rows) resolve (id: row.deck, content: JSON.parse row.json for row, i in rows)
delDeck: (deckID) -> delDeck: (deckID) ->

View file

@ -0,0 +1,34 @@
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
deck: decks
.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

View file

@ -20,6 +20,8 @@ fastify.route (require "./routes/#{route}") for route in [
'user/logout' 'user/logout'
# register user # register user
'user/register' 'user/register'
# list decks
'decks/list'
] ]
# request logging # request logging

View file

@ -3,6 +3,13 @@
<Header /> <Header />
<p>user logged in: {{ user.login }}</p> <p>user logged in: {{ user.login }}</p>
<ul>
<li v-for="deck in decks" :key="deck.id">
{{ deck.id }}: {{ deck.content.name }}
</li>
</ul>
<v-btn @click.native="logout">Logout</v-btn> <v-btn @click.native="logout">Logout</v-btn>
</v-container> </v-container>
</template> </template>
@ -21,7 +28,8 @@ export default {
}, },
data: () => ({ data: () => ({
user: '' user: '',
decks: ''
}), }),
methods: { methods: {
@ -55,6 +63,15 @@ export default {
this.goHome() this.goHome()
} }
}) })
axios
.post('/decks/list', {
session: Cookies.get('session')
})
.then(response => {
if (response.data.success) {
this.decks = response.data.deck
}
})
} }
} }
</script> </script>