From 128de54b9b4be27e966a3777427ad4927bc2e910 Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Thu, 31 Mar 2022 15:35:48 -0400 Subject: [PATCH] Edit Access Point OK --- server/src/resolvers/Mutation/index.js | 25 +++++++++++++++++ server/src/typeDefs.js | 11 ++++++++ web/src/views/AccessPoints/edit.vue | 37 ++++++++++++++++++++++++-- web/src/views/AccessPoints/index.vue | 4 +-- 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/server/src/resolvers/Mutation/index.js b/server/src/resolvers/Mutation/index.js index 6891ec3..a2da034 100644 --- a/server/src/resolvers/Mutation/index.js +++ b/server/src/resolvers/Mutation/index.js @@ -10,6 +10,8 @@ import { updateAccessPoints } from '../../lib/accessPoints' import prisma from '../../prisma' +import { ACCESS_POINTS_UPDATED, pubsub } from '../../pubsub' + const Mutation = { async login(parent, { data }) { return User.login(data.username, data.password) @@ -121,6 +123,29 @@ const Mutation = { }) throw e } + }, + async updateAccessPoint( + parent, + { data: { id, name, local, notes } }, + context, + info + ) { + console.log(id, name, local, notes) + + const accessPoint = await prisma.accessPoint.update({ + where: { id: parseInt(id) }, + data: { name, local, notes } + }) + + const accessPoints = await prisma.accessPoint.findMany({ + include: { wifiDevices: true } + }) + + pubsub.publish(ACCESS_POINTS_UPDATED, { + accessPointsUpdated: accessPoints + }) + + return accessPoint } } diff --git a/server/src/typeDefs.js b/server/src/typeDefs.js index 30e4d83..4cd7b06 100644 --- a/server/src/typeDefs.js +++ b/server/src/typeDefs.js @@ -103,6 +103,10 @@ const typeDefs = gql` "Force Update Access Points" updateAccessPoints: String! @auth(roles: ["superAdmin"]) + + "Update an Access Point" + updateAccessPoint(data: UpdateAccessPointInput): AccessPoint! + @auth(roles: ["superAdmin"]) } type Subscription { @@ -357,6 +361,13 @@ const typeDefs = gql` description: String! note: String } + + input UpdateAccessPointInput { + id: ID! + name: String + local: String + notes: String + } ` export { typeDefs } diff --git a/web/src/views/AccessPoints/edit.vue b/web/src/views/AccessPoints/edit.vue index 00d03f2..749dc64 100644 --- a/web/src/views/AccessPoints/edit.vue +++ b/web/src/views/AccessPoints/edit.vue @@ -17,14 +17,16 @@ label="Nome" hint="Nome amigável ou apelido (opcional)" outlined + clearable /> - + @@ -63,7 +65,38 @@ export default { } }, methods: { - onUpdateAccessPoint() {} + async onUpdateAccessPoint() { + this.errors = [] + this.loading = true + try { + await this.$apollo.mutate({ + mutation: gql` + mutation ($id: ID!, $name: String, $local: String, $notes: String) { + updateAccessPoint( + data: { id: $id, name: $name, local: $local, notes: $notes } + ) { + id + name + local + notes + } + } + `, + variables: { + id: this.$route.params.id, + name: this.name, + local: this.local, + notes: this.notes + } + }) + + this.$router.push({ name: 'access-points' }) + } catch (e) { + this.errors = e.graphQLErrors.map(error => error.message) + } finally { + this.loading = false + } + } }, apollo: { accessPoint: { diff --git a/web/src/views/AccessPoints/index.vue b/web/src/views/AccessPoints/index.vue index ea40c96..adcf26f 100644 --- a/web/src/views/AccessPoints/index.vue +++ b/web/src/views/AccessPoints/index.vue @@ -62,6 +62,7 @@ :search="search" calculate-widths class="elevation-1" + sort-by="ip" :footer-props="{ itemsPerPageOptions: [10, 25, 50, 100, 150] }" >