Delete deck

This commit is contained in:
Jörn-Michael Miehe 2019-05-24 13:41:48 +02:00
parent 0475e45275
commit 9616a2fe97
4 changed files with 88 additions and 4 deletions

View file

@ -210,10 +210,10 @@ class FFTCGDB
logger.debug "getDecks: OK '#{userID}'"
resolve (id: row.deck, content: JSON.parse row.json for row, i in rows)
delDeck: (deckID) ->
delDeck: (userID, deckID) ->
new Promise (resolve, reject) =>
stmt = @db.prepare 'DELETE FROM decks WHERE deck = ?'
stmt.run [deckID], (err) ->
stmt = @db.prepare 'DELETE FROM decks WHERE deck = ? AND user = ?'
stmt.run [deckID, userID], (err) ->
stmt.finalize()
if err
logger.warn "delDeck: FAIL db '#{err.code}' for '#{deckID}'"

View file

@ -0,0 +1,34 @@
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

View file

@ -26,6 +26,8 @@ fastify.route (require "./routes/#{route}") for route in [
'decks/add'
# modify deck
'decks/modify'
# delete deck
'decks/delete'
]
# request logging

View file

@ -28,6 +28,40 @@
<v-btn fab absolute bottom right @click.native="editing = true">
<v-icon>edit</v-icon>
</v-btn>
<v-dialog v-model="deleting" persistent>
<v-btn fab absolute bottom left slot="activator">
<v-icon>delete</v-icon>
</v-btn>
<v-card>
<v-card-title class="headline">
Really delete this deck?
</v-card-title>
<v-card-text>
Are you sure you want to delete this deck? This cannot be undone.
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="error" @click.native="deleting = false">
Cancel
</v-btn>
<v-btn
color="success"
@click.native="
deleting = false
delete_deck()
"
>
Confirm
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-layout>
</v-container>
@ -60,7 +94,8 @@ export default {
},
data: () => ({
editing: false
editing: false,
deleting: false
}),
computed: {
@ -81,6 +116,19 @@ export default {
this.$emit('change')
}
})
},
delete_deck() {
axios
.post('/decks/delete', {
session: this.session,
deckID: this.deck.id
})
.then(response => {
if (response.data.success) {
this.$emit('change')
}
})
}
}
}