refactor: modernize transaction patterns and improve type safety

- Refactored user.service.ts to use withTransaction() helper
- Added 14 comprehensive unit tests for user.service.ts
- Removed duplicate user creation in interactionCreate.ts
- Improved type safety in interaction.routes.ts
This commit is contained in:
syntaxbullet
2025-12-24 21:23:58 +01:00
parent f44b053a10
commit 6334275d02
4 changed files with 197 additions and 28 deletions

View File

@@ -1,10 +1,20 @@
import { ButtonInteraction, ModalSubmitInteraction, StringSelectMenuInteraction } from "discord.js";
type InteractionHandler = (interaction: any) => Promise<void>;
// Union type for all component interactions
type ComponentInteraction = ButtonInteraction | StringSelectMenuInteraction | ModalSubmitInteraction;
// Type for the handler function that modules export
type InteractionHandler = (interaction: ComponentInteraction) => Promise<void>;
// Type for the dynamically imported module containing the handler
interface InteractionModule {
[key: string]: (...args: any[]) => Promise<void> | any;
}
// Route definition
interface InteractionRoute {
predicate: (interaction: ButtonInteraction | StringSelectMenuInteraction | ModalSubmitInteraction) => boolean;
handler: () => Promise<any>;
predicate: (interaction: ComponentInteraction) => boolean;
handler: () => Promise<InteractionModule>;
method: string;
}