Commit 82191785 authored by nanahira's avatar nanahira

allow restart match

parent 8863ec48
...@@ -68,7 +68,10 @@ export class MatchService extends CrudService(Match, { ...@@ -68,7 +68,10 @@ export class MatchService extends CrudService(Match, {
'对局胜者不在对局中。', '对局胜者不在对局中。',
).toException(); ).toException();
} }
if (match.status === MatchStatus.Pending) { if (
match.status === MatchStatus.Pending ||
match.status === MatchStatus.Abandoned
) {
throw new BlankReturnMessageDto( throw new BlankReturnMessageDto(
400, 400,
'对局尚未开始,无法修改。', '对局尚未开始,无法修改。',
...@@ -92,7 +95,11 @@ export class MatchService extends CrudService(Match, { ...@@ -92,7 +95,11 @@ export class MatchService extends CrudService(Match, {
if (dto.winnerId !== undefined) { if (dto.winnerId !== undefined) {
dto.status = MatchStatus.Finished; dto.status = MatchStatus.Finished;
} }
if (match.status === MatchStatus.Finished && dto.winnerId !== undefined) { if (
match.status === MatchStatus.Finished &&
(dto.winnerId !== undefined ||
(dto.player1Score === 0 && dto.player2Score === 0))
) {
// clean all other matches in greater rounds // clean all other matches in greater rounds
await this.repo.update( await this.repo.update(
{ round: MoreThan(match.round), tournamentId: match.tournamentId }, { round: MoreThan(match.round), tournamentId: match.tournamentId },
...@@ -107,6 +114,9 @@ export class MatchService extends CrudService(Match, { ...@@ -107,6 +114,9 @@ export class MatchService extends CrudService(Match, {
); );
} }
dto.winnerId ||= null; dto.winnerId ||= null;
if (dto.player1Score === 0 && dto.player2Score === 0) {
dto.status = MatchStatus.Pending;
}
const result = await this.update(id, dto); const result = await this.update(id, dto);
await this.tournamentService.afterMatchUpdate(match.tournamentId); await this.tournamentService.afterMatchUpdate(match.tournamentId);
return result; return result;
......
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