From 322f1c46071078a0fd28ce465c3f8ce82b697d2b Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 7 Jun 2023 23:29:26 -0400 Subject: [PATCH] refactor(striker-ui-api): rearrange GET network-interface handler --- .../network-interface/getNetworkInterface.ts | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/striker-ui-api/src/lib/request_handlers/network-interface/getNetworkInterface.ts b/striker-ui-api/src/lib/request_handlers/network-interface/getNetworkInterface.ts index 6c70a3ba..0b1e115b 100644 --- a/striker-ui-api/src/lib/request_handlers/network-interface/getNetworkInterface.ts +++ b/striker-ui-api/src/lib/request_handlers/network-interface/getNetworkInterface.ts @@ -1,10 +1,32 @@ -import { toHostUUID } from '../../convertHostUUID'; +import { DELETED, LOCAL } from '../../consts'; import buildGetRequestHandler from '../buildGetRequestHandler'; +import { toHostUUID } from '../../convertHostUUID'; export const getNetworkInterface = buildGetRequestHandler( - ({ params: { hostUUID: rawHostUUID } }, buildQueryOptions) => { - const hostUUID = toHostUUID(rawHostUUID ?? 'local'); + (request, buildQueryOptions) => { + const { + params: { hostUUID: rHostUUID = LOCAL }, + } = request; + + const hostUUID = toHostUUID(rHostUUID); + + const query = ` + SELECT + network_interface_uuid, + network_interface_mac_address, + network_interface_name, + CASE + WHEN network_interface_link_state = '1' + AND network_interface_operational = 'up' + THEN 'up' + ELSE 'down' + END AS network_interface_state, + network_interface_speed, + ROW_NUMBER() OVER(ORDER BY modified_date ASC) AS network_interface_order + FROM network_interfaces + WHERE network_interface_operational != '${DELETED}' + AND network_interface_host_uuid = '${hostUUID}';`; if (buildQueryOptions) { buildQueryOptions.afterQueryReturn = (queryStdout) => { @@ -34,21 +56,6 @@ export const getNetworkInterface = buildGetRequestHandler( }; } - return ` - SELECT - network_interface_uuid, - network_interface_mac_address, - network_interface_name, - CASE - WHEN network_interface_link_state = '1' - AND network_interface_operational = 'up' - THEN 'up' - ELSE 'down' - END AS network_interface_state, - network_interface_speed, - ROW_NUMBER() OVER(ORDER BY modified_date ASC) AS network_interface_order - FROM network_interfaces - WHERE network_interface_operational != 'DELETED' - AND network_interface_host_uuid = '${hostUUID}';`; + return query; }, );