Add bio field to user model and update related components: Enhance leaderboard and profile features by including a bio field in user data. Update API routes, UI components, and validation logic to support bio input and display, improving user profiles and leaderboard entries.

This commit is contained in:
Julien Froidefond
2025-12-09 22:00:19 +01:00
parent 16b0437ecb
commit 3a0dd57bb6
13 changed files with 147 additions and 24 deletions

View File

@@ -17,6 +17,7 @@ export async function GET() {
email: true,
username: true,
avatar: true,
bio: true,
hp: true,
maxHp: true,
xp: true,
@@ -50,7 +51,7 @@ export async function PUT(request: Request) {
}
const body = await request.json();
const { username, avatar } = body;
const { username, avatar, bio } = body;
// Validation
if (username !== undefined) {
@@ -84,14 +85,33 @@ export async function PUT(request: Request) {
}
}
// Validation bio
if (bio !== undefined) {
if (typeof bio !== "string") {
return NextResponse.json(
{ error: "La bio doit être une chaîne de caractères" },
{ status: 400 }
);
}
if (bio.length > 500) {
return NextResponse.json(
{ error: "La bio ne peut pas dépasser 500 caractères" },
{ status: 400 }
);
}
}
// Mettre à jour l'utilisateur
const updateData: { username?: string; avatar?: string | null } = {};
const updateData: { username?: string; avatar?: string | null; bio?: string | null } = {};
if (username !== undefined) {
updateData.username = username.trim();
}
if (avatar !== undefined) {
updateData.avatar = avatar || null;
}
if (bio !== undefined) {
updateData.bio = bio.trim() || null;
}
const updatedUser = await prisma.user.update({
where: { id: session.user.id },
@@ -101,6 +121,7 @@ export async function PUT(request: Request) {
email: true,
username: true,
avatar: true,
bio: true,
hp: true,
maxHp: true,
xp: true,