built out rest of functionality; add placeholder when there are no custom roles

This commit is contained in:
AlecM33
2023-08-16 13:43:22 -04:00
parent 25fb043292
commit 1d22aebbb9
10 changed files with 117 additions and 49 deletions

View File

@@ -56,6 +56,22 @@ class GameCreationRequest {
}
return false;
}
static timerParamsAreValid = (hasTimer, timerParams) => {
if (hasTimer === false) {
return timerParams === null;
} else {
if (timerParams === null || typeof timerParams !== 'object') {
return false;
}
return (timerParams.hours === null && timerParams.minutes > 0 && timerParams.minutes < 60)
|| (timerParams.minutes === null && timerParams.hours > 0 && timerParams.hours < 6)
|| (timerParams.hours === 0 && timerParams.minutes > 0 && timerParams.minutes < 60)
|| (timerParams.minutes === 0 && timerParams.hours > 0 && timerParams.hours < 6)
|| (timerParams.hours > 0 && timerParams.hours < 6 && timerParams.minutes >= 0 && timerParams.minutes < 60);
}
}
}
function valid (gameParams) {
@@ -65,24 +81,8 @@ function valid (gameParams) {
&& typeof gameParams.moderatorName === 'string'
&& gameParams.moderatorName.length > 0
&& gameParams.moderatorName.length <= 30
&& timerParamsAreValid(gameParams.hasTimer, gameParams.timerParams)
&& GameCreationRequest.timerParamsAreValid(gameParams.hasTimer, gameParams.timerParams)
&& GameCreationRequest.deckIsValid(gameParams.deck);
}
function timerParamsAreValid (hasTimer, timerParams) {
if (hasTimer === false) {
return timerParams === null;
} else {
if (timerParams === null || typeof timerParams !== 'object') {
return false;
}
return (timerParams.hours === null && timerParams.minutes > 0 && timerParams.minutes < 60)
|| (timerParams.minutes === null && timerParams.hours > 0 && timerParams.hours < 6)
|| (timerParams.hours === 0 && timerParams.minutes > 0 && timerParams.minutes < 60)
|| (timerParams.minutes === 0 && timerParams.hours > 0 && timerParams.hours < 6)
|| (timerParams.hours > 0 && timerParams.hours < 6 && timerParams.minutes >= 0 && timerParams.minutes < 60);
}
}
module.exports = GameCreationRequest;