style(api): apply prettier formatting
This commit is contained in:
1 parent
80fef25af3
commit
96fede9fe5
75 files changed
+955
-674
No files matched your search
@@ -45,7 +45,10 @@ export async function migrateAuctionPassHistory(
|
||||
};
|
||||
}> = [];
|
||||
|
||||
for await (const doc of db.collection('auction').find({}).limit(options.limit ?? 0)) {
|
||||
for await (const doc of db
|
||||
.collection('auction')
|
||||
.find({})
|
||||
.limit(options.limit ?? 0)) {
|
||||
stats.scannedAuctions += 1;
|
||||
const set: Record<string, unknown> = {};
|
||||
let changed = false;
|
||||
|
||||
@@ -27,17 +27,21 @@ function createDb(params: {
|
||||
},
|
||||
};
|
||||
},
|
||||
async bulkWrite(writes: Array<{
|
||||
updateOne: {
|
||||
filter: { _id: unknown };
|
||||
update: {
|
||||
$set: Record<string, unknown>;
|
||||
$unset: Record<string, ''>;
|
||||
async bulkWrite(
|
||||
writes: Array<{
|
||||
updateOne: {
|
||||
filter: { _id: unknown };
|
||||
update: {
|
||||
$set: Record<string, unknown>;
|
||||
$unset: Record<string, ''>;
|
||||
};
|
||||
};
|
||||
};
|
||||
}>) {
|
||||
}>,
|
||||
) {
|
||||
for (const write of writes) {
|
||||
const doc = docs.find((item) => item._id === write.updateOne.filter._id);
|
||||
const doc = docs.find(
|
||||
(item) => item._id === write.updateOne.filter._id,
|
||||
);
|
||||
if (!doc) continue;
|
||||
Object.assign(doc, write.updateOne.update.$set);
|
||||
for (const key of Object.keys(write.updateOne.update.$unset)) {
|
||||
@@ -57,7 +61,10 @@ describe('migrateTeamIndex', () => {
|
||||
auctions: [
|
||||
{
|
||||
_id: 'auction-1',
|
||||
teams: [{ side: 'blue', groupIndex: 1 }, { side: 'red', groupIndex: 1 }],
|
||||
teams: [
|
||||
{ side: 'blue', groupIndex: 1 },
|
||||
{ side: 'red', groupIndex: 1 },
|
||||
],
|
||||
bids: [{ side: 'red', groupIndex: 1, amount: 100 }],
|
||||
currentBidder: 'red',
|
||||
currentBidderGroupIndex: 1,
|
||||
@@ -66,7 +73,10 @@ describe('migrateTeamIndex', () => {
|
||||
matches: [
|
||||
{
|
||||
_id: 'match-1',
|
||||
teams: [{ side: 'blue', groupIndex: 1 }, { side: 'red', groupIndex: 1 }],
|
||||
teams: [
|
||||
{ side: 'blue', groupIndex: 1 },
|
||||
{ side: 'red', groupIndex: 1 },
|
||||
],
|
||||
result: {
|
||||
winnerSide: 'blue',
|
||||
blueScore: 1,
|
||||
@@ -112,7 +122,10 @@ describe('migrateTeamIndex', () => {
|
||||
currentBidderTeamIndex: 2,
|
||||
});
|
||||
expect(collections.match[0]).toMatchObject({
|
||||
teams: [{ teamIndex: 1, name: '1팀' }, { teamIndex: 2, name: '2팀' }],
|
||||
teams: [
|
||||
{ teamIndex: 1, name: '1팀' },
|
||||
{ teamIndex: 2, name: '2팀' },
|
||||
],
|
||||
result: {
|
||||
winnerTeamIndex: 1,
|
||||
games: [
|
||||
|
||||
@@ -45,8 +45,20 @@ export async function migrateTeamIndex(
|
||||
changedMatches: 0,
|
||||
};
|
||||
|
||||
await migrateCollection(db.collection('auction'), options.limit, dryRun, stats, 'auction');
|
||||
await migrateCollection(db.collection('match'), options.limit, dryRun, stats, 'match');
|
||||
await migrateCollection(
|
||||
db.collection('auction'),
|
||||
options.limit,
|
||||
dryRun,
|
||||
stats,
|
||||
'auction',
|
||||
);
|
||||
await migrateCollection(
|
||||
db.collection('match'),
|
||||
options.limit,
|
||||
dryRun,
|
||||
stats,
|
||||
'match',
|
||||
);
|
||||
|
||||
return stats;
|
||||
}
|
||||
@@ -60,7 +72,7 @@ async function migrateCollection(
|
||||
) {
|
||||
const cursor = collection.find({}).limit(limit ?? 0);
|
||||
const writes: Array<{
|
||||
updateOne: {
|
||||
updateOne: {
|
||||
filter: { _id: unknown };
|
||||
update: { $set: Record<string, unknown>; $unset: Record<string, ''> };
|
||||
};
|
||||
@@ -143,7 +155,8 @@ function migrateMatch(doc: AnyDoc) {
|
||||
const migrated = { ...team };
|
||||
const teamIndex = readTeamIndex(migrated);
|
||||
if (teamIndex !== undefined) migrated.teamIndex = teamIndex;
|
||||
if (!migrated.name && typeof teamIndex === 'number') migrated.name = `${teamIndex}팀`;
|
||||
if (!migrated.name && typeof teamIndex === 'number')
|
||||
migrated.name = `${teamIndex}팀`;
|
||||
if ('side' in migrated || 'groupIndex' in migrated) changed = true;
|
||||
delete migrated.side;
|
||||
delete migrated.groupIndex;
|
||||
@@ -200,7 +213,10 @@ function migrateResult(result: Record<string, unknown>) {
|
||||
migrated.games = games;
|
||||
|
||||
const seriesResults = asArray(result.seriesResults).map((series) => {
|
||||
if (typeof series.teamAIndex === 'number' && typeof series.teamBIndex === 'number') {
|
||||
if (
|
||||
typeof series.teamAIndex === 'number' &&
|
||||
typeof series.teamBIndex === 'number'
|
||||
) {
|
||||
return series;
|
||||
}
|
||||
changed = true;
|
||||
@@ -216,7 +232,9 @@ function migrateResult(result: Record<string, unknown>) {
|
||||
const teamBIndex = Math.max(legacyBlueTeamIndex, legacyRedTeamIndex);
|
||||
const blueScore = numberOrDefault(series.blueScore, 0);
|
||||
const redScore = numberOrDefault(series.redScore, 0);
|
||||
const winnerSide = isSide(series.winnerSide) ? series.winnerSide : undefined;
|
||||
const winnerSide = isSide(series.winnerSide)
|
||||
? series.winnerSide
|
||||
: undefined;
|
||||
const winnerTeamIndex =
|
||||
winnerSide === 'blue'
|
||||
? legacyBlueTeamIndex
|
||||
@@ -231,7 +249,8 @@ function migrateResult(result: Record<string, unknown>) {
|
||||
winnerTeamIndex,
|
||||
};
|
||||
});
|
||||
migrated.seriesResults = seriesResults.length > 0 ? seriesResults : buildSeries(games);
|
||||
migrated.seriesResults =
|
||||
seriesResults.length > 0 ? seriesResults : buildSeries(games);
|
||||
|
||||
if (typeof migrated.winnerTeamIndex !== 'number') {
|
||||
const migratedSeriesResults = Array.isArray(migrated.seriesResults)
|
||||
@@ -244,7 +263,11 @@ function migrateResult(result: Record<string, unknown>) {
|
||||
: undefined);
|
||||
}
|
||||
|
||||
if ('winnerSide' in migrated || 'blueScore' in migrated || 'redScore' in migrated) {
|
||||
if (
|
||||
'winnerSide' in migrated ||
|
||||
'blueScore' in migrated ||
|
||||
'redScore' in migrated
|
||||
) {
|
||||
changed = true;
|
||||
}
|
||||
delete migrated.winnerSide;
|
||||
@@ -272,8 +295,12 @@ function buildSeries(games: Record<string, unknown>[]) {
|
||||
const teamAIndex = Math.min(blueTeamIndex, redTeamIndex);
|
||||
const teamBIndex = Math.max(blueTeamIndex, redTeamIndex);
|
||||
const key = `${teamAIndex}:${teamBIndex}`;
|
||||
const current =
|
||||
bySeries.get(key) ?? { teamAIndex, teamBIndex, teamAWins: 0, teamBWins: 0 };
|
||||
const current = bySeries.get(key) ?? {
|
||||
teamAIndex,
|
||||
teamBIndex,
|
||||
teamAWins: 0,
|
||||
teamBWins: 0,
|
||||
};
|
||||
if (winnerTeamIndex === teamAIndex) current.teamAWins += 1;
|
||||
if (winnerTeamIndex === teamBIndex) current.teamBWins += 1;
|
||||
current.winnerTeamIndex =
|
||||
@@ -331,5 +358,7 @@ function numberOrDefault(value: unknown, fallback: number) {
|
||||
}
|
||||
|
||||
function numberOrUndefined(value: unknown) {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
||||
return typeof value === 'number' && Number.isFinite(value)
|
||||
? value
|
||||
: undefined;
|
||||
}
|
||||
+16
-10
@@ -30,20 +30,26 @@ function createDb(params: { auctions?: Doc[]; history?: Doc[] }) {
|
||||
},
|
||||
};
|
||||
},
|
||||
async bulkWrite(writes: Array<{
|
||||
updateOne: {
|
||||
filter: { _id: unknown };
|
||||
update: {
|
||||
$set?: Record<string, unknown>;
|
||||
$unset?: Record<string, ''>;
|
||||
async bulkWrite(
|
||||
writes: Array<{
|
||||
updateOne: {
|
||||
filter: { _id: unknown };
|
||||
update: {
|
||||
$set?: Record<string, unknown>;
|
||||
$unset?: Record<string, ''>;
|
||||
};
|
||||
};
|
||||
};
|
||||
}>) {
|
||||
}>,
|
||||
) {
|
||||
for (const write of writes) {
|
||||
const doc = docs.find((item) => item._id === write.updateOne.filter._id);
|
||||
const doc = docs.find(
|
||||
(item) => item._id === write.updateOne.filter._id,
|
||||
);
|
||||
if (!doc) continue;
|
||||
Object.assign(doc, write.updateOne.update.$set ?? {});
|
||||
for (const key of Object.keys(write.updateOne.update.$unset ?? {})) {
|
||||
for (const key of Object.keys(
|
||||
write.updateOne.update.$unset ?? {},
|
||||
)) {
|
||||
delete doc[key];
|
||||
}
|
||||
}
|
||||
|
||||
+11
-3
@@ -31,7 +31,10 @@ interface MigrationStats {
|
||||
}
|
||||
|
||||
type AnyDoc = Record<string, unknown> & { _id: unknown };
|
||||
type UpdateDoc = { $set?: Record<string, unknown>; $unset?: Record<string, ''> };
|
||||
type UpdateDoc = {
|
||||
$set?: Record<string, unknown>;
|
||||
$unset?: Record<string, ''>;
|
||||
};
|
||||
|
||||
const AUCTION_FIELD_RENAMES: Array<{
|
||||
from: string;
|
||||
@@ -43,7 +46,11 @@ const AUCTION_FIELD_RENAMES: Array<{
|
||||
{ from: 'passedQueue', to: 'passedAuctionPlayerQueue' },
|
||||
{ from: 'auctionRound', to: 'currentAuctionRound' },
|
||||
{ from: 'currentIndex', to: 'currentAuctionPlayerOrderIndex' },
|
||||
{ from: 'bids', to: 'auctionBidHistory', transform: transformAuctionBidHistory },
|
||||
{
|
||||
from: 'bids',
|
||||
to: 'auctionBidHistory',
|
||||
transform: transformAuctionBidHistory,
|
||||
},
|
||||
{ from: 'currentBid', to: 'currentHighestBidPointAmount' },
|
||||
{ from: 'currentBidderTeamIndex', to: 'currentHighestBidderTeamIndex' },
|
||||
{
|
||||
@@ -157,7 +164,8 @@ async function countDuplicateHistorySequences(
|
||||
const duplicates = new Set<string>();
|
||||
for await (const doc of collection.find({}).limit(limit ?? 0)) {
|
||||
const auctionId = stringifyId(doc.auctionId);
|
||||
const sequence = typeof doc.sequence === 'number' ? doc.sequence : undefined;
|
||||
const sequence =
|
||||
typeof doc.sequence === 'number' ? doc.sequence : undefined;
|
||||
if (!auctionId || sequence === undefined) continue;
|
||||
|
||||
const key = `${auctionId}:${sequence}`;
|
||||
|
||||
+14
-12
@@ -5,10 +5,7 @@ import { NestFactory } from '@nestjs/core';
|
||||
import mongoose from 'mongoose';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
import {
|
||||
ConnectionService,
|
||||
resolveMongoDbName,
|
||||
} from '../connection.service';
|
||||
import { ConnectionService, resolveMongoDbName } from '../connection.service';
|
||||
import type {
|
||||
MatchDocument,
|
||||
MatchGameAssignment,
|
||||
@@ -214,12 +211,16 @@ async function main() {
|
||||
printPlan(options, match, codes, plan);
|
||||
|
||||
if (options.dryRun) {
|
||||
console.log('No writes were made. Re-run with --apply to update MongoDB.');
|
||||
console.log(
|
||||
'No writes were made. Re-run with --apply to update MongoDB.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const session = await (await connectionService.getConnection()).startSession();
|
||||
const session = await (
|
||||
await connectionService.getConnection()
|
||||
).startSession();
|
||||
try {
|
||||
await session.withTransaction(async () => {
|
||||
await applyTournamentCodeUpdates(plan, now, session);
|
||||
@@ -230,9 +231,9 @@ async function main() {
|
||||
status: 'finished',
|
||||
roundRobinMaxRounds: options.maxRounds,
|
||||
gameSchedule: plan.schedule,
|
||||
tournamentCodeIds: [
|
||||
...plan.usedCodeByOldGameNumber.values(),
|
||||
].map((code) => code._id),
|
||||
tournamentCodeIds: [...plan.usedCodeByOldGameNumber.values()].map(
|
||||
(code) => code._id,
|
||||
),
|
||||
resultPollState: {
|
||||
startedAt: match.resultPollState?.startedAt ?? now,
|
||||
lastPolledAt: now,
|
||||
@@ -423,7 +424,9 @@ function partitionIntoRounds(
|
||||
}
|
||||
|
||||
if (!fillRound(0)) {
|
||||
throw new Error('Could not partition result games into simultaneous rounds.');
|
||||
throw new Error(
|
||||
'Could not partition result games into simultaneous rounds.',
|
||||
);
|
||||
}
|
||||
|
||||
return rounds;
|
||||
@@ -586,8 +589,7 @@ function buildSeriesResults(games: MatchGameResult[]): MatchSeriesResult[] {
|
||||
}
|
||||
return [...bySeries.values()].sort(
|
||||
(left, right) =>
|
||||
left.teamAIndex - right.teamAIndex ||
|
||||
left.teamBIndex - right.teamBIndex,
|
||||
left.teamAIndex - right.teamAIndex || left.teamBIndex - right.teamBIndex,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,9 +219,9 @@ async function listDuplicateHistorySequences(
|
||||
.toArray();
|
||||
}
|
||||
|
||||
function printDuplicateHistorySequences(groups: Awaited<
|
||||
ReturnType<typeof listDuplicateHistorySequences>
|
||||
>) {
|
||||
function printDuplicateHistorySequences(
|
||||
groups: Awaited<ReturnType<typeof listDuplicateHistorySequences>>,
|
||||
) {
|
||||
if (groups.length === 0) {
|
||||
console.log('No duplicate auctionHistory auctionId+sequence groups found.');
|
||||
return;
|
||||
@@ -248,7 +248,8 @@ async function repairDuplicateHistorySequences(
|
||||
): Promise<DuplicateSequenceRepairStats> {
|
||||
const historyCollection = db.collection('auctionHistory');
|
||||
const auctionCollection = db.collection('auction');
|
||||
const affectedAuctionIds = await findAuctionIdsWithDuplicateHistorySequences(db);
|
||||
const affectedAuctionIds =
|
||||
await findAuctionIdsWithDuplicateHistorySequences(db);
|
||||
const stats: DuplicateSequenceRepairStats = {
|
||||
affectedAuctions: affectedAuctionIds.length,
|
||||
changedAuctionSequenceFields: 0,
|
||||
|
||||
+4
-4
@@ -177,7 +177,9 @@ function parseArgs(argv: string[]): CliOptions {
|
||||
|
||||
function parseCommitQuorum(value: string | undefined, label: string) {
|
||||
if (!value) {
|
||||
throw new Error(`${label} requires a positive integer, majority, or votingMembers.`);
|
||||
throw new Error(
|
||||
`${label} requires a positive integer, majority, or votingMembers.`,
|
||||
);
|
||||
}
|
||||
if (value === 'majority' || value === 'votingMembers') return value;
|
||||
return parsePositiveInteger(value, label);
|
||||
@@ -230,9 +232,7 @@ function printDuplicateGroups(groups: TournamentCodeDuplicateGroupSummary[]) {
|
||||
kind: group.kind,
|
||||
loserCodes: group.losers.map((loser) => loser.code ?? '').join(', '),
|
||||
loserIds: group.losers.map((loser) => loser.id).join(', '),
|
||||
loserStates: group.losers
|
||||
.map((loser) => loser.state ?? '')
|
||||
.join(', '),
|
||||
loserStates: group.losers.map((loser) => loser.state ?? '').join(', '),
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user