feat: remove game

This commit is contained in:
Settel 2022-12-16 15:48:10 +01:00
parent 9821353cfb
commit 15d1dca106
2 changed files with 13 additions and 0 deletions

View File

@ -132,6 +132,7 @@ const removeGame = async (): Promise<void> => {
if (confirm('remove game and wipe all of it\'s data?')) { if (confirm('remove game and wipe all of it\'s data?')) {
console.log(1) console.log(1)
await useEngine().removeGame() await useEngine().removeGame()
document.location.reload()
} }
} }
</script> </script>

View File

@ -3,6 +3,7 @@ package application
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"path"
"sirlab.de/go/knowyt/game" "sirlab.de/go/knowyt/game"
"sirlab.de/go/knowyt/log" "sirlab.de/go/knowyt/log"
@ -47,6 +48,17 @@ func (app *Application) removePlayerById(id string, gm *game.Game) error {
return fmt.Errorf("couldn't find player %s in game %s", id, gm.GetId()) return fmt.Errorf("couldn't find player %s in game %s", id, gm.GetId())
} }
quotesInfo := gm.GetQuotesInfoByUser(userToRemove)
for _, quote := range quotesInfo.Quotes {
gameDirName := path.Join(app.config.DataDir, "games", gm.GetId())
quoteFileNameShort := quote.Id + ".json"
quoteFileName := path.Join(gameDirName, "quotes", quoteFileNameShort)
if err := gm.RemoveQuote(quoteFileName, userToRemove.GetId(), quote.Id); err != nil {
return err
}
}
if err := userToRemove.RemovePlayer(); err != nil { if err := userToRemove.RemovePlayer(); err != nil {
return err return err
} }