feat: Implement userService.getOrCreateUser and integrate it across commands, remove old utility scripts, and fix daily bonus calculation.

This commit is contained in:
syntaxbullet
2025-12-08 10:29:40 +01:00
parent 29c0a4752d
commit 866cfab03e
12 changed files with 42 additions and 94 deletions

View File

@@ -17,25 +17,7 @@ export const profile = createCommand({
const targetUser = interaction.options.getUser("user") || interaction.user;
const targetMember = await interaction.guild?.members.fetch(targetUser.id).catch(() => null);
let user = await userService.getUserById(targetUser.id);
if (!user) {
// Auto-create user if they don't exist
// Assuming no class assigned initially (null)
user = await userService.createUser(targetUser.id, targetUser.username, undefined);
}
// Refetch to get class relation if needed (though createUser returns user, it might not have relations loaded if we add them later)
// For now, let's assume we might need to join class manually or update userService to return it.
// Actually, let's just use what we have. If we need class name, we might need a separate query or update userService to include relation.
// Let's check if 'class' is in the returned user object from userService.getUserById.
// Looking at userService.ts, it uses findFirst. If we want relations, we need to add `with`.
// Let's quickly re-fetch with relations to be safe and get Class Name
// Or we can update userService given we are in "Implement Commands" but changing service might be out of scope?
// No, I should make sure the command works.
// Let's rely on standard Drizzle query here for the "view" part or update service.
// Updating service is cleaner.
const user = await userService.getOrCreateUser(targetUser.id, targetUser.username);
const embed = new EmbedBuilder()
.setTitle(`${targetUser.username}'s Profile`)