parent
c352fc5f0e
commit
de8d2ddd50
18 changed files with 169 additions and 34 deletions
@ -0,0 +1,9 @@ |
|||||||
|
const call = <T = unknown>( |
||||||
|
toCall: unknown, |
||||||
|
{ parameters = [], notCallableReturn }: CallOptions = {}, |
||||||
|
) => |
||||||
|
(typeof toCall === 'function' |
||||||
|
? toCall(...parameters) |
||||||
|
: notCallableReturn) as T; |
||||||
|
|
||||||
|
export default call; |
@ -0,0 +1,54 @@ |
|||||||
|
import buildGetRequestHandler from '../buildGetRequestHandler'; |
||||||
|
|
||||||
|
const getAnvil = buildGetRequestHandler((request, options) => { |
||||||
|
const { anvilsUUID } = request.body; |
||||||
|
|
||||||
|
let query = ` |
||||||
|
SELECT |
||||||
|
anv.anvil_name, |
||||||
|
anv.anvil_uuid, |
||||||
|
hos.host_name, |
||||||
|
hos.host_uuid |
||||||
|
FROM anvils AS anv |
||||||
|
JOIN hosts AS hos |
||||||
|
ON anv.anvil_uuid = hos.host_anvil_uuid;`;
|
||||||
|
|
||||||
|
if (options) { |
||||||
|
options.afterQueryReturn = (queryStdout) => { |
||||||
|
let results = queryStdout; |
||||||
|
|
||||||
|
if (queryStdout instanceof Array) { |
||||||
|
let rowStage: AnvilOverview; |
||||||
|
|
||||||
|
results = queryStdout.reduce<AnvilOverview[]>( |
||||||
|
(reducedRows, [anvilName, anvilUUID, hostName, hostUUID]) => { |
||||||
|
if (rowStage && anvilUUID === rowStage.anvilUUID) { |
||||||
|
rowStage.hosts.push({ hostName, hostUUID }); |
||||||
|
} else { |
||||||
|
rowStage = { |
||||||
|
anvilName, |
||||||
|
anvilUUID, |
||||||
|
hosts: [], |
||||||
|
}; |
||||||
|
|
||||||
|
reducedRows.push(rowStage); |
||||||
|
} |
||||||
|
|
||||||
|
return reducedRows; |
||||||
|
}, |
||||||
|
[], |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
return results; |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
if (anvilsUUID) { |
||||||
|
query = 'SELECT * FROM anvils;'; |
||||||
|
} |
||||||
|
|
||||||
|
return query; |
||||||
|
}); |
||||||
|
|
||||||
|
export default getAnvil; |
@ -1,8 +1,8 @@ |
|||||||
import buildGetRequestHandler from '../buildGetRequestHandler'; |
import buildGetRequestHandler from '../buildGetRequestHandler'; |
||||||
import buildQueryFilesDetail from './buildQueryFilesDetail'; |
import buildQueryFileDetail from './buildQueryFileDetail'; |
||||||
|
|
||||||
const getFileDetail = buildGetRequestHandler((request) => |
const getFileDetail = buildGetRequestHandler((request) => |
||||||
buildQueryFilesDetail({ filesUUID: [request.params.fileUUID] }), |
buildQueryFileDetail({ filesUUID: [request.params.fileUUID] }), |
||||||
); |
); |
||||||
|
|
||||||
export default getFileDetail; |
export default getFileDetail; |
@ -0,0 +1,9 @@ |
|||||||
|
import express from 'express'; |
||||||
|
|
||||||
|
import getAnvil from '../lib/request_handlers/anvil/getAnvil'; |
||||||
|
|
||||||
|
const router = express.Router(); |
||||||
|
|
||||||
|
router.get('/', getAnvil); |
||||||
|
|
||||||
|
export default router; |
@ -1,5 +1,15 @@ |
|||||||
|
import { Router } from 'express'; |
||||||
|
|
||||||
|
import anvilRouter from './anvil'; |
||||||
import echoRouter from './echo'; |
import echoRouter from './echo'; |
||||||
import filesRouter from './files'; |
import fileRouter from './file'; |
||||||
import serversRouter from './servers'; |
import serverRouter from './server'; |
||||||
|
|
||||||
|
const routes: Readonly<Record<string, Router>> = { |
||||||
|
anvil: anvilRouter, |
||||||
|
echo: echoRouter, |
||||||
|
file: fileRouter, |
||||||
|
server: serverRouter, |
||||||
|
}; |
||||||
|
|
||||||
export { echoRouter, filesRouter, serversRouter }; |
export default routes; |
||||||
|
@ -0,0 +1,9 @@ |
|||||||
|
import express from 'express'; |
||||||
|
|
||||||
|
import getServer from '../lib/request_handlers/server/getServer'; |
||||||
|
|
||||||
|
const router = express.Router(); |
||||||
|
|
||||||
|
router.get('/', getServer); |
||||||
|
|
||||||
|
export default router; |
@ -1,9 +0,0 @@ |
|||||||
import express from 'express'; |
|
||||||
|
|
||||||
import getServers from '../lib/request_handlers/servers/getServers'; |
|
||||||
|
|
||||||
const router = express.Router(); |
|
||||||
|
|
||||||
router.get('/', getServers); |
|
||||||
|
|
||||||
export default router; |
|
@ -0,0 +1,8 @@ |
|||||||
|
type AnvilOverview = { |
||||||
|
anvilName: string; |
||||||
|
anvilUUID: string; |
||||||
|
hosts: Array<{ |
||||||
|
hostName: string; |
||||||
|
hostUUID: string; |
||||||
|
}>; |
||||||
|
}; |
@ -0,0 +1,3 @@ |
|||||||
|
type BuildGetRequestHandlerOptions = { |
||||||
|
beforeRespond?: (queryStdout: unknown) => unknown; |
||||||
|
}; |
@ -0,0 +1,8 @@ |
|||||||
|
type BuildQueryOptions = { |
||||||
|
afterQueryReturn?: (queryStdout: unknown) => unknown; |
||||||
|
}; |
||||||
|
|
||||||
|
type BuildQueryFunction = ( |
||||||
|
request: import('express').Request, |
||||||
|
options?: BuildQueryOptions, |
||||||
|
) => string; |
@ -0,0 +1,4 @@ |
|||||||
|
type CallOptions = { |
||||||
|
parameters?: unknown[]; |
||||||
|
notCallableReturn?: unknown; |
||||||
|
}; |
Loading…
Reference in new issue