refactor(striker-ui-api): rearrange GET network-interface handler

main
Tsu-ba-me 2 years ago
parent 8b828f81a5
commit 322f1c4607
  1. 45
      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;
},
);

Loading…
Cancel
Save