fix(striker-ui-api): include missed hosts in /anvil GET

main
Tsu-ba-me 3 years ago
parent de8d2ddd50
commit cf5cba3950
  1. 31
      striker-ui-api/src/lib/request_handlers/anvil/getAnvil.ts
  2. 12
      striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts

@ -11,29 +11,36 @@ const getAnvil = buildGetRequestHandler((request, options) => {
hos.host_uuid hos.host_uuid
FROM anvils AS anv FROM anvils AS anv
JOIN hosts AS hos JOIN hosts AS hos
ON anv.anvil_uuid = hos.host_anvil_uuid;`; ON hos.host_uuid IN (
anv.anvil_node1_host_uuid,
anv.anvil_node2_host_uuid,
anv.anvil_dr1_host_uuid
)
ORDER BY anv.anvil_uuid;`;
if (options) { if (options) {
options.afterQueryReturn = (queryStdout) => { options.afterQueryReturn = (queryStdout) => {
let results = queryStdout; let results = queryStdout;
if (queryStdout instanceof Array) { if (queryStdout instanceof Array) {
let rowStage: AnvilOverview; let rowStage: AnvilOverview | undefined;
results = queryStdout.reduce<AnvilOverview[]>( results = queryStdout.reduce<AnvilOverview[]>(
(reducedRows, [anvilName, anvilUUID, hostName, hostUUID]) => { (reducedRows, [anvilName, anvilUUID, hostName, hostUUID]) => {
if (rowStage && anvilUUID === rowStage.anvilUUID) { if (!rowStage || anvilUUID !== rowStage.anvilUUID) {
rowStage.hosts.push({ hostName, hostUUID }); {
} else { rowStage = {
rowStage = { anvilName,
anvilName, anvilUUID,
anvilUUID, hosts: [],
hosts: [], };
};
reducedRows.push(rowStage);
reducedRows.push(rowStage); }
} }
rowStage.hosts.push({ hostName, hostUUID });
return reducedRows; return reducedRows;
}, },
[], [],

@ -26,8 +26,18 @@ const buildGetRequestHandler =
console.log(`Query error: ${queryError}`); console.log(`Query error: ${queryError}`);
response.status(500).send(); response.status(500).send();
return;
} }
console.log(
`Query stdout pre-hooks (type=[${typeof queryStdout}]): ${JSON.stringify(
queryStdout,
null,
2,
)}`,
);
const { afterQueryReturn } = buildQueryOptions; const { afterQueryReturn } = buildQueryOptions;
queryStdout = call(afterQueryReturn, { queryStdout = call(afterQueryReturn, {
@ -41,7 +51,7 @@ const buildGetRequestHandler =
}); });
console.log( console.log(
`Query stdout (type=[${typeof queryStdout}]): ${JSON.stringify( `Query stdout post-hooks (type=[${typeof queryStdout}]): ${JSON.stringify(
queryStdout, queryStdout,
null, null,
2, 2,

Loading…
Cancel
Save