From 1354b59cb08925e8c42c677dd7155e1688aacd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Mon, 20 May 2019 17:02:39 +0200 Subject: [PATCH] decks/modify route --- backend/db.coffee | 6 ++-- backend/routes/decks/modify.coffee | 34 ++++++++++++++++++++ backend/server.coffee | 2 ++ frontend/src/components/forms/DeckEditor.vue | 23 +++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 backend/routes/decks/modify.coffee diff --git a/backend/db.coffee b/backend/db.coffee index 7d729e1..734770c 100644 --- a/backend/db.coffee +++ b/backend/db.coffee @@ -187,13 +187,15 @@ class FFTCGDB modDeck: (userID, deckID, deckCards) -> new Promise (resolve, reject) => stmt = @db.prepare 'UPDATE decks SET json = ? WHERE deck = ? AND user = ?' - stmt.run [JSON.stringify deckCards, deckID, userID], (err) -> + stmt.run [(JSON.stringify deckCards), deckID, userID], (err) -> stmt.finalize() if err logger.warn "modDeck: FAIL db '#{err.code}' for '#{deckID}'" reject messages.db + else if @changes == 0 + logger.warn "no changes for input (#{userID}, #{deckID}, #{JSON.stringify deckCards})!" + reject messages.db else - logger.debug "modDeck: OK '#{deckID}'" resolve deckID getDecks: (userID) -> diff --git a/backend/routes/decks/modify.coffee b/backend/routes/decks/modify.coffee new file mode 100644 index 0000000..9cb8009 --- /dev/null +++ b/backend/routes/decks/modify.coffee @@ -0,0 +1,34 @@ +logger = (require 'logging').default '/decks/modify' + +# session storage (volatile data) +session = (require '../../session') +# fftcg.db (persistent data) +fftcgdb = (require '../../db') + +module.exports = + url: '/decks/modify' + method: 'POST' + # schema: (require './modify.schema') + + handler: (request, reply) -> + session.check request.body.session ? "" + .then (userid) -> + # active session found, get associated user + fftcgdb.modDeck (userid), (request.body.deckID), (request.body.deckCards) + .then (deckID) -> + logger.info "OK user '#{userid}' modified 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 diff --git a/backend/server.coffee b/backend/server.coffee index 45a22bb..021ec57 100644 --- a/backend/server.coffee +++ b/backend/server.coffee @@ -22,6 +22,8 @@ fastify.route (require "./routes/#{route}") for route in [ 'user/register' # list decks 'decks/list' + # modify deck + 'decks/modify' ] # request logging diff --git a/frontend/src/components/forms/DeckEditor.vue b/frontend/src/components/forms/DeckEditor.vue index 4ef144e..69a1e99 100644 --- a/frontend/src/components/forms/DeckEditor.vue +++ b/frontend/src/components/forms/DeckEditor.vue @@ -42,6 +42,9 @@