feat: use displayName in mapUserForClient and profile update
This commit is contained in:
@@ -8,7 +8,11 @@ function mapUserForClient(user) {
|
|||||||
return {
|
return {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
name: user.name,
|
displayName: user.displayName,
|
||||||
|
firstName: user.firstName,
|
||||||
|
lastName: user.lastName,
|
||||||
|
gender: user.gender,
|
||||||
|
avatar: user.avatar,
|
||||||
phone: user.phone,
|
phone: user.phone,
|
||||||
isAdmin: Boolean(adminEmail) && userEmail === adminEmail,
|
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) => {
|
fastify.patch('/api/me/profile', { preHandler: [fastify.authenticate] }, async (request, reply) => {
|
||||||
const userId = request.user.sub
|
const userId = request.user.sub
|
||||||
const nameRaw = request.body?.name
|
const nameRaw = request.body?.displayName
|
||||||
const name = nameRaw === null || nameRaw === undefined ? null : String(nameRaw).trim()
|
const displayName = nameRaw === null || nameRaw === undefined ? null : String(nameRaw).trim()
|
||||||
const phoneRaw = request.body?.phone
|
const phoneRaw = request.body?.phone
|
||||||
const phone = phoneRaw === null || phoneRaw === undefined ? null : String(phoneRaw).trim()
|
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) {
|
if (phone !== null) {
|
||||||
const compact = phone.replace(/[\s()-]/g, '')
|
const compact = phone.replace(/[\s()-]/g, '')
|
||||||
if (compact.length > 20) return reply.code(400).send({ error: 'Телефон слишком длинный' })
|
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({
|
const updated = await prisma.user.update({
|
||||||
where: { id: userId },
|
where: { id: userId },
|
||||||
data: {
|
data: {
|
||||||
name: name && name.length ? name : null,
|
displayName: displayName && displayName.length ? displayName : null,
|
||||||
phone: phone && phone.length ? phone : null,
|
phone: phone && phone.length ? phone : null,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user