From 1fec480af7e02d93537e9c74db0e1651127d4971 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 20 Oct 2022 21:56:38 -0400 Subject: [PATCH] fix(striker-ui-api): rename buildCondition functions --- striker-ui-api/src/lib/buildCondition.ts | 19 +++++++++++-------- .../src/lib/request_handlers/host/getHost.ts | 4 ++-- .../host/getHostConnection.ts | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/striker-ui-api/src/lib/buildCondition.ts b/striker-ui-api/src/lib/buildCondition.ts index 5bafdd65..81877444 100644 --- a/striker-ui-api/src/lib/buildCondition.ts +++ b/striker-ui-api/src/lib/buildCondition.ts @@ -2,7 +2,7 @@ import join from './join'; import { sanitizeQS } from './sanitizeQS'; const buildIDCondition = ( - ids: Parameters[0], + keys: Parameters[0], conditionPrefix: string, { onFallback = () => '', @@ -10,24 +10,27 @@ const buildIDCondition = ( result ? `${conditionPrefix} IN (${result})` : onFallback(), }: Pick & { onFallback?: () => string } = {}, ) => - join(ids, { + join(keys, { beforeReturn, elementWrapper: "'", separator: ', ', }) as string; -export const buildQSIDCondition = ( - ids: unknown, +export const buildUnknownIDCondition = ( + keys: unknown, conditionPrefix: string, { onFallback = () => '' }: { onFallback?: () => string }, ): { after: string; before: string[] } => { - const before = sanitizeQS(ids, { isForSQL: true, returnType: 'string[]' }); + const before = sanitizeQS(keys, { + modifierType: 'sql', + returnType: 'string[]', + }); const after = buildIDCondition(before, conditionPrefix, { onFallback }); return { after, before }; }; -export const buildParamIDCondition = ( - ids: string[] | '*' = '*', +export const buildKnownIDCondition = ( + keys: string[] | '*' = '*', conditionPrefix: string, -) => (ids[0] === '*' ? '' : buildIDCondition(ids, conditionPrefix)); +) => (keys[0] === '*' ? '' : buildIDCondition(keys, conditionPrefix)); diff --git a/striker-ui-api/src/lib/request_handlers/host/getHost.ts b/striker-ui-api/src/lib/request_handlers/host/getHost.ts index a4b90a8d..16d32f34 100644 --- a/striker-ui-api/src/lib/request_handlers/host/getHost.ts +++ b/striker-ui-api/src/lib/request_handlers/host/getHost.ts @@ -1,12 +1,12 @@ import { getLocalHostUUID } from '../../accessModule'; import buildGetRequestHandler from '../buildGetRequestHandler'; -import { buildQSIDCondition } from '../../buildCondition'; +import { buildUnknownIDCondition } from '../../buildCondition'; export const getHost = buildGetRequestHandler((request, buildQueryOptions) => { const { hostUUIDs } = request.query; const hostUUIDField = 'hos.host_uuid'; - const { after: condHostUUIDs } = buildQSIDCondition( + const { after: condHostUUIDs } = buildUnknownIDCondition( hostUUIDs, hostUUIDField, { diff --git a/striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts b/striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts index 0bd0f2c9..c21ba866 100644 --- a/striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts +++ b/striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts @@ -1,5 +1,5 @@ import { getAnvilData, getLocalHostUUID } from '../../accessModule'; -import { buildQSIDCondition } from '../../buildCondition'; +import { buildUnknownIDCondition } from '../../buildCondition'; import buildGetRequestHandler from '../buildGetRequestHandler'; const buildHostConnections = ( @@ -59,7 +59,7 @@ export const getHostConnection = buildGetRequestHandler( const hostUUIDField = 'ip_add.ip_address_host_uuid'; const { after: condHostUUIDs, before: beforeBuildIDCond } = - buildQSIDCondition(rawHostUUIDs, hostUUIDField, { + buildUnknownIDCondition(rawHostUUIDs, hostUUIDField, { onFallback: () => `${hostUUIDField} = '${localHostUUID}'`, }); const hostUUIDs =