Delete deck
This commit is contained in:
parent
0475e45275
commit
9616a2fe97
4 changed files with 88 additions and 4 deletions
|
@ -210,10 +210,10 @@ class FFTCGDB
|
||||||
logger.debug "getDecks: OK '#{userID}'"
|
logger.debug "getDecks: OK '#{userID}'"
|
||||||
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: (userID, deckID) ->
|
||||||
new Promise (resolve, reject) =>
|
new Promise (resolve, reject) =>
|
||||||
stmt = @db.prepare 'DELETE FROM decks WHERE deck = ?'
|
stmt = @db.prepare 'DELETE FROM decks WHERE deck = ? AND user = ?'
|
||||||
stmt.run [deckID], (err) ->
|
stmt.run [deckID, userID], (err) ->
|
||||||
stmt.finalize()
|
stmt.finalize()
|
||||||
if err
|
if err
|
||||||
logger.warn "delDeck: FAIL db '#{err.code}' for '#{deckID}'"
|
logger.warn "delDeck: FAIL db '#{err.code}' for '#{deckID}'"
|
||||||
|
|
34
backend/routes/decks/delete.coffee
Normal file
34
backend/routes/decks/delete.coffee
Normal 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
|
|
@ -26,6 +26,8 @@ fastify.route (require "./routes/#{route}") for route in [
|
||||||
'decks/add'
|
'decks/add'
|
||||||
# modify deck
|
# modify deck
|
||||||
'decks/modify'
|
'decks/modify'
|
||||||
|
# delete deck
|
||||||
|
'decks/delete'
|
||||||
]
|
]
|
||||||
|
|
||||||
# request logging
|
# request logging
|
||||||
|
|
|
@ -28,6 +28,40 @@
|
||||||
<v-btn fab absolute bottom right @click.native="editing = true">
|
<v-btn fab absolute bottom right @click.native="editing = true">
|
||||||
<v-icon>edit</v-icon>
|
<v-icon>edit</v-icon>
|
||||||
</v-btn>
|
</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-layout>
|
||||||
</v-container>
|
</v-container>
|
||||||
|
|
||||||
|
@ -60,7 +94,8 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
data: () => ({
|
data: () => ({
|
||||||
editing: false
|
editing: false,
|
||||||
|
deleting: false
|
||||||
}),
|
}),
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -81,6 +116,19 @@ export default {
|
||||||
this.$emit('change')
|
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')
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue