fix(striker-ui-api): rename buildCondition functions

main
Tsu-ba-me 2 years ago
parent e38864e256
commit 1fec480af7
  1. 19
      striker-ui-api/src/lib/buildCondition.ts
  2. 4
      striker-ui-api/src/lib/request_handlers/host/getHost.ts
  3. 4
      striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts

@ -2,7 +2,7 @@ import join from './join';
import { sanitizeQS } from './sanitizeQS';
const buildIDCondition = (
ids: Parameters<JoinFunction>[0],
keys: Parameters<JoinFunction>[0],
conditionPrefix: string,
{
onFallback = () => '',
@ -10,24 +10,27 @@ const buildIDCondition = (
result ? `${conditionPrefix} IN (${result})` : onFallback(),
}: Pick<JoinOptions, 'beforeReturn'> & { 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));

@ -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,
{

@ -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 =

Loading…
Cancel
Save