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

@ -1,15 +1,36 @@
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { query } from '../../accessModule';
import { execManageAlerts } from '../../execManageAlerts'; import { execManageAlerts } from '../../execManageAlerts';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell'; import { stderr } from '../../shell';
export const deleteMailRecipient: RequestHandler< export const deleteMailRecipient: RequestHandler<
MailRecipientParamsDictionary MailRecipientParamsDictionary
> = (request, response) => { > = async (request, response) => {
const { const {
params: { uuid }, params: { uuid: rUuid },
} = request; } = 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 { try {
execManageAlerts('recipients', 'delete', { uuid }); execManageAlerts('recipients', 'delete', { uuid });
} catch (error) { } catch (error) {

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

Loading…
Cancel
Save