fix: tribe - fix incorrect most points logic
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
56dc421bd0
commit
42f95d6dd1
|
@ -0,0 +1,38 @@
|
||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"gitea.dwysokinski.me/twhelp/core/internal/bundb/internal/model"
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
||||||
|
var servers []model.Server
|
||||||
|
if err := db.NewSelect().
|
||||||
|
Model(&servers).
|
||||||
|
Where("special = false").
|
||||||
|
Scan(ctx); err != nil {
|
||||||
|
return fmt.Errorf("couldn't select servers from the db: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, srv := range servers {
|
||||||
|
if _, err := db.NewUpdate().
|
||||||
|
Model(&model.Tribe{}).
|
||||||
|
Where("server_key = ?", srv.Key).
|
||||||
|
Where("most_points < all_points").
|
||||||
|
Set("most_points = all_points").
|
||||||
|
Set("most_points_at = ?", srv.TribeDataUpdatedAt).
|
||||||
|
Returning("NULL").
|
||||||
|
Exec(ctx); err != nil {
|
||||||
|
return fmt.Errorf("%s: couldn't set most p: %w", srv.Key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}, func(ctx context.Context, db *bun.DB) error {
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -260,12 +260,12 @@ func (c createTribeParamsBuilder) setBestRank(p domain.CreateTribeParams) domain
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c createTribeParamsBuilder) setMostPoints(p domain.CreateTribeParams) domain.CreateTribeParams {
|
func (c createTribeParamsBuilder) setMostPoints(p domain.CreateTribeParams) domain.CreateTribeParams {
|
||||||
if c.tribe.Points <= c.tribeDB.MostPoints && c.tribeDB.ID > 0 {
|
if c.tribe.AllPoints <= c.tribeDB.MostPoints && c.tribeDB.ID > 0 {
|
||||||
p.MostPoints = c.tribeDB.MostPoints
|
p.MostPoints = c.tribeDB.MostPoints
|
||||||
p.MostPointsAt = c.tribeDB.MostPointsAt
|
p.MostPointsAt = c.tribeDB.MostPointsAt
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
p.MostPoints = c.tribe.Points
|
p.MostPoints = c.tribe.AllPoints
|
||||||
p.MostPointsAt = time.Now()
|
p.MostPointsAt = time.Now()
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,7 +215,7 @@ func TestTribe_Refresh(t *testing.T) {
|
||||||
ProfileURL: tribes[1].ProfileURL,
|
ProfileURL: tribes[1].ProfileURL,
|
||||||
BestRank: tribes[1].Rank,
|
BestRank: tribes[1].Rank,
|
||||||
BestRankAt: time.Now(),
|
BestRankAt: time.Now(),
|
||||||
MostPoints: tribes[1].Points,
|
MostPoints: tribes[1].AllPoints,
|
||||||
MostPointsAt: time.Now(),
|
MostPointsAt: time.Now(),
|
||||||
MostVillages: tribes[1].NumVillages,
|
MostVillages: tribes[1].NumVillages,
|
||||||
MostVillagesAt: time.Now(),
|
MostVillagesAt: time.Now(),
|
||||||
|
@ -234,7 +234,7 @@ func TestTribe_Refresh(t *testing.T) {
|
||||||
ProfileURL: tribes[2].ProfileURL,
|
ProfileURL: tribes[2].ProfileURL,
|
||||||
BestRank: tribes[2].Rank,
|
BestRank: tribes[2].Rank,
|
||||||
BestRankAt: time.Now(),
|
BestRankAt: time.Now(),
|
||||||
MostPoints: tribes[2].Points,
|
MostPoints: tribes[2].AllPoints,
|
||||||
MostPointsAt: time.Now(),
|
MostPointsAt: time.Now(),
|
||||||
MostVillages: tribes[2].NumVillages,
|
MostVillages: tribes[2].NumVillages,
|
||||||
MostVillagesAt: time.Now(),
|
MostVillagesAt: time.Now(),
|
||||||
|
|
Reference in New Issue
Block a user