feat: local Game
This commit is contained in:
@@ -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");
|
if (alreadyJoined.length) throw new ApiError(400, "User already joined this game");
|
||||||
|
|
||||||
const [gameRows] = await conn.query(
|
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]
|
[gameId]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,27 @@
|
|||||||
|
|
||||||
<q-separator />
|
<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-card-actions align="center">
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="gameCreator === user.id"
|
v-if="gameCreator === user.id"
|
||||||
@@ -52,6 +73,7 @@ const gameID = ref();
|
|||||||
const gameCreator = ref(null);
|
const gameCreator = ref(null);
|
||||||
const gamePlayers = ref([]);
|
const gamePlayers = ref([]);
|
||||||
const user = ref({ username:"", id:0 });
|
const user = ref({ username:"", id:0 });
|
||||||
|
const addUsername = ref(null);
|
||||||
var canUpdate = false
|
var canUpdate = false
|
||||||
|
|
||||||
const storedUser = LocalStorage.getItem("user")
|
const storedUser = LocalStorage.getItem("user")
|
||||||
@@ -90,6 +112,56 @@ if (storedgameID) {
|
|||||||
router.push("/")
|
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() {
|
async function update() {
|
||||||
if (!canUpdate) {return}
|
if (!canUpdate) {return}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user