test commit
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user