Skip to content

Add match validation #69

Description

@tandrewnichols

We need more validation around adding a match. Currently, you add matches in which individual games are ties, or even the entire match is a tie. For instance, you can enter the default scores, 11 to 11 in both games, and it works fine.

We should check that:

  1. One player wins two of the games.
  2. One player does NOT win three games (could affect ratings strangely).
  3. The scores in all games are different.
  4. Winning score is 11 if losing score is 9 or less.
  5. Winning score is NEVER less than 11.
  6. Losing score is AT LEAST 2 less than the winning score.

Mongoose has something called statics, so we could just add these to the match schema. I would like to see us, generally, move more of the logic to the schemas, since we're really doing operations against Matches and Players most of the time.

Something like:

Match.statics.validateGame = function(matchObj){
    // Do validation
}

Match.statics.validateMatch = function(matchObj){
    // Do validation
}

etc...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions