Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Feb 8, 2021
1 parent 82fe896 commit 3e3bb25
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
10 changes: 4 additions & 6 deletions x-pack/plugins/case/server/client/cases/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ export const get = ({ savedObjectsClient, caseService }: CaseClientFactoryArgume
id,
includeComments = false,
}: CaseClientGet): Promise<CaseResponse> => {
const [theCase] = await Promise.all([
caseService.getCase({
client: savedObjectsClient,
caseId: id,
}),
]);
const theCase = await caseService.getCase({
client: savedObjectsClient,
caseId: id,
});

if (!includeComments) {
return CaseResponseRt.encode(
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/case/server/client/cases/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const push = ({
/* Start of push to external service */
const theCase = await caseClient.get({ id: caseId, includeComments: true });

// We need to change the logic when we support subcases
if (theCase.status === CaseStatuses.closed) {
throw Boom.conflict(
`This case ${theCase.title} is closed. You can not pushed if the case is closed.`
Expand Down
20 changes: 14 additions & 6 deletions x-pack/plugins/case/server/client/cases/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
import { ActionsClient } from '../../../../actions/server';
import { externalServiceFormatters, FormatterConnectorTypes } from '../../connectors';
import { CaseClientGetAlertsResponse } from '../../client/alerts/types';
import { isUserContext } from '../../routes/api/utils';
import {
BasicParams,
EntityInformation,
Expand Down Expand Up @@ -300,14 +299,23 @@ export const isCommentAlertType = (

export const getCommentContextFromAttributes = (
attributes: CommentAttributes
): CommentRequestUserType | CommentRequestAlertType =>
isUserContext(attributes)
? {
): CommentRequestUserType | CommentRequestAlertType => {
switch (attributes.type) {
case CommentType.user:
return {
type: CommentType.user,
comment: attributes.comment,
}
: {
};
case CommentType.alert:
return {
type: CommentType.alert,
alertId: attributes.alertId,
index: attributes.index,
};
default:
return {
type: CommentType.user,
comment: '',
};
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ExternalServiceParams extends JiraFieldsType {
labels: string[];
}

const format: ExternalServiceFormatter<ExternalServiceParams>['format'] = async (theCase) => {
const format: ExternalServiceFormatter<ExternalServiceParams>['format'] = (theCase) => {
const { priority = null, issueType = null, parent = null } =
(theCase.connector.fields as ConnectorJiraTypeFields['fields']) ?? {};
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { ResilientFieldsType, ConnectorResillientTypeFields } from '../../../common/api';
import { ExternalServiceFormatter } from '../types';

const format: ExternalServiceFormatter<ResilientFieldsType>['format'] = async (theCase) => {
const format: ExternalServiceFormatter<ResilientFieldsType>['format'] = (theCase) => {
const { incidentTypes = null, severityCode = null } =
(theCase.connector.fields as ConnectorResillientTypeFields['fields']) ?? {};
return { incidentTypes, severityCode };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { ServiceNowITSMFieldsType, ConnectorServiceNowITSMTypeFields } from '../../../common/api';
import { ExternalServiceFormatter } from '../types';

const format: ExternalServiceFormatter<ServiceNowITSMFieldsType>['format'] = async (theCase) => {
const format: ExternalServiceFormatter<ServiceNowITSMFieldsType>['format'] = (theCase) => {
const { severity = null, urgency = null, impact = null } =
(theCase.connector.fields as ConnectorServiceNowITSMTypeFields['fields']) ?? {};
return { severity, urgency, impact };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ type AlertFieldMappingAndValues = Record<
{ alertPath: string; values: Set<string>; sirFieldKey: string }
>;

const format: ExternalServiceFormatter<ExternalServiceParams>['format'] = async (
theCase,
alerts
) => {
const format: ExternalServiceFormatter<ExternalServiceParams>['format'] = (theCase, alerts) => {
const {
destIp = null,
sourceIp = null,
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/case/server/connectors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ export interface RegisterConnectorsArgs extends GetActionTypeParams {
export type FormatterConnectorTypes = Exclude<ConnectorTypes, ConnectorTypes.none>;

export interface ExternalServiceFormatter<TExternalServiceParams = {}> {
format: (
theCase: CaseResponse,
alerts: CaseClientGetAlertsResponse
) => Promise<TExternalServiceParams>;
format: (theCase: CaseResponse, alerts: CaseClientGetAlertsResponse) => TExternalServiceParams;
}

export type ExternalServiceFormatterMapper = {
Expand Down

0 comments on commit 3e3bb25

Please sign in to comment.