diff --git a/server/services/monitoringService.ts b/server/services/monitoringService.ts index e162fe6..65d0a37 100644 --- a/server/services/monitoringService.ts +++ b/server/services/monitoringService.ts @@ -19,8 +19,10 @@ import { Domain, DurationSeconds, Hostname, + isDomain, isMonitoringSortField, isOnlineState, + isSite, MAC, MailType, MonitoringSortField, @@ -71,8 +73,8 @@ export type ParsedNode = { importTimestamp: UnixTimestampSeconds, state: OnlineState, lastSeen: UnixTimestampSeconds, - site: Site, - domain: Domain, + site?: Site, + domain?: Domain, }; export type NodesParsingResult = { @@ -224,14 +226,14 @@ export function parseNode(importTimestamp: UnixTimestampSeconds, nodeData: any): ); } - let site = "" as Site; // FIXME: Handle this - if (_.isPlainObject(nodeData.nodeinfo.system) && _.isString(nodeData.nodeinfo.system.site_code)) { - site = nodeData.nodeinfo.system.site_code as Site; + let site: Site | undefined; + if (_.isPlainObject(nodeData.nodeinfo.system) && isSite(nodeData.nodeinfo.system.site_code)) { + site = nodeData.nodeinfo.system.site_code; } - let domain = "" as Domain; // FIXME: Handle this - if (_.isPlainObject(nodeData.nodeinfo.system) && _.isString(nodeData.nodeinfo.system.domain_code)) { - domain = nodeData.nodeinfo.system.domain_code as Domain; + let domain: Domain | undefined; + if (_.isPlainObject(nodeData.nodeinfo.system) && isDomain(nodeData.nodeinfo.system.domain_code)) { + domain = nodeData.nodeinfo.system.domain_code; } return { @@ -611,8 +613,8 @@ export async function getByMacs(macs: MAC[]): Promise } nodeStateByMac[row.mac] = { - site: row.site || "" as Site, // FIXME: Handle this - domain: row.domain || "" as Domain, // FIXME: Handle this + site: row.site || undefined, + domain: row.domain || undefined, state: onlineState, }; } diff --git a/server/types/index.ts b/server/types/index.ts index f409f04..04b39d8 100644 --- a/server/types/index.ts +++ b/server/types/index.ts @@ -23,8 +23,8 @@ export * from "./logger"; export * from "./shared"; export type NodeStateData = { - site: Site, - domain: Domain, + site?: Site, + domain?: Domain, state: OnlineState, }