Refactor
This commit is contained in:
parent
8f2ab2ba45
commit
33233f5947
|
@ -1,7 +1,7 @@
|
|||
import prisma from '../prisma'
|
||||
import { ACCESS_POINTS_UPDATED, pubsub } from '../pubsub'
|
||||
import { getAccessPoints as getCiscoAccessPoints } from './ciscoController'
|
||||
import { logInfo } from './logger'
|
||||
import { logInfo, logSuccess } from './logger'
|
||||
import { getAccessPoints as getUnifiAccessPoints } from './unifiController'
|
||||
|
||||
async function getAccessPoints() {
|
||||
|
@ -37,18 +37,16 @@ export async function updateAccessPoints() {
|
|||
message: 'Atualizando informações dos APs'
|
||||
})
|
||||
|
||||
const accessPoints = await getAccessPoints()
|
||||
const onlineAccessPoints = await getAccessPoints()
|
||||
|
||||
const updatedAccessPoints = await updateDB(accessPoints)
|
||||
await updateDB(onlineAccessPoints)
|
||||
|
||||
const dbAccessPoints = await prisma.accessPoint.findMany()
|
||||
|
||||
const offLineAps = dbAccessPoints.filter(dbAccessPoint => !updatedAccessPoints.find(updatedAccessPoint => updatedAccessPoint.mac === dbAccessPoint.mac))
|
||||
const onlineAccessPointsMACs = onlineAccessPoints.map(ap => ap.mac)
|
||||
|
||||
await prisma.accessPoint.updateMany({
|
||||
where: {
|
||||
mac: {
|
||||
in: offLineAps.map(offLineAccessPoint => offLineAccessPoint.mac)
|
||||
notIn: onlineAccessPointsMACs
|
||||
}
|
||||
},
|
||||
data: {
|
||||
|
@ -56,6 +54,20 @@ export async function updateAccessPoints() {
|
|||
}
|
||||
})
|
||||
|
||||
const updatedDbAccessPoints = await prisma.accessPoint.findMany({
|
||||
include: {
|
||||
wifiDevices: {
|
||||
where: {
|
||||
status: 'ONLINE'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
pubsub.publish(ACCESS_POINTS_UPDATED, { accessPointsUpdated: dbAccessPoints })
|
||||
pubsub.publish(ACCESS_POINTS_UPDATED, { accessPointsUpdated: updatedDbAccessPoints })
|
||||
|
||||
logSuccess({
|
||||
tags: ['accessPoints', 'updateAccessPoints'],
|
||||
message: `${updatedDbAccessPoints.length} APs atualizados`
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@ async function log(
|
|||
const entryTags = tags.length ? ` [${tags}] ` : ''
|
||||
|
||||
console.log(
|
||||
`${color}[${format(now, 'HH:mm:ss')}]${
|
||||
entryTags ? entryTags : ''
|
||||
`${color}[${format(now, 'HH:mm:ss')}]${entryTags ? entryTags : ''
|
||||
}\x1b[0m${message}`
|
||||
)
|
||||
|
||||
|
|
|
@ -2,15 +2,21 @@ import prisma from "../prisma";
|
|||
import { getSubnetInfo } from "../utils/subnetInfo";
|
||||
|
||||
export const AccessPoint = {
|
||||
updatedAt: parent => parent.updatedAt?.toISOString(),
|
||||
clients: parent => prisma.wifiDevice.count({
|
||||
where: {
|
||||
status: 'ONLINE',
|
||||
accessPoint: {
|
||||
id: parent.id
|
||||
updatedAt: (parent, data, context, info) => parent.updatedAt?.toISOString(),
|
||||
|
||||
async clients(parent, data, context, info) {
|
||||
|
||||
const clientsCount = await prisma.wifiDevice.count({
|
||||
where: {
|
||||
status: 'ONLINE',
|
||||
accessPoint: {
|
||||
id: parent.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
return clientsCount;
|
||||
},
|
||||
subnetInfo: parent => getSubnetInfo(parent.ip)
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ export async function updateAccessPoint(
|
|||
})
|
||||
|
||||
logInfo({
|
||||
tags: ['accessPointUpdated', 'accessPoints'],
|
||||
tags: ['accessPointEdited', 'accessPoints'],
|
||||
message: `O usuário ${auth.displayName} (${auth.sAMAccountName}) atualizou as informações do AP ${accessPoint.name || accessPoint.hostname}`,
|
||||
data: accessPoint
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import prisma from '../../prisma'
|
||||
|
||||
const MAX_RESULT = 5000
|
||||
const MAX_RESULT = 1000
|
||||
|
||||
export async function logs(parent, { search, dateIn, dateOut, limit = 100 }) {
|
||||
try {
|
||||
|
@ -16,9 +16,9 @@ export async function logs(parent, { search, dateIn, dateOut, limit = 100 }) {
|
|||
},
|
||||
OR: search
|
||||
? [
|
||||
{ message: { contains: search, mode: 'insensitive' } },
|
||||
{ tags: { contains: search, mode: 'insensitive' } }
|
||||
]
|
||||
{ message: { contains: search, mode: 'insensitive' } },
|
||||
{ tags: { contains: search, mode: 'insensitive' } }
|
||||
]
|
||||
: undefined
|
||||
},
|
||||
orderBy: { timestamp: 'desc' },
|
||||
|
|
Loading…
Reference in New Issue
Block a user