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

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

@ -11,20 +11,24 @@ const getAnvil = buildGetRequestHandler((request, options) => {
hos.host_uuid
FROM anvils AS anv
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) {
options.afterQueryReturn = (queryStdout) => {
let results = queryStdout;
if (queryStdout instanceof Array) {
let rowStage: AnvilOverview;
let rowStage: AnvilOverview | undefined;
results = queryStdout.reduce<AnvilOverview[]>(
(reducedRows, [anvilName, anvilUUID, hostName, hostUUID]) => {
if (rowStage && anvilUUID === rowStage.anvilUUID) {
rowStage.hosts.push({ hostName, hostUUID });
} else {
if (!rowStage || anvilUUID !== rowStage.anvilUUID) {
{
rowStage = {
anvilName,
anvilUUID,
@ -33,6 +37,9 @@ const getAnvil = buildGetRequestHandler((request, options) => {
reducedRows.push(rowStage);
}
}
rowStage.hosts.push({ hostName, hostUUID });
return reducedRows;
},

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

Loading…
Cancel
Save