feat: local Game

This commit is contained in:
2025-09-14 04:52:20 +02:00
parent 62932b94e7
commit 0e0a127c60
2 changed files with 73 additions and 1 deletions

View File

@@ -301,7 +301,7 @@ router.post("/games/:id/players", asyncHandler(async (req, res) => {
if (alreadyJoined.length) throw new ApiError(400, "User already joined this game");
const [gameRows] = await conn.query(
"SELECT * FROM current_games WHERE id = ? AND is_open = TRUE AND is_local = FALSE",
"SELECT * FROM current_games WHERE id = ? AND is_open = TRUE",// AND is_local = FALSE", TODO: wehn im body der richtige creator angegeben wurde wir user zu dem local game hinzugefügt
[gameId]
);

View File

@@ -24,6 +24,27 @@
<q-separator />
<div class="row items-center q-gutter-sm full-width q-pa-sm">
<q-input
v-model="addUsername"
filled
label="Username"
maxlength="32"
counter
dense
style="border-radius: 6px;"
/>
<q-btn
label="Add"
color="secondary"
@click="addUser"
rounded
unelevated
/>
</div>
<q-separator />
<q-card-actions align="center">
<q-btn
v-if="gameCreator === user.id"
@@ -52,6 +73,7 @@ const gameID = ref();
const gameCreator = ref(null);
const gamePlayers = ref([]);
const user = ref({ username:"", id:0 });
const addUsername = ref(null);
var canUpdate = false
const storedUser = LocalStorage.getItem("user")
@@ -90,6 +112,56 @@ if (storedgameID) {
router.push("/")
}
async function addUser() {
console.log(addUsername.value)
if (!addUsername.value) {
$q.notify({
type: "negative",
message: "Please enter a username!",
});
return;
}
api.post("/api/users", {
username: addUsername.value
})
.then(function (userResponse) {
console.log(userResponse);
api.post(`/api/games/${gameID.value}/players`, {
user: userResponse.data.id
})
.then(function (joinResponse) {
console.log(joinResponse);
$q.notify({
type: "positive",
message: "Success!",
});
})
.catch(function (error) {
console.log(error);
$q.notify({
type: "negative",
message: error.response.data.error,
});
});
})
.catch(function (error) {
console.log(error);
$q.notify({
type: "negative",
message: error.response.data.error,
});
});
}
async function update() {
if (!canUpdate) {return}