More commands

- fixed backend error responses
- added round abort command
pull/15/head
Julius 6 years ago
parent 31c91c54ad
commit d0085a2bfd

@ -49,3 +49,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- code style issues - code style issues
- Bingo button not shown on refresh - Bingo button not shown on refresh
- bingo chat style (images too large) - bingo chat style (images too large)
- backend now returns precise error messages

@ -24,6 +24,9 @@ type LobbyMutation {
"starts a round in a lobby if the user is the admin" "starts a round in a lobby if the user is the admin"
startRound: BingoRound startRound: BingoRound
"sets the round status"
setRoundStatus(status: RoundStatus): BingoRound
"sets the new gridsize for the lobby" "sets the new gridsize for the lobby"
setGridSize(gridSize: Int!): BingoLobby setGridSize(gridSize: Int!): BingoLobby

@ -125,7 +125,7 @@ async function leaveLobby() {
/** /**
* Kicks a player by id. * Kicks a player by id.
* @param playerId * @param pid
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async function kickPlayer(pid) { async function kickPlayer(pid) {
@ -167,6 +167,7 @@ async function executeCommand(message) {
/hideinfo - hides all info messages <br> /hideinfo - hides all info messages <br>
/showinfo - shows all info messages <br> /showinfo - shows all info messages <br>
/ping - shows the current ping <br> /ping - shows the current ping <br>
/abortround - aborts the current round <br>
`); `);
break; break;
case '/hideinfo': case '/hideinfo':
@ -178,6 +179,9 @@ async function executeCommand(message) {
case '/ping': case '/ping':
reply(`Ping: ${await ping()} ms`); reply(`Ping: ${await ping()} ms`);
break; break;
case '/abortround':
reply(await setRoundFinished());
break;
default: default:
reply('Unknown command'); reply('Unknown command');
break; break;
@ -334,6 +338,30 @@ async function submitFieldToggle(wordPanel) {
} }
} }
/**
* Sets the round status to FINISHED
* @returns {Promise<string>}
*/
async function setRoundFinished() {
let response = await postGraphqlQuery(`
mutation($lobbyId:ID!){
bingo {
mutateLobby(id:$lobbyId) {
setRoundStatus(status:FINISHED) {
status
}
}
}
}`, {lobbyId: getLobbyParam()});
if (response.status === 200 && response.data.bingo.mutateLobby.setRoundStatus) {
return 'Set round to finished';
} else {
console.error(response);
showError('Failed to set round status');
}
}
/** /**
* Submits bingo * Submits bingo
* @returns {Promise<void>} * @returns {Promise<void>}
@ -442,7 +470,10 @@ async function loadWinnerInfo() {
}`, {lobbyId: getLobbyParam()}); }`, {lobbyId: getLobbyParam()});
if (response.status === 200) { if (response.status === 200) {
let roundInfo = response.data.bingo.lobby.currentRound; let roundInfo = response.data.bingo.lobby.currentRound;
displayWinner(roundInfo); if (roundInfo.winner)
displayWinner(roundInfo);
else
window.location.reload();
} else { } else {
console.error(response); console.error(response);
showError('Failed to get round information'); showError('Failed to get round information');

@ -1064,6 +1064,18 @@ class LobbyWrapper {
let currentRound = await this.currentRound(); let currentRound = await this.currentRound();
return currentRound && (await currentRound.status()) === 'ACTIVE'; return currentRound && (await currentRound.status()) === 'ACTIVE';
} }
/**
* Sets the status of the current round
* @param status {String} - the status
* @returns {Promise<RoundWrapper>}
*/
async setRoundStatus(status) {
let currentRound = await this.currentRound();
await currentRound.updateStatus(status);
await bdm.addInfoMessage(this.id, `Admin set round status to ${status}`);
return currentRound;
}
} }
@ -1386,6 +1398,9 @@ router.graphqlResolver = async (req, res) => {
if (admin.id === playerId) { if (admin.id === playerId) {
await lobbyWrapper.removePlayer(pid); await lobbyWrapper.removePlayer(pid);
return new PlayerWrapper(pid); return new PlayerWrapper(pid);
} else {
res.status(403);
return new GraphQLError('You are not an admin');
} }
}, },
startRound: async () => { startRound: async () => {
@ -1393,6 +1408,18 @@ router.graphqlResolver = async (req, res) => {
if (admin.id === playerId) { if (admin.id === playerId) {
await lobbyWrapper.startNewRound(); await lobbyWrapper.startNewRound();
return lobbyWrapper.currentRound(); return lobbyWrapper.currentRound();
} else {
res.status(403);
return new GraphQLError('You are not an admin');
}
},
setRoundStatus: async ({status}) => {
let admin = await lobbyWrapper.admin();
if (admin.id === playerId) {
return await lobbyWrapper.setRoundStatus(status);
} else {
res.status(403);
return new GraphQLError('You are not an admin');
} }
}, },
setGridSize: async ({gridSize}) => { setGridSize: async ({gridSize}) => {
@ -1400,6 +1427,9 @@ router.graphqlResolver = async (req, res) => {
if (admin.id === playerId) { if (admin.id === playerId) {
await lobbyWrapper.setGridSize(gridSize); await lobbyWrapper.setGridSize(gridSize);
return lobbyWrapper; return lobbyWrapper;
} else {
res.status(403);
return new GraphQLError('You are not an admin');
} }
}, },
setWords: async({words}) => { setWords: async({words}) => {
@ -1410,6 +1440,7 @@ router.graphqlResolver = async (req, res) => {
return lobbyWrapper; return lobbyWrapper;
} else { } else {
res.status(413); // request entity too large res.status(413); // request entity too large
return new GraphQLError('Too many words');
} }
else else
res.status(403); // forbidden res.status(403); // forbidden
@ -1421,6 +1452,7 @@ router.graphqlResolver = async (req, res) => {
return new MessageWrapper(result); return new MessageWrapper(result);
} else { } else {
res.status(401); // unautorized res.status(401); // unautorized
return new GraphQLError('You are not in the lobby');
} }
}, },
submitBingo: async () => { submitBingo: async () => {
@ -1428,10 +1460,13 @@ router.graphqlResolver = async (req, res) => {
let currentRound = await lobbyWrapper.currentRound(); let currentRound = await lobbyWrapper.currentRound();
if (isBingo && await lobbyWrapper.hasPlayer(playerId)) { if (isBingo && await lobbyWrapper.hasPlayer(playerId)) {
let result = await currentRound.setWinner(playerId); let result = await currentRound.setWinner(playerId);
if (result) let username = await new PlayerWrapper(playerId).username();
if (result) {
await bdm.addInfoMessage(lobbyId, `**${username}** won!`);
return currentRound; return currentRound;
else } else {
res.status(500); res.status(500);
}
} else { } else {
res.status(400); res.status(400);
return new GraphQLError('Bingo check failed. This is not a bingo!'); return new GraphQLError('Bingo check failed. This is not a bingo!');

Loading…
Cancel
Save