From ce49f75100cdcd689ca6180a1d9aa1007ac31a4a Mon Sep 17 00:00:00 2001 From: Kirill Date: Wed, 20 May 2026 10:46:31 +0500 Subject: [PATCH] feat: use displayName in mapUserForClient and profile update --- server/src/routes/auth.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server/src/routes/auth.js b/server/src/routes/auth.js index 74b18d5..db286d7 100644 --- a/server/src/routes/auth.js +++ b/server/src/routes/auth.js @@ -8,7 +8,11 @@ function mapUserForClient(user) { return { id: user.id, email: user.email, - name: user.name, + displayName: user.displayName, + firstName: user.firstName, + lastName: user.lastName, + gender: user.gender, + avatar: user.avatar, phone: user.phone, isAdmin: Boolean(adminEmail) && userEmail === adminEmail, } @@ -113,12 +117,12 @@ export async function registerAuthRoutes(fastify) { fastify.patch('/api/me/profile', { preHandler: [fastify.authenticate] }, async (request, reply) => { const userId = request.user.sub - const nameRaw = request.body?.name - const name = nameRaw === null || nameRaw === undefined ? null : String(nameRaw).trim() + const nameRaw = request.body?.displayName + const displayName = nameRaw === null || nameRaw === undefined ? null : String(nameRaw).trim() const phoneRaw = request.body?.phone const phone = phoneRaw === null || phoneRaw === undefined ? null : String(phoneRaw).trim() - if (name !== null && name.length > 40) return reply.code(400).send({ error: 'Имя/ник максимум 40 символов' }) + if (displayName !== null && displayName.length > 40) return reply.code(400).send({ error: 'Имя/ник максимум 40 символов' }) if (phone !== null) { const compact = phone.replace(/[\s()-]/g, '') if (compact.length > 20) return reply.code(400).send({ error: 'Телефон слишком длинный' }) @@ -130,7 +134,7 @@ export async function registerAuthRoutes(fastify) { const updated = await prisma.user.update({ where: { id: userId }, data: { - name: name && name.length ? name : null, + displayName: displayName && displayName.length ? displayName : null, phone: phone && phone.length ? phone : null, }, })