test commit

This commit is contained in:
Kirill
2026-05-21 13:39:45 +05:00
parent a176955521
commit 058fa26e12
18 changed files with 563 additions and 45 deletions
@@ -0,0 +1,2 @@
ALTER TABLE User DROP COLUMN phone;
ALTER TABLE User ADD COLUMN "avatarType" TEXT;
@@ -0,0 +1 @@
ALTER TABLE User ADD COLUMN "avatarStyle" TEXT;
Binary file not shown.
+2 -1
View File
@@ -82,7 +82,8 @@ model User {
lastName String?
gender String?
avatar String?
phone String?
avatarType String?
avatarStyle String?
passwordHash String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
+1 -1
View File
@@ -73,7 +73,7 @@ export async function registerAdminOrderRoutes(fastify) {
const order = await prisma.order.findUnique({
where: { id },
include: {
user: { select: { id: true, email: true, displayName: true, phone: true } },
user: { select: { id: true, email: true, displayName: true } },
items: true,
messages: { orderBy: { createdAt: 'asc' } },
},
+30 -13
View File
@@ -13,7 +13,8 @@ function mapUserForClient(user) {
lastName: user.lastName,
gender: user.gender,
avatar: user.avatar,
phone: user.phone,
avatarType: user.avatarType,
avatarStyle: user.avatarStyle,
isAdmin: Boolean(adminEmail) && userEmail === adminEmail,
}
}
@@ -119,25 +120,41 @@ export async function registerAuthRoutes(fastify) {
const userId = request.user.sub
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()
const avatarRaw = request.body?.avatar
const avatar = avatarRaw === null || avatarRaw === undefined ? undefined : String(avatarRaw).trim()
const avatarTypeRaw = request.body?.avatarType
const avatarType =
avatarTypeRaw === null || avatarTypeRaw === undefined ? undefined : String(avatarTypeRaw).trim()
const avatarStyleRaw = request.body?.avatarStyle
const avatarStyle =
avatarStyleRaw === null || avatarStyleRaw === undefined ? undefined : String(avatarStyleRaw).trim()
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: 'Телефон слишком длинный' })
if (compact.length && !/^\+?\d{7,20}$/.test(compact)) {
return reply.code(400).send({ error: 'Некорректный телефон' })
}
if (avatarType !== undefined && avatarType !== 'oauth' && avatarType !== 'generated' && avatarType !== '') {
return reply.code(400).send({ error: 'avatarType должен быть oauth | generated | пустая строка' })
}
if (avatar !== undefined && avatar.length > 200000) return reply.code(400).send({ error: 'Аватар слишком большой' })
if (avatarStyle !== undefined && avatarStyle !== '' && avatarStyle.length > 30) {
return reply.code(400).send({ error: 'Стиль аватара слишком длинный' })
}
const data = {
displayName: displayName && displayName.length ? displayName : null,
}
if (avatarType !== undefined) {
data.avatarType = avatarType === '' ? null : avatarType
}
if (avatar !== undefined) {
data.avatar = avatar === '' ? null : avatar
}
if (avatarStyle !== undefined) {
data.avatarStyle = avatarStyle === '' ? null : avatarStyle
}
const updated = await prisma.user.update({
where: { id: userId },
data: {
displayName: displayName && displayName.length ? displayName : null,
phone: phone && phone.length ? phone : null,
},
data,
})
return { user: mapUserForClient(updated) }
})
+1 -1
View File
@@ -60,7 +60,7 @@ export async function registerUserPaymentRoutes(fastify) {
const receipt = buildReceipt({
orderItems: order.items,
deliveryFeeCents: order.deliveryFeeCents,
userEmail: userEmail,
userEmail: userEmail,
})
let result