/decks/list route (schema missing)
This commit is contained in:
parent
6dcb5a4963
commit
9d1e790a0d
4 changed files with 56 additions and 3 deletions
|
@ -199,10 +199,10 @@ class FFTCGDB
|
|||
stmt.all [user], (err, rows) ->
|
||||
stmt.finalize()
|
||||
if err
|
||||
logger.warn "getDeck: FAIL db '#{err.code}' for '#{deckID}'"
|
||||
logger.warn "getDeck: FAIL db '#{err.code}' for '#{user}'"
|
||||
reject messages.db
|
||||
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)
|
||||
|
||||
delDeck: (deckID) ->
|
||||
|
|
34
backend/routes/decks/list.coffee
Normal file
34
backend/routes/decks/list.coffee
Normal 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
|
|
@ -20,6 +20,8 @@ fastify.route (require "./routes/#{route}") for route in [
|
|||
'user/logout'
|
||||
# register user
|
||||
'user/register'
|
||||
# list decks
|
||||
'decks/list'
|
||||
]
|
||||
|
||||
# request logging
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
<Header />
|
||||
|
||||
<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-container>
|
||||
</template>
|
||||
|
@ -21,7 +28,8 @@ export default {
|
|||
},
|
||||
|
||||
data: () => ({
|
||||
user: ''
|
||||
user: '',
|
||||
decks: ''
|
||||
}),
|
||||
|
||||
methods: {
|
||||
|
@ -55,6 +63,15 @@ export default {
|
|||
this.goHome()
|
||||
}
|
||||
})
|
||||
axios
|
||||
.post('/decks/list', {
|
||||
session: Cookies.get('session')
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.decks = response.data.deck
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Reference in a new issue