fix(striker-ui-api): filter /host with host type(s)

main
Tsu-ba-me 2 years ago
parent 11aa7f548f
commit 271b33eaf7
  1. 2
      striker-ui-api/src/lib/buildCondition.ts
  2. 21
      striker-ui-api/src/lib/request_handlers/host/getHost.ts
  3. 1
      striker-ui-api/src/types/HostOverview.d.ts

@ -22,7 +22,7 @@ const buildIDCondition = (
export const buildUnknownIDCondition = (
keys: unknown,
conditionPrefix: string,
{ onFallback }: { onFallback?: () => string },
{ onFallback }: { onFallback?: () => string } = {},
): { after: string; before: string[] } => {
const before = sanitize(keys, 'string[]', {
modifierType: 'sql',

@ -1,4 +1,5 @@
import { getLocalHostUUID } from '../../accessModule';
import { buildUnknownIDCondition } from '../../buildCondition';
import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryHostDetail } from './buildQueryHostDetail';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
@ -7,22 +8,36 @@ import { getShortHostName } from '../../getShortHostName';
import { sanitize } from '../../sanitize';
export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
const { hostUUIDs } = request.query;
const { hostUUIDs, types: hostTypes } = request.query;
const localHostUUID: string = getLocalHostUUID();
const { after: typeCondition } = buildUnknownIDCondition(
hostTypes,
'hos.host_type',
);
let condition = '';
if (typeCondition.length > 0) {
condition += `WHERE ${typeCondition}`;
}
let query = `
SELECT
hos.host_name,
hos.host_type,
hos.host_uuid
FROM hosts AS hos;`;
FROM hosts AS hos
${condition};`;
let afterQueryReturn: QueryResultModifierFunction | undefined =
buildQueryResultReducer<{ [hostUUID: string]: HostOverview }>(
(previous, [hostName, hostUUID]) => {
(previous, [hostName, hostType, hostUUID]) => {
const key = toLocal(hostUUID, localHostUUID);
previous[key] = {
hostName,
hostType,
hostUUID,
shortHostName: getShortHostName(hostName),
};

@ -1,5 +1,6 @@
type HostOverview = {
hostName: string;
hostType: string;
hostUUID: string;
shortHostName: string;
};

Loading…
Cancel
Save