From 9d1e790a0dbefde26b20406f27cf2abebba9eef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Fri, 10 May 2019 14:09:49 +0200 Subject: [PATCH] /decks/list route (schema missing) --- backend/db.coffee | 4 ++-- backend/routes/decks/list.coffee | 34 ++++++++++++++++++++++++++++++++ backend/server.coffee | 2 ++ frontend/src/views/UserCP.vue | 19 +++++++++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 backend/routes/decks/list.coffee diff --git a/backend/db.coffee b/backend/db.coffee index f1cbbb3..d4debdf 100644 --- a/backend/db.coffee +++ b/backend/db.coffee @@ -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) -> diff --git a/backend/routes/decks/list.coffee b/backend/routes/decks/list.coffee new file mode 100644 index 0000000..ecdae02 --- /dev/null +++ b/backend/routes/decks/list.coffee @@ -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 diff --git a/backend/server.coffee b/backend/server.coffee index f3c1ab1..45a22bb 100644 --- a/backend/server.coffee +++ b/backend/server.coffee @@ -20,6 +20,8 @@ fastify.route (require "./routes/#{route}") for route in [ 'user/logout' # register user 'user/register' + # list decks + 'decks/list' ] # request logging diff --git a/frontend/src/views/UserCP.vue b/frontend/src/views/UserCP.vue index c763cc0..ce9df24 100644 --- a/frontend/src/views/UserCP.vue +++ b/frontend/src/views/UserCP.vue @@ -3,6 +3,13 @@

user logged in: {{ user.login }}

+ + + Logout @@ -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 + } + }) } }