34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { requireAuth } from '~/server/utils/auth'
|
|
import { prisma } from '~/server/utils/prisma'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const user = requireAuth(event)
|
|
const id = getRouterParam(event, 'id')
|
|
const body = await readBody(event)
|
|
|
|
// Проверяем права: только владелец может менять настройки доступа
|
|
const canvas = await prisma.canvas.findUnique({
|
|
where: { id }
|
|
})
|
|
|
|
if (!canvas) {
|
|
throw createError({ statusCode: 404, message: 'Canvas not found' })
|
|
}
|
|
|
|
if (canvas.ownerId !== user.id && user.role !== 'admin') {
|
|
throw createError({ statusCode: 403, message: 'Only owner can change settings' })
|
|
}
|
|
|
|
// Обновляем поля
|
|
const updatedCanvas = await prisma.canvas.update({
|
|
where: { id },
|
|
data: {
|
|
name: body.name !== undefined ? body.name : undefined,
|
|
isPublic: body.isPublic !== undefined ? body.isPublic : undefined,
|
|
groupId: body.groupId !== undefined ? body.groupId : undefined,
|
|
}
|
|
})
|
|
|
|
return { success: true, canvas: updatedCanvas }
|
|
})
|