diff --git a/server/.gitignore b/server/.gitignore index 585f2c7..4a8c9eb 100755 --- a/server/.gitignore +++ b/server/.gitignore @@ -4,4 +4,6 @@ config/ dist/ generated/ -node_modules/ \ No newline at end of file +node_modules/ +* +.log diff --git a/server/src/resolvers/Mutation/updateAccessPoint.js b/server/src/resolvers/Mutation/updateAccessPoint.js index a27b4fe..22ed170 100644 --- a/server/src/resolvers/Mutation/updateAccessPoint.js +++ b/server/src/resolvers/Mutation/updateAccessPoint.js @@ -4,23 +4,19 @@ import { ACCESS_POINTS_UPDATED, pubsub } from '../../pubsub' import { logError, logInfo } from '../../lib/logger' import { getSubnetInfo } from '../../utils/subnetInfo' -export async function updateAccessPoint( - parent, - { data: { id, name, local, notes } }, - { auth }, - info -) { - +export async function updateAccessPoint(_, { data: { id, name, local, notes } }, { auth },) { const accessPoint = await prisma.accessPoint.findUnique({ where: { id: parseInt(id) }, }) + if (!accessPoint) throw new Error('Access Point não encontrado') + if (getSubnetInfo(accessPoint.ip).shortName !== auth.campus) { logError({ tags: ['accessPointEdited', 'accessPoints'], - message: `O usuário ${auth.displayName} (${auth.sAMAccountName}) tentou atualizar as informações do AP ${updatedAccessPoint.name || updatedAccessPoint.hostname}, mas não tinha permissão.`, - data: updatedAccessPoint + message: `O usuário ${auth.displayName} (${auth.sAMAccountName}) tentou atualizar as informações do + AP ${accessPoint.name || accessPoint.hostname}, mas não tinha permissão.` }) - throw new Error(`O AP ${accessPoint.name || accessPoint.hostname} não está na rede do campus ${auth.campus}. Você só pode editar APs da rede do seu campus.`) + throw new Error(`O AP ${accessPoint.name || accessPoint.hostname} não está na rede do campus ${auth.campus}. Você só pode editar APs da rede do seu campus.`) } const updatedAccessPoint = await prisma.accessPoint.update({