Refactor character class handling across components: Replace hardcoded character class definitions with a centralized CHARACTER_CLASSES import, enhancing maintainability and consistency. Update ProfileForm, Leaderboard, and LeaderboardSection components to utilize new utility functions for character class icons and names, improving code clarity and reducing duplication.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m48s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m48s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { prisma } from "../database";
|
||||
import type { User, Role, Prisma } from "@/prisma/generated/prisma/client";
|
||||
import type { User, Role, Prisma, CharacterClass } from "@/prisma/generated/prisma/client";
|
||||
import { NotFoundError } from "../errors";
|
||||
import { userService } from "./user.service";
|
||||
|
||||
@@ -19,7 +19,7 @@ export interface LeaderboardEntry {
|
||||
level: number;
|
||||
avatar: string | null;
|
||||
bio: string | null;
|
||||
characterClass: string | null;
|
||||
characterClass: CharacterClass | null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,20 +6,7 @@ import type {
|
||||
Prisma,
|
||||
} from "@/prisma/generated/prisma/client";
|
||||
import { ValidationError, NotFoundError, ConflictError } from "../errors";
|
||||
|
||||
// Constantes de validation
|
||||
const VALID_CHARACTER_CLASSES = [
|
||||
"WARRIOR",
|
||||
"MAGE",
|
||||
"ROGUE",
|
||||
"RANGER",
|
||||
"PALADIN",
|
||||
"ENGINEER",
|
||||
"MERCHANT",
|
||||
"SCHOLAR",
|
||||
"BERSERKER",
|
||||
"NECROMANCER",
|
||||
] as const;
|
||||
import { isValidCharacterClass } from "@/lib/character-classes";
|
||||
|
||||
const USERNAME_MIN_LENGTH = 3;
|
||||
const USERNAME_MAX_LENGTH = 20;
|
||||
@@ -305,10 +292,7 @@ export class UserService {
|
||||
}
|
||||
|
||||
// Validation du characterClass
|
||||
if (
|
||||
data.characterClass &&
|
||||
!VALID_CHARACTER_CLASSES.includes(data.characterClass as CharacterClass)
|
||||
) {
|
||||
if (data.characterClass && !isValidCharacterClass(data.characterClass)) {
|
||||
throw new ValidationError(
|
||||
"Classe de personnage invalide",
|
||||
"characterClass"
|
||||
@@ -402,7 +386,7 @@ export class UserService {
|
||||
if (
|
||||
data.characterClass !== undefined &&
|
||||
data.characterClass !== null &&
|
||||
!VALID_CHARACTER_CLASSES.includes(data.characterClass as CharacterClass)
|
||||
!isValidCharacterClass(data.characterClass)
|
||||
) {
|
||||
throw new ValidationError(
|
||||
"Classe de personnage invalide",
|
||||
|
||||
Reference in New Issue
Block a user