feat: use displayName in mapUserForClient and profile update

This commit is contained in:
Kirill
2026-05-20 10:46:31 +05:00
parent 36880c298c
commit ce49f75100
+9 -5
View File
@@ -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,
},
})