Make site and domain optional and get rid of "<unknown>" values.

This commit is contained in:
baldo 2022-07-28 12:24:07 +02:00
parent 72543b95ee
commit 2d83326b78
2 changed files with 14 additions and 12 deletions

View file

@ -19,8 +19,10 @@ import {
Domain, Domain,
DurationSeconds, DurationSeconds,
Hostname, Hostname,
isDomain,
isMonitoringSortField, isMonitoringSortField,
isOnlineState, isOnlineState,
isSite,
MAC, MAC,
MailType, MailType,
MonitoringSortField, MonitoringSortField,
@ -71,8 +73,8 @@ export type ParsedNode = {
importTimestamp: UnixTimestampSeconds, importTimestamp: UnixTimestampSeconds,
state: OnlineState, state: OnlineState,
lastSeen: UnixTimestampSeconds, lastSeen: UnixTimestampSeconds,
site: Site, site?: Site,
domain: Domain, domain?: Domain,
}; };
export type NodesParsingResult = { export type NodesParsingResult = {
@ -224,14 +226,14 @@ export function parseNode(importTimestamp: UnixTimestampSeconds, nodeData: any):
); );
} }
let site = "<unknown-site>" as Site; // FIXME: Handle this let site: Site | undefined;
if (_.isPlainObject(nodeData.nodeinfo.system) && _.isString(nodeData.nodeinfo.system.site_code)) { if (_.isPlainObject(nodeData.nodeinfo.system) && isSite(nodeData.nodeinfo.system.site_code)) {
site = nodeData.nodeinfo.system.site_code as Site; site = nodeData.nodeinfo.system.site_code;
} }
let domain = "<unknown-domain>" as Domain; // FIXME: Handle this let domain: Domain | undefined;
if (_.isPlainObject(nodeData.nodeinfo.system) && _.isString(nodeData.nodeinfo.system.domain_code)) { if (_.isPlainObject(nodeData.nodeinfo.system) && isDomain(nodeData.nodeinfo.system.domain_code)) {
domain = nodeData.nodeinfo.system.domain_code as Domain; domain = nodeData.nodeinfo.system.domain_code;
} }
return { return {
@ -611,8 +613,8 @@ export async function getByMacs(macs: MAC[]): Promise<Record<MAC, NodeStateData>
} }
nodeStateByMac[row.mac] = { nodeStateByMac[row.mac] = {
site: row.site || "<unknown-site>" as Site, // FIXME: Handle this site: row.site || undefined,
domain: row.domain || "<unknown-domain>" as Domain, // FIXME: Handle this domain: row.domain || undefined,
state: onlineState, state: onlineState,
}; };
} }

View file

@ -23,8 +23,8 @@ export * from "./logger";
export * from "./shared"; export * from "./shared";
export type NodeStateData = { export type NodeStateData = {
site: Site, site?: Site,
domain: Domain, domain?: Domain,
state: OnlineState, state: OnlineState,
} }