Skip to content

Commit

Permalink
fix: allow fallers to have a lower index then the subevent
Browse files Browse the repository at this point in the history
  • Loading branch information
cskiwi committed Sep 5, 2024
1 parent cc554ba commit 8cfae86
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class AssemblyValidationData {
meta?: MetaEntry;
otherMeta?: MetaEntry[];
team?: Team;
previousSeasonTeam?: Team | null;

teamIndex?: number;
teamPlayers?: Player[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RankingLastPlace,
RankingPlace,
RankingSystem,
Standing,
SubEventCompetition,
Team,
} from '@badman/backend-database';
Expand Down Expand Up @@ -84,13 +85,33 @@ export class AssemblyValidationService extends ValidationService<
const idSubs = args.subtitudes?.filter((p) => p !== undefined && p !== null);

const team = await Team.findByPk(args.teamId, {
attributes: ['id', 'name', 'type', 'teamNumber', 'clubId'],
attributes: ['id', 'name', 'type', 'teamNumber', 'clubId', 'link', 'season'],
});

if (!team) {
if (!team?.season) {
throw new Error('Team not found');
}

const previousSeasonTeam = await Team.findOne({
attributes: ['id'],
where: {
link: team.link,
season: team.season - 1,
},
include: [
{
attributes: ['id'],
model: EventEntry,
include: [
{
attributes: ['id', 'faller'],
model: Standing,
},
],
},
],
});

const encounter = (await EncounterCompetition.findByPk(args.encounterId)) || undefined;

let draw: DrawCompetition | null = null;
Expand Down Expand Up @@ -304,8 +325,6 @@ export class AssemblyValidationService extends ValidationService<
}),
);

// const titularsTeam = Team.baseTeam(players, type);

return {
type,
meta,
Expand All @@ -321,6 +340,7 @@ export class AssemblyValidationService extends ValidationService<
event,

team,
previousSeasonTeam,

system,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ export type TeamSubeventIndexRuleParams = {
export class TeamSubeventIndexRule extends Rule {
static override readonly description = 'all.rules.team-assembly.team-subevent-index';
async validate(assembly: AssemblyValidationData): Promise<AssemblyOutput> {
const { teamIndex, subEvent } = assembly;
const { teamIndex, subEvent, previousSeasonTeam } = assembly;

if (!subEvent?.minBaseIndex) {
throw new Error('Subevent is not defined');
}

// if team is degraded, it can have a lower index
if (previousSeasonTeam?.entry?.standing?.faller) {
return {
valid: true,
};
}

if ((teamIndex ?? 0) < subEvent.minBaseIndex) {
return {
valid: false,
Expand Down

0 comments on commit 8cfae86

Please sign in to comment.