fix(striker-ui-api): cascade delete alert override records when delete mail recipient

main
Tsu-ba-me 11 months ago
parent 462a4ae999
commit e5cf18a562
  1. 6
      striker-ui-api/src/lib/request_handlers/mail-recipient/createMailRecipient.ts
  2. 25
      striker-ui-api/src/lib/request_handlers/mail-recipient/deleteMailRecipient.ts
  3. 6
      striker-ui-api/src/lib/request_handlers/mail-recipient/updateMailRecipient.ts

@ -11,14 +11,14 @@ export const createMailRecipient: RequestHandler<
> = (request, response) => {
const { body: rBody = {} } = request;
stdout('Begin creating alert recipient.');
stdout('Begin creating mail recipient.');
let reqBody: MailRecipientRequestBody;
try {
reqBody = getMailRecipientRequestBody(rBody);
} catch (error) {
stderr(`Failed to process alert recipient input; CAUSE: ${error}`);
stderr(`Failed to process mail recipient input; CAUSE: ${error}`);
return response.status(400).send();
}
@ -32,7 +32,7 @@ export const createMailRecipient: RequestHandler<
resBody = { uuid };
} catch (error) {
stderr(`Failed to create alert recipient; CAUSE: ${error}`);
stderr(`Failed to create mail recipient; CAUSE: ${error}`);
return response.status(500).send();
}

@ -1,15 +1,36 @@
import { RequestHandler } from 'express';
import { query } from '../../accessModule';
import { execManageAlerts } from '../../execManageAlerts';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
export const deleteMailRecipient: RequestHandler<
MailRecipientParamsDictionary
> = (request, response) => {
> = async (request, response) => {
const {
params: { uuid },
params: { uuid: rUuid },
} = request;
const uuid = sanitize(rUuid, 'string', { modifierType: 'sql' });
try {
const rows = await query<[string][]>(
`SELECT alert_override_uuid
FROM alert_overrides
WHERE alert_override_alert_level != -1
AND alert_override_recipient_uuid = '${uuid}';`,
);
rows.forEach(([u]) =>
execManageAlerts('alert-overrides', 'delete', { uuid: u }),
);
} catch (error) {
stderr(`Failed to delete related alert override records; CAUSE ${error}`);
return response.status(500).send();
}
try {
execManageAlerts('recipients', 'delete', { uuid });
} catch (error) {

@ -14,14 +14,14 @@ export const updateMailRecipient: RequestHandler<
params: { uuid },
} = request;
stdout('Begin updating alert recipient.');
stdout('Begin updating mail recipient.');
let body: MailRecipientRequestBody;
try {
body = getMailRecipientRequestBody(rBody, uuid);
} catch (error) {
stderr(`Failed to process alert recipient input; CAUSE: ${error}`);
stderr(`Failed to process mail recipient input; CAUSE: ${error}`);
return response.status(400).send();
}
@ -29,7 +29,7 @@ export const updateMailRecipient: RequestHandler<
try {
execManageAlerts('recipients', 'edit', { body, uuid });
} catch (error) {
stderr(`Failed to update mail server; CAUSE: ${error}`);
stderr(`Failed to update mail recipient; CAUSE: ${error}`);
return response.status(500).send();
}

Loading…
Cancel
Save