Commit 485d2019 authored by nanahira's avatar nanahira

fix ranking

parent 26677bd5
...@@ -4,7 +4,6 @@ import { ...@@ -4,7 +4,6 @@ import {
Participant, Participant,
ParticipantScore, ParticipantScore,
} from '../../participant/entities/participant.entity'; } from '../../participant/entities/participant.entity';
import * as path from 'path';
export class SingleElimination extends TournamentRuleBase { export class SingleElimination extends TournamentRuleBase {
totalRoundCount() { totalRoundCount() {
......
...@@ -27,6 +27,7 @@ import { ApiProperty, PartialType } from '@nestjs/swagger'; ...@@ -27,6 +27,7 @@ import { ApiProperty, PartialType } from '@nestjs/swagger';
import { Match } from '../../match/entities/match.entity'; import { Match } from '../../match/entities/match.entity';
import { TournamentRules } from '../../tournament-rules/rule-map'; import { TournamentRules } from '../../tournament-rules/rule-map';
import _ from 'lodash'; import _ from 'lodash';
import { RenameClass } from 'nicot/dist/src/utility/rename-class';
export enum TournamentRule { export enum TournamentRule {
SingleElimination = 'SingleElimination', SingleElimination = 'SingleElimination',
...@@ -78,7 +79,10 @@ export class Tournament extends DescBase { ...@@ -78,7 +79,10 @@ export class Tournament extends DescBase {
@NotChangeable() @NotChangeable()
@Column('jsonb', { comment: '规则设定', default: {} }) @Column('jsonb', { comment: '规则设定', default: {} })
@ApiProperty({ type: PartialType(RuleSettings), required: false }) @ApiProperty({
type: RenameClass(PartialType(RuleSettings), 'RuleSettingsPartial'),
required: false,
})
ruleSettings: RuleSettings; ruleSettings: RuleSettings;
@EnumColumn(TournamentVisibility, { @EnumColumn(TournamentVisibility, {
...@@ -190,10 +194,11 @@ export class Tournament extends DescBase { ...@@ -190,10 +194,11 @@ export class Tournament extends DescBase {
p.score = new ParticipantScore(); p.score = new ParticipantScore();
Object.assign(p.score, rule.participantScore(p)); Object.assign(p.score, rule.participantScore(p));
}); });
_.sortBy( this.participants = _.sortBy(
this.participants, this.participants,
(p) => -p.score.score, (p) => -p.score.score,
(p) => -p.score.tieBreaker, (p) => -p.score.tieBreaker,
(p) => p.id,
); );
this.participants.forEach((p, i) => { this.participants.forEach((p, i) => {
p.score.rank = i + 1; p.score.rank = i + 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment