feat(striker-ui-api): add /network-interface endpoint

main
Tsu-ba-me 2 years ago
parent 6ddc0dd5b5
commit c424980bb7
  1. 43
      striker-ui-api/src/lib/request_handlers/network-interface/getNetworkInterface.ts
  2. 1
      striker-ui-api/src/lib/request_handlers/network-interface/index.ts
  3. 2
      striker-ui-api/src/routes/index.ts
  4. 9
      striker-ui-api/src/routes/network-interface.ts
  5. 8
      striker-ui-api/src/types/NetworkInterfaceOverview.d.ts

@ -0,0 +1,43 @@
import buildGetRequestHandler from '../buildGetRequestHandler';
export const getNetworkInterface = buildGetRequestHandler(
(request, buildQueryOptions) => {
if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = (queryStdout) => {
let result = queryStdout;
if (queryStdout instanceof Array) {
result = queryStdout.map<NetworkInterfaceOverview>(
([
networkInterfaceUUID,
networkInterfaceMACAddress,
networkInterfaceName,
networkInterfaceState,
networkInterfaceSpeed,
networkInterfaceOrder,
]) => ({
networkInterfaceUUID,
networkInterfaceMACAddress,
networkInterfaceName,
networkInterfaceState,
networkInterfaceSpeed,
networkInterfaceOrder,
}),
);
}
return result;
};
}
return `
SELECT
network_interface_uuid,
network_interface_mac_address,
network_interface_name,
network_interface_operational,
network_interface_speed,
ROW_NUMBER() OVER(ORDER BY modified_date ASC) AS network_interface_order
FROM network_interfaces;`;
},
);

@ -0,0 +1 @@
export { getNetworkInterface } from './getNetworkInterface';

@ -3,12 +3,14 @@ import { Router } from 'express';
import anvilRouter from './anvil'; import anvilRouter from './anvil';
import echoRouter from './echo'; import echoRouter from './echo';
import fileRouter from './file'; import fileRouter from './file';
import networkInterfaceRouter from './network-interface';
import serverRouter from './server'; import serverRouter from './server';
const routes: Readonly<Record<string, Router>> = { const routes: Readonly<Record<string, Router>> = {
anvil: anvilRouter, anvil: anvilRouter,
echo: echoRouter, echo: echoRouter,
file: fileRouter, file: fileRouter,
'network-interface': networkInterfaceRouter,
server: serverRouter, server: serverRouter,
}; };

@ -0,0 +1,9 @@
import express from 'express';
import { getNetworkInterface } from '../lib/request_handlers/network-interface';
const router = express.Router();
router.get('/', getNetworkInterface);
export default router;

@ -0,0 +1,8 @@
type NetworkInterfaceOverview = {
networkInterfaceUUID: string;
networkInterfaceMACAddress: string;
networkInterfaceName: string;
networkInterfaceState: string;
networkInterfaceSpeed: number;
networkInterfaceOrder: number;
};
Loading…
Cancel
Save