~xenrox/10man-api

ef96558a86fea0024e003dd48a479d7d4333f632 — Thorben Günther 2 years ago 8b2ba79
Fix multiple bugs

vetoMap:
1. Panic, when trying to vote without a match being in database yet
2. The first element of the reset slice was the first of the old slice.
Reset slice completely to fix that.
getTeams:
1. Return error if less than 5 players are in a team. Happens when
   trying to query for a team when no team has been created yet.
1 files changed, 11 insertions(+), 0 deletions(-)

M graph/schema.resolvers.go
M graph/schema.resolvers.go => graph/schema.resolvers.go +11 -0
@@ 314,6 314,8 @@ func (r *mutationResolver) CreateMatch(ctx context.Context) (int, error) {
	}

	// initialize map vote (maps and random voter)
	// reset slice; if any element is left over, go will not reassign the value
	voteMaps = make([]string, 0)
	voteMaps = config.Maps
	rand.Seed(time.Now().UTC().UnixNano())
	voter := rand.Intn(2)


@@ 416,6 418,10 @@ func (r *mutationResolver) VetoMap(ctx context.Context, mapArg *string) (*model.
		return &mapVote, nil
	}

	if voteStatus == "" {
		return nil, errors.New("vote has not started")
	}

	if voteStatus == "DONE" {
		return nil, errors.New("vote is done")
	}


@@ 537,6 543,11 @@ func (r *queryResolver) GetTeams(ctx context.Context, id *int) (*model.Teams, er
		return nil, database.CheckErrorCode(err)
	}

	// e.g. no teams yet
	if len(team1) != 5 {
		return nil, errors.New("no teams yet")
	}

	// Team 2
	if id != nil {
		// get match by id