fix(striker-ui-api): correct ID condition in query host detail

This commit is contained in:
Tsu-ba-me 2023-10-16 05:50:36 -04:00
parent df7b5fa397
commit 78b75c649a
3 changed files with 10 additions and 4 deletions

View File

@ -33,6 +33,9 @@ export const buildUnknownIDCondition = (
}; };
export const buildKnownIDCondition = ( export const buildKnownIDCondition = (
keys: string[] | '*' = '*', keys: string[] | 'all' | '*' = 'all',
conditionPrefix: string, conditionPrefix: string,
) => (keys[0] === '*' ? '' : buildIDCondition(keys, conditionPrefix)); ) =>
!(keys instanceof Array) || keys.some((v) => ['all', '*'].includes(v))
? ''
: buildIDCondition(keys, conditionPrefix);

View File

@ -42,7 +42,7 @@ const setCvar = (
export const buildQueryHostDetail: BuildQueryDetailFunction = ({ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
keys: hostUUIDs = '*', keys: hostUUIDs = '*',
} = {}) => { } = {}) => {
const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'a.host_uuid'); const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'WHERE a.host_uuid');
stdout(`condHostUUIDs=[${condHostUUIDs}]`); stdout(`condHostUUIDs=[${condHostUUIDs}]`);
@ -74,7 +74,7 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
ON b.variable_name LIKE '%link%_mac%' ON b.variable_name LIKE '%link%_mac%'
AND b.variable_value = c.network_interface_mac_address AND b.variable_value = c.network_interface_mac_address
AND a.host_uuid = c.network_interface_host_uuid AND a.host_uuid = c.network_interface_host_uuid
WHERE ${condHostUUIDs} ${condHostUUIDs}
ORDER BY a.host_name ASC, ORDER BY a.host_name ASC,
cvar_name ASC, cvar_name ASC,
b.variable_name ASC;`; b.variable_name ASC;`;

View File

@ -49,6 +49,9 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
); );
if (hostUUIDs) { if (hostUUIDs) {
// TODO: the output of host detail is designed to only contain one
// host, correct it to support multiple hosts to allow selecting
// multiple hosts' detail.
({ query, afterQueryReturn } = buildQueryHostDetail({ ({ query, afterQueryReturn } = buildQueryHostDetail({
keys: sanitize(hostUUIDs, 'string[]', { keys: sanitize(hostUUIDs, 'string[]', {
modifierType: 'sql', modifierType: 'sql',