added check for missing players to HK

This commit is contained in:
2021-11-18 00:01:57 +01:00
parent 85970d0214
commit 58317ed5fa
2 changed files with 68 additions and 0 deletions

View File

@@ -6,6 +6,8 @@ import (
"csgowtfd/ent/match"
"csgowtfd/ent/matchplayer"
"csgowtfd/ent/player"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/spray"
"csgowtfd/ent/weapon"
"encoding/json"
"entgo.io/ent/dialect/sql"
@@ -388,6 +390,36 @@ func GetMetaStats(dbPlayer *ent.Player) (*MetaStatsResponse, error) {
return mResponse, nil
}
func DeleteMatch(matchDel *ent.Match, db *ent.Client) error {
tMatchPlayer, err := matchDel.QueryStats().IDs(context.Background())
if err != nil {
return err
}
_, err = db.Spray.Delete().Where(spray.HasMatchPlayersWith(matchplayer.IDIn(tMatchPlayer...))).Exec(context.Background())
if err != nil {
return err
}
_, err = db.Weapon.Delete().Where(weapon.HasStatWith(matchplayer.IDIn(tMatchPlayer...))).Exec(context.Background())
if err != nil {
return err
}
_, err = db.RoundStats.Delete().Where(roundstats.HasMatchPlayerWith(matchplayer.IDIn(tMatchPlayer...))).Exec(context.Background())
if err != nil {
return err
}
_, err = db.MatchPlayer.Delete().Where(matchplayer.IDIn(tMatchPlayer...)).Exec(context.Background())
if err != nil {
return err
}
_, err = db.Match.Delete().Where(match.ID(matchDel.ID)).Exec(context.Background())
if err != nil {
return err
}
return nil
}
func GetWinLossTieForPlayer(dbPlayer *ent.Player) (wins int, looses int, ties int, err error) {
var res []struct {
MatchResult int `json:"match_result"`