|
|
@ -236,6 +236,16 @@ class BingoDataManager {
|
|
|
|
return await this._queryFirstResult(this.queries.addWord.sql, [lobbyId, word]);
|
|
|
|
return await this._queryFirstResult(this.queries.addWord.sql, [lobbyId, word]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Removes a word from the lobby
|
|
|
|
|
|
|
|
* @param lobbyId {Number} - the id of the lobby
|
|
|
|
|
|
|
|
* @param wordId {Number} - the id of the word
|
|
|
|
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async removeWordFromLobby(lobbyId, wordId) {
|
|
|
|
|
|
|
|
return await this._queryFirstResult(this.queries.removeLobbyWord.sql, [lobbyId, wordId]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Returns all words used in a lobby
|
|
|
|
* Returns all words used in a lobby
|
|
|
|
* @param lobbyId {Number} - the id of the lobby
|
|
|
|
* @param lobbyId {Number} - the id of the lobby
|
|
|
@ -303,6 +313,15 @@ class BingoDataManager {
|
|
|
|
return await this._queryFirstResult(this.queries.addGrid.sql, [playerId, lobbyId, roundId]);
|
|
|
|
return await this._queryFirstResult(this.queries.addGrid.sql, [playerId, lobbyId, roundId]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Clears all grids for a lobby.
|
|
|
|
|
|
|
|
* @param lobbyId {Number} - the id of the lobby
|
|
|
|
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async clearGrids(lobbyId) {
|
|
|
|
|
|
|
|
return await this._queryFirstResult(this.queries.clearLobbyGrids.sql, [lobbyId]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Adds a word to a grid with specific location
|
|
|
|
* Adds a word to a grid with specific location
|
|
|
|
* @param gridId {Number} - the id of the gird
|
|
|
|
* @param gridId {Number} - the id of the gird
|
|
|
@ -1018,20 +1037,65 @@ class LobbyWrapper {
|
|
|
|
return (result && result.player_id);
|
|
|
|
return (result && result.player_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Adds a word to the lobby
|
|
|
|
|
|
|
|
* @param word
|
|
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async addWord(word) {
|
|
|
|
|
|
|
|
await bdm.addWordToLobby(this.id, word);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Removes a word from the lobby
|
|
|
|
|
|
|
|
* @param wordId
|
|
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async removeWord(wordId) {
|
|
|
|
|
|
|
|
await bdm.removeWordFromLobby(this.id, wordId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Sets the words of the lobby
|
|
|
|
* Sets the words of the lobby
|
|
|
|
* @param words
|
|
|
|
* @param words
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async setWords(words) {
|
|
|
|
async setWords(words) {
|
|
|
|
if (words.length > 0) {
|
|
|
|
if (words.length > 0 && !await this.roundActive()) {
|
|
|
|
await bdm.clearLobbyWords(this.id);
|
|
|
|
let {newWords, removedWords} = await this._filterWords(words);
|
|
|
|
for (let word of words)
|
|
|
|
for (let word of newWords)
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await this.addWord(word);
|
|
|
|
await bdm.addWordToLobby(this.id, word);
|
|
|
|
for (let word of removedWords)
|
|
|
|
|
|
|
|
await this.removeWord(word.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Filters the bingo words
|
|
|
|
|
|
|
|
* @param words
|
|
|
|
|
|
|
|
* @returns {Promise<{removedWords: *[], newWords: *[]}>}
|
|
|
|
|
|
|
|
* @private
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
async _filterWords(words) {
|
|
|
|
|
|
|
|
let curWords = await this.words();
|
|
|
|
|
|
|
|
let currentWords = [];
|
|
|
|
|
|
|
|
let currentWordContent = [];
|
|
|
|
|
|
|
|
for (let word of curWords) {
|
|
|
|
|
|
|
|
currentWordContent.push(await word.content());
|
|
|
|
|
|
|
|
currentWords.push({
|
|
|
|
|
|
|
|
id: word.id,
|
|
|
|
|
|
|
|
content: (await word.content())
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let newWords = words.filter(x => (!currentWordContent.includes(x)));
|
|
|
|
|
|
|
|
let removedWords = currentWords.filter(x => !words.includes(x.content));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
newWords: newWords,
|
|
|
|
|
|
|
|
removedWords: removedWords
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Adds a player to the lobby.
|
|
|
|
* Adds a player to the lobby.
|
|
|
|
* @param playerId
|
|
|
|
* @param playerId
|
|
|
@ -1074,6 +1138,9 @@ class LobbyWrapper {
|
|
|
|
let currentRound = await this.currentRound();
|
|
|
|
let currentRound = await this.currentRound();
|
|
|
|
await currentRound.updateStatus(status);
|
|
|
|
await currentRound.updateStatus(status);
|
|
|
|
await bdm.addInfoMessage(this.id, `Admin set round status to ${status}`);
|
|
|
|
await bdm.addInfoMessage(this.id, `Admin set round status to ${status}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (status === 'FINISHED')
|
|
|
|
|
|
|
|
await bdm.clearGrids(this.id);
|
|
|
|
return currentRound;
|
|
|
|
return currentRound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1463,6 +1530,7 @@ router.graphqlResolver = async (req, res) => {
|
|
|
|
let username = await new PlayerWrapper(playerId).username();
|
|
|
|
let username = await new PlayerWrapper(playerId).username();
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
await bdm.addInfoMessage(lobbyId, `**${username}** won!`);
|
|
|
|
await bdm.addInfoMessage(lobbyId, `**${username}** won!`);
|
|
|
|
|
|
|
|
await bdm.clearGrids(lobbyId);
|
|
|
|
return currentRound;
|
|
|
|
return currentRound;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
res.status(500);
|
|
|
|
res.status(500);
|
|
|
|