test commit

This commit is contained in:
Kirill
2026-05-21 12:02:29 +05:00
parent ae6f86041a
commit 1837b36b14
10 changed files with 113 additions and 45 deletions
+14
View File
@@ -92,6 +92,7 @@ export async function registerAdminUserRoutes(fastify) {
fastify.patch('/api/admin/users/:id', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
const { id } = request.params
const body = request.body ?? {}
const adminUserId = request.user.sub
const existing = await prisma.user.findUnique({ where: { id } })
if (!existing) {
@@ -99,9 +100,15 @@ export async function registerAdminUserRoutes(fastify) {
return
}
const isSelf = id === adminUserId
const data = {}
if (body.email !== undefined) {
if (isSelf) {
reply.code(403).send({ error: 'Нельзя изменить свою почту через панель администратора' })
return
}
const email = normalizeEmail(body.email)
if (!email || !email.includes('@')) {
reply.code(400).send({ error: 'Некорректная почта' })
@@ -139,6 +146,13 @@ export async function registerAdminUserRoutes(fastify) {
fastify.delete('/api/admin/users/:id', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
const { id } = request.params
const adminUserId = request.user.sub
if (id === adminUserId) {
reply.code(403).send({ error: 'Нельзя удалить свою учётную запись' })
return
}
try {
await prisma.user.delete({ where: { id } })
reply.code(204).send()