Commit 64cd40bb authored by nanahira's avatar nanahira

lint

parent 7eb92860
...@@ -25,7 +25,7 @@ import { HttpModule } from '@nestjs/axios'; ...@@ -25,7 +25,7 @@ import { HttpModule } from '@nestjs/axios';
...MycardAuthModule.registerAsync({ ...MycardAuthModule.registerAsync({
inject: [ConfigService], inject: [ConfigService],
useFactory: async (config: ConfigService) => ({ useFactory: async (config: ConfigService) => ({
accountUrl: config.get('ACCOUNT_ENDPOINT') accountUrl: config.get('ACCOUNT_ENDPOINT'),
}), }),
}), }),
global: true, global: true,
......
...@@ -63,18 +63,23 @@ export class TournamentRuleBase { ...@@ -63,18 +63,23 @@ export class TournamentRuleBase {
if (!winnerId) { if (!winnerId) {
for (const pid of [player1Id, player2Id]) { for (const pid of [player1Id, player2Id]) {
const score = map.get(pid) ?? { win: 0, lose: 0, draw: 0 } as ParticipantScore; const score =
map.get(pid) ?? ({ win: 0, lose: 0, draw: 0 } as ParticipantScore);
score.draw += 1; score.draw += 1;
map.set(pid, score); map.set(pid, score);
} }
} else { } else {
const loserId = winnerId === player1Id ? player2Id : player1Id; const loserId = winnerId === player1Id ? player2Id : player1Id;
const winScore = map.get(winnerId) ?? { win: 0, lose: 0, draw: 0 } as ParticipantScore; const winScore =
map.get(winnerId) ??
({ win: 0, lose: 0, draw: 0 } as ParticipantScore);
winScore.win += 1; winScore.win += 1;
map.set(winnerId, winScore); map.set(winnerId, winScore);
const loseScore = map.get(loserId) ?? { win: 0, lose: 0, draw: 0 } as ParticipantScore; const loseScore =
map.get(loserId) ??
({ win: 0, lose: 0, draw: 0 } as ParticipantScore);
loseScore.lose += 1; loseScore.lose += 1;
map.set(loserId, loseScore); map.set(loserId, loseScore);
} }
...@@ -85,7 +90,9 @@ export class TournamentRuleBase { ...@@ -85,7 +90,9 @@ export class TournamentRuleBase {
} }
participantScore(participant: Participant): Partial<ParticipantScore> { participantScore(participant: Participant): Partial<ParticipantScore> {
return this.getScoreMap().get(participant.id) ?? { win: 0, lose: 0, draw: 0 }; return (
this.getScoreMap().get(participant.id) ?? { win: 0, lose: 0, draw: 0 }
);
} }
participantScoreAfter(participant: Participant): Partial<ParticipantScore> { participantScoreAfter(participant: Participant): Partial<ParticipantScore> {
......
...@@ -141,10 +141,12 @@ export class Swiss extends TournamentRuleBase { ...@@ -141,10 +141,12 @@ export class Swiss extends TournamentRuleBase {
participantScoreAfter(participant: Participant): Partial<ParticipantScore> { participantScoreAfter(participant: Participant): Partial<ParticipantScore> {
const opponentIds = this.getOpponentMap().get(participant.id) ?? new Set(); const opponentIds = this.getOpponentMap().get(participant.id) ?? new Set();
const opponents = Array.from(opponentIds).map((id) => this.participantMap.get(id)); const opponents = Array.from(opponentIds).map((id) =>
this.participantMap.get(id),
);
return { return {
tieBreaker: _.sumBy(opponents, (p) => p.score.score), tieBreaker: _.sumBy(opponents, (p) => p.score.score),
...(participant.quit ? { score: -1 } : {}) ...(participant.quit ? { score: -1 } : {}),
}; };
} }
} }
...@@ -248,8 +248,10 @@ export class Tournament extends DescBase { ...@@ -248,8 +248,10 @@ 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));
}); });
const editScores = this.participants.map((p) => rule.participantScoreAfter(p)); const editScores = this.participants.map((p) =>
this.participants.forEach((p, i) => Object.assign(p.score, editScores[i])) rule.participantScoreAfter(p),
);
this.participants.forEach((p, i) => Object.assign(p.score, editScores[i]));
this.participants = _.sortBy( this.participants = _.sortBy(
this.participants, this.participants,
(p) => -p.score.score, (p) => -p.score.score,
......
...@@ -67,7 +67,11 @@ export class TournamentService extends CrudService(Tournament, { ...@@ -67,7 +67,11 @@ export class TournamentService extends CrudService(Tournament, {
private cmptApiToken = this.config.get<string>('CMPT_API_TOKEN', ''); private cmptApiToken = this.config.get<string>('CMPT_API_TOKEN', '');
async getTournament(id: number, user: MycardUser | number, noAnalytics = false) { async getTournament(
id: number,
user: MycardUser | number,
noAnalytics = false,
) {
const result = await this.findOne(id, (qb) => const result = await this.findOne(id, (qb) =>
Tournament.extraQueryForUser(user, qb, this.entityAliasName), Tournament.extraQueryForUser(user, qb, this.entityAliasName),
); );
...@@ -75,7 +79,7 @@ export class TournamentService extends CrudService(Tournament, { ...@@ -75,7 +79,7 @@ export class TournamentService extends CrudService(Tournament, {
result.data.participants?.forEach((p) => result.data.participants?.forEach((p) =>
this.participantService.wipeDeckbuf(user, p, result.data), this.participantService.wipeDeckbuf(user, p, result.data),
); );
if(result.data.status === TournamentStatus.Ready && !noAnalytics) { if (result.data.status === TournamentStatus.Ready && !noAnalytics) {
result.data.analytics(); result.data.analytics();
} }
} }
...@@ -314,9 +318,7 @@ export class TournamentService extends CrudService(Tournament, { ...@@ -314,9 +318,7 @@ export class TournamentService extends CrudService(Tournament, {
).toException(); ).toException();
} }
participants = sortAfterSwiss( participants = sortAfterSwiss(
participants participants.filter((p) => !p.quit).slice(0, dto.swissMaxPlayers),
.filter((p) => !p.quit)
.slice(0, dto.swissMaxPlayers),
); );
} }
} else if (dto.ygobbsCompt) { } else if (dto.ygobbsCompt) {
......
...@@ -9,7 +9,10 @@ export const multerToParticipant = ( ...@@ -9,7 +9,10 @@ export const multerToParticipant = (
const participant = new Participant(); const participant = new Participant();
participant.quit = false; participant.quit = false;
participant.seq = 1000; participant.seq = 1000;
const rawName = iconv.decode(Buffer.from(multerFile.originalname, 'binary'), 'utf-8'); const rawName = iconv.decode(
Buffer.from(multerFile.originalname, 'binary'),
'utf-8',
);
participant.name = rawName.replace(/(\.ydk)+$/i, ''); participant.name = rawName.replace(/(\.ydk)+$/i, '');
participant.tournamentId = tournamentId; participant.tournamentId = tournamentId;
participant.deckbuf = Buffer.from( participant.deckbuf = Buffer.from(
......
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