Added AP subscription
This commit is contained in:
parent
4f838fea26
commit
b3d05783a4
|
@ -17,13 +17,18 @@ async function getAccessPoints() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateDB(accessPoints) {
|
async function updateDB(accessPoints) {
|
||||||
|
const dbAccessPoints = []
|
||||||
|
|
||||||
for (const accessPoint of accessPoints) {
|
for (const accessPoint of accessPoints) {
|
||||||
await prisma.accessPoint.upsert({
|
dbAccessPoints.push(
|
||||||
where: { mac: accessPoint.mac },
|
await prisma.accessPoint.upsert({
|
||||||
create: accessPoint,
|
where: { mac: accessPoint.mac },
|
||||||
update: accessPoint
|
create: accessPoint,
|
||||||
})
|
update: accessPoint
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
return dbAccessPoints
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateAccessPoints() {
|
export async function updateAccessPoints() {
|
||||||
|
@ -34,7 +39,7 @@ export async function updateAccessPoints() {
|
||||||
|
|
||||||
const accessPoints = await getAccessPoints()
|
const accessPoints = await getAccessPoints()
|
||||||
|
|
||||||
await updateDB(accessPoints)
|
const dbAccessPoints = await updateDB(accessPoints)
|
||||||
|
|
||||||
pubsub.publish(ACCESS_POINTS_UPDATED, { accessPointsUpdated: accessPoints })
|
pubsub.publish(ACCESS_POINTS_UPDATED, { accessPointsUpdated: dbAccessPoints })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
import { pubsub, USER_PRESENCE_UPDATED, AUTH_UPDATED } from '../../pubsub'
|
import {
|
||||||
|
pubsub,
|
||||||
|
USER_PRESENCE_UPDATED,
|
||||||
|
AUTH_UPDATED,
|
||||||
|
ACCESS_POINTS_UPDATED
|
||||||
|
} from '../../pubsub'
|
||||||
import { withFilter } from 'apollo-server'
|
import { withFilter } from 'apollo-server'
|
||||||
import { validateToken } from '../../utils/validateToken'
|
import { validateToken } from '../../utils/validateToken'
|
||||||
|
|
||||||
|
@ -6,6 +11,9 @@ const Subscription = {
|
||||||
userPresenceUpdated: {
|
userPresenceUpdated: {
|
||||||
subscribe: () => pubsub.asyncIterator([USER_PRESENCE_UPDATED])
|
subscribe: () => pubsub.asyncIterator([USER_PRESENCE_UPDATED])
|
||||||
},
|
},
|
||||||
|
accessPointsUpdated: {
|
||||||
|
subscribe: () => pubsub.asyncIterator([ACCESS_POINTS_UPDATED])
|
||||||
|
},
|
||||||
authUpdated: {
|
authUpdated: {
|
||||||
subscribe: withFilter(
|
subscribe: withFilter(
|
||||||
() => pubsub.asyncIterator([AUTH_UPDATED]),
|
() => pubsub.asyncIterator([AUTH_UPDATED]),
|
||||||
|
|
|
@ -104,6 +104,9 @@ const typeDefs = gql`
|
||||||
|
|
||||||
"Info about the logged user was updated"
|
"Info about the logged user was updated"
|
||||||
authUpdated: User! @auth
|
authUpdated: User! @auth
|
||||||
|
|
||||||
|
"Access Points were updated"
|
||||||
|
accessPointsUpdated: [AccessPoint!]!
|
||||||
}
|
}
|
||||||
|
|
||||||
"Needs authentication. Optionally, provide an array with roles to match."
|
"Needs authentication. Optionally, provide an array with roles to match."
|
||||||
|
|
Loading…
Reference in New Issue
Block a user