Edit Access Point OK

This commit is contained in:
Douglas Barone 2022-03-31 15:35:48 -04:00
parent f14292c8bd
commit 128de54b9b
4 changed files with 73 additions and 4 deletions

View File

@ -10,6 +10,8 @@ import { updateAccessPoints } from '../../lib/accessPoints'
import prisma from '../../prisma' import prisma from '../../prisma'
import { ACCESS_POINTS_UPDATED, pubsub } from '../../pubsub'
const Mutation = { const Mutation = {
async login(parent, { data }) { async login(parent, { data }) {
return User.login(data.username, data.password) return User.login(data.username, data.password)
@ -121,6 +123,29 @@ const Mutation = {
}) })
throw e 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
} }
} }

View File

@ -103,6 +103,10 @@ const typeDefs = gql`
"Force Update Access Points" "Force Update Access Points"
updateAccessPoints: String! @auth(roles: ["superAdmin"]) updateAccessPoints: String! @auth(roles: ["superAdmin"])
"Update an Access Point"
updateAccessPoint(data: UpdateAccessPointInput): AccessPoint!
@auth(roles: ["superAdmin"])
} }
type Subscription { type Subscription {
@ -357,6 +361,13 @@ const typeDefs = gql`
description: String! description: String!
note: String note: String
} }
input UpdateAccessPointInput {
id: ID!
name: String
local: String
notes: String
}
` `
export { typeDefs } export { typeDefs }

View File

@ -17,14 +17,16 @@
label="Nome" label="Nome"
hint="Nome amigável ou apelido (opcional)" hint="Nome amigável ou apelido (opcional)"
outlined outlined
clearable
/> />
<v-text-field <v-text-field
v-model="local" v-model="local"
label="Local" label="Local"
hint="Localização aproximada (opcional)" hint="Localização aproximada (opcional)"
outlined outlined
clearable
/> />
<v-textarea v-model="notes" label="Observações" outlined /> <v-textarea v-model="notes" label="Observações" outlined clearable />
<v-card-actions> <v-card-actions>
<v-spacer /> <v-spacer />
<v-btn color="primary" @click="onUpdateAccessPoint"> <v-btn color="primary" @click="onUpdateAccessPoint">
@ -63,7 +65,38 @@ export default {
} }
}, },
methods: { 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: { apollo: {
accessPoint: { accessPoint: {

View File

@ -62,6 +62,7 @@
:search="search" :search="search"
calculate-widths calculate-widths
class="elevation-1" class="elevation-1"
sort-by="ip"
:footer-props="{ itemsPerPageOptions: [10, 25, 50, 100, 150] }" :footer-props="{ itemsPerPageOptions: [10, 25, 50, 100, 150] }"
> >
<template #[`item.name`]="{ item }"> <template #[`item.name`]="{ item }">
@ -154,8 +155,7 @@ export default {
'clients', 'clients',
'uptime', 'uptime',
'updatedAt', 'updatedAt',
// 'notes', 'notes',
'controller',
'mac' 'mac'
], ],
allHeaders: [ allHeaders: [