~mna/hockeysim

1427589f710a5c5d4e2a468c4f0e3db1ab9f7bd0 — Martin Angers 1 year, 18 days ago 7afce25
add length validation to new league
2 files changed, 18 insertions(+), 2 deletions(-)

M src/cmds/league_cmds/new.js
M src/constants.js
M src/cmds/league_cmds/new.js => src/cmds/league_cmds/new.js +16 -2
@@ 15,7 15,14 @@ function leagueNameQuestion (pres) {
    name: 'leagueName',
    message: 'League name:',
    validate (input) {
      return input.trim ().length > 0
      const len = input.trim ().length
      if (len === 0) {
        return 'value is required'
      }
      if (len > Constants.maxLeagueNameLength) {
        return `value is too long, maximum is ${Constants.maxLeagueNameLength}`
      }
      return true
    },
    filter (input) {
      return input.trim ().toLowerCase ()


@@ 74,7 81,14 @@ function teamSelectionQuestion (conn, index) {
          if (res.teams.includes (name)) {
            return 'team already included in the league'
          }
          return name.length > 0
          const len = name.length
          if (len === 0) {
            return 'value is required'
          }
          if (len > Constants.maxTeamNameLength) {
            return `value is too long, maximum is ${Constants.maxTeamNameLength}`
          }
          return true
        },
        filter (input) {
          return input.trim ()

M src/constants.js => src/constants.js +2 -0
@@ 1,5 1,7 @@
const Constants = Object.freeze ({
  teamsPerLeague: 12,
  maxLeagueNameLength: 100,
  maxTeamNameLength: 100,
})

const PlayerName = Object.freeze ({