fix(striker-ui-api): allow filter alert override list with recipient

main
Tsu-ba-me 11 months ago
parent 4a7feae98a
commit dc0c919436
  1. 7
      striker-ui-api/src/lib/request_handlers/alert-override/deleteAlertOverride.ts
  2. 93
      striker-ui-api/src/lib/request_handlers/alert-override/getAlertOverride.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/alert-override/getAlertOverrideDetail.ts
  4. 2
      striker-ui-api/src/lib/request_handlers/alert-override/updateAlertOverride.ts
  5. 6
      striker-ui-api/src/types/ApiAlertOverride.d.ts

@ -3,9 +3,10 @@ import { RequestHandler } from 'express';
import { execManageAlerts } from '../../execManageAlerts';
import { stderr } from '../../shell';
export const deleteAlertOverride: RequestHandler<
AlertOverrideParamsDictionary
> = (request, response) => {
export const deleteAlertOverride: RequestHandler<AlertOverrideReqParams> = (
request,
response,
) => {
const {
params: { uuid },
} = request;

@ -2,13 +2,28 @@ import { RequestHandler } from 'express';
import { DELETED } from '../../consts';
import { buildUnknownIDCondition } from '../../buildCondition';
import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
import { getShortHostName } from '../../disassembleHostName';
export const getAlertOverride: RequestHandler = buildGetRequestHandler(
(request, options) => {
const query = `
export const getAlertOverride: RequestHandler<
AlertOverrideReqParams,
undefined,
undefined,
AlertOverrideReqQuery
> = buildGetRequestHandler((request, options) => {
const {
query: { 'mail-recipient': mailRecipient },
} = request;
const { after: mailRecipientCond } = buildUnknownIDCondition(
mailRecipient,
'b.recipient_uuid',
{ onFallback: () => 'TRUE' },
);
const query = `
SELECT
a.alert_override_uuid,
a.alert_override_alert_level,
@ -24,46 +39,46 @@ export const getAlertOverride: RequestHandler = buildGetRequestHandler(
ON a.alert_override_host_uuid = c.host_uuid
WHERE a.alert_override_alert_level != -1
AND b.recipient_name != '${DELETED}'
AND ${mailRecipientCond}
ORDER BY b.recipient_name ASC;`;
const afterQueryReturn: QueryResultModifierFunction =
buildQueryResultReducer<AlertOverrideOverviewList>(
(
previous,
[
uuid,
level,
mailRecipientUuid,
mailRecipientName,
hostUuid,
const afterQueryReturn: QueryResultModifierFunction =
buildQueryResultReducer<AlertOverrideOverviewList>(
(
previous,
[
uuid,
level,
mailRecipientUuid,
mailRecipientName,
hostUuid,
hostName,
hostType,
],
) => {
previous[uuid] = {
host: {
hostName,
hostType,
],
) => {
previous[uuid] = {
host: {
hostName,
hostType,
hostUUID: hostUuid,
shortHostName: getShortHostName(hostName),
},
level: Number(level),
mailRecipient: {
name: mailRecipientName,
uuid: mailRecipientUuid,
},
uuid,
};
hostUUID: hostUuid,
shortHostName: getShortHostName(hostName),
},
level: Number(level),
mailRecipient: {
name: mailRecipientName,
uuid: mailRecipientUuid,
},
uuid,
};
return previous;
},
{},
);
return previous;
},
{},
);
if (options) {
options.afterQueryReturn = afterQueryReturn;
}
if (options) {
options.afterQueryReturn = afterQueryReturn;
}
return query;
},
);
return query;
});

@ -7,7 +7,7 @@ import { buildQueryResultModifier } from '../../buildQueryResultModifier';
import { getShortHostName } from '../../disassembleHostName';
import { sanitize } from '../../sanitize';
export const getAlertOverrideDetail: RequestHandler<AlertOverrideParamsDictionary> =
export const getAlertOverrideDetail: RequestHandler<AlertOverrideReqParams> =
buildGetRequestHandler((request, options) => {
const {
params: { uuid: rUuid },

@ -5,7 +5,7 @@ import { getAlertOverrideRequestBody } from './getAlertOverrideRequestBody';
import { stderr, stdout } from '../../shell';
export const updateAlertOverride: RequestHandler<
AlertOverrideParamsDictionary,
AlertOverrideReqParams,
undefined,
AlertOverrideRequestBody
> = (request, response) => {

@ -11,7 +11,11 @@ type AlertOverrideOverviewList = {
[uuid: string]: AlertOverrideOverview;
};
type AlertOverrideParamsDictionary = {
type AlertOverrideReqQuery = {
'mail-recipient': string | string[];
};
type AlertOverrideReqParams = {
uuid: string;
};

Loading…
Cancel
Save