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