Skip to content

Commit

Permalink
Added a test admin command to reset seasons
Browse files Browse the repository at this point in the history
  • Loading branch information
kev306 committed Jan 14, 2025
1 parent 9b308ed commit 833a05c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/databaseAdapters/season.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MongoSeasonAdapter implements DatabaseAdapter {
// Check if ongoing season
if (currentSeason.endDate > new Date()) {
throw new Error(
`Unable to reset season while season is ongoing. Season ends on ${currentSeason.endDate}.`,
`Unable to reset season while season is ongoing. Current season ends on ${currentSeason.endDate}.`,
);
}

Expand Down
27 changes: 27 additions & 0 deletions src/sockets/commands/admin/aresetseason.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// TODO-kev: Delete this file. Purely for testing purposes

import { Command } from '../types';
import { SocketUser } from '../../types';
import seasonAdapter from '../../../databaseAdapters/season';
import { sendReplyToCommand } from '../../sockets';

export const aresetseason: Command = {
command: 'ars',
help: '/ars: Reset season.',
run: async (args: string[], socket: SocketUser) => {
if (args.length != 2) {
sendReplyToCommand(socket, 'Please include the season name.');
return;
}

const seasonName = args[1];

try {
await seasonAdapter.resetSeason(seasonName);
sendReplyToCommand(socket, 'Successfully reset season.');
} catch (error) {
sendReplyToCommand(socket, error.message);
return;
}
},
};
2 changes: 2 additions & 0 deletions src/sockets/commands/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { asessions } from './asessions';
// TODO-kev: Delete the below. Purely for testing purposes
import { acreateseason } from './acreateseason';
import { agetcurrentseason } from './agetcurrentseason';
import { aresetseason } from './aresetseason';

export const adminCommands: Commands = {
[a.command]: a,
Expand All @@ -29,4 +30,5 @@ export const adminCommands: Commands = {
// TODO-kev: Delete the below. Purely for testing purposes
[acreateseason.command]: acreateseason,
[agetcurrentseason.command]: agetcurrentseason,
[aresetseason.command]: aresetseason,
};

0 comments on commit 833a05c

Please sign in to comment.