Skip to content

Commit

Permalink
fix(backend): bug preventing signups with Fide, ECF, DWZ
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstenglein committed Jul 26, 2024
1 parent 3defea6 commit 1844712
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/database/ratings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ func getCohort(ratingSystem RatingSystem, currentRating int) DojoCohort {
case Ecf:
fallthrough
case Dwz:
fallthrough
case Knsb:
switch {
case currentRating < 300:
Expand Down
4 changes: 2 additions & 2 deletions backend/user/ratings/ratings.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ func FetchDwzRating(dwzId string) (int, error) {

const ratingIndex = 13
tokens := strings.Split(string(b), "|")
if len(tokens) < ratingIndex {
err = errors.New(400, "Invalid request: DWZ API did not return a rating", "Tokens length less than 14")
if ratingIndex >= len(tokens) {
err = errors.New(400, "Invalid request: DWZ API did not return a rating", fmt.Sprintf("ratingIndex out of bounds for tokens %v", tokens))
return 0, err
}

Expand Down
4 changes: 2 additions & 2 deletions backend/user/update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func fetchRatings(user *database.User, update *database.UserUpdate) error {
}

for system, rating := range *update.Ratings {
existingRating, _ := user.Ratings[system]
existingRating := user.Ratings[system]
if system != database.Custom && (existingRating == nil || rating.Username != existingRating.Username ||
rating.CurrentRating == 0 || rating.StartRating == 0) {
if err := fetchCurrentRating(rating, ratings.RatingFetchFuncs[system]); err != nil {
Expand All @@ -168,7 +168,7 @@ func handleAutopickCohort(user *database.User, update *database.UserUpdate) api.
return api.Failure(err)
}
if cohort := update.AutopickCohort(); cohort == database.NoCohort {
return api.Failure(errors.New(500, "Unable to choose cohort. Please contact support", fmt.Sprintf("Autopick cohort returned NoCohort for update %+v", update)))
return api.Failure(errors.New(500, "Unable to choose cohort. Please contact support", fmt.Sprintf("Autopick cohort returned NoCohort for update %#v", update)))
}

user, err := repository.UpdateUser(user.Username, update)
Expand Down

0 comments on commit 1844712

Please sign in to comment.