-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor case client & create internal case client
- Loading branch information
Showing
28 changed files
with
508 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { CaseStatuses } from '../../../common/api'; | ||
import { AlertInfo } from '../../common'; | ||
import { CasesSubClientImplementation } from '../types'; | ||
import { CasesClientGetAlertsResponse } from './types'; | ||
import { get } from './get'; | ||
import { updateStatus } from './update_status'; | ||
|
||
/** | ||
* Defines the fields necessary to update an alert's status. | ||
*/ | ||
export interface UpdateAlertRequest { | ||
id: string; | ||
index: string; | ||
status: CaseStatuses; | ||
} | ||
|
||
export interface AlertUpdateStatus { | ||
alerts: UpdateAlertRequest[]; | ||
} | ||
|
||
export interface AlertGet { | ||
alertsInfo: AlertInfo[]; | ||
} | ||
|
||
export interface AlertSubClient { | ||
get(args: AlertGet): Promise<CasesClientGetAlertsResponse>; | ||
updateStatus(args: AlertUpdateStatus): Promise<void>; | ||
} | ||
|
||
export const createAlertsSubClient: CasesSubClientImplementation<AlertSubClient> = (args) => { | ||
const { alertsService, scopedClusterClient, logger } = args; | ||
|
||
const alertsSubClient: AlertSubClient = { | ||
get: (params: AlertGet) => | ||
get({ | ||
...params, | ||
alertsService, | ||
scopedClusterClient, | ||
logger, | ||
}), | ||
updateStatus: (params: AlertUpdateStatus) => | ||
updateStatus({ | ||
...params, | ||
alertsService, | ||
scopedClusterClient, | ||
logger, | ||
}), | ||
}; | ||
|
||
return alertsSubClient; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { CaseResponse, CommentRequest as AttachmentsRequest } from '../../../common/api'; | ||
import { CasesClientArgs, CasesSubClientImplementation } from '../types'; | ||
import { addComment } from './add'; | ||
|
||
export interface AttachmentsAdd { | ||
caseId: string; | ||
comment: AttachmentsRequest; | ||
} | ||
|
||
export interface AttachmentsSubClient { | ||
add(args: AttachmentsAdd): Promise<CaseResponse>; | ||
} | ||
|
||
export const createAttachmentsSubClient: CasesSubClientImplementation<AttachmentsSubClient> = ( | ||
args, | ||
getClientsFactories | ||
) => { | ||
const { getCasesInternalClient } = getClientsFactories; | ||
const attachmentSubClient: AttachmentsSubClient = { | ||
add: ({ caseId, comment }: AttachmentsAdd) => | ||
addComment({ | ||
...args, | ||
getCasesInternalClient, | ||
caseId, | ||
comment, | ||
}), | ||
}; | ||
|
||
return attachmentSubClient; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ActionsClient } from '../../../../actions/server'; | ||
import { | ||
CasePostRequest, | ||
CaseResponse, | ||
CasesPatchRequest, | ||
CasesResponse, | ||
CasesFindRequest, | ||
CasesFindResponse, | ||
} from '../../../common/api'; | ||
import { CasesSubClientImplementation } from '../types'; | ||
import { create } from './create'; | ||
import { find } from './find'; | ||
import { get } from './get'; | ||
import { push } from './push'; | ||
import { update } from './update'; | ||
|
||
export interface CaseGet { | ||
id: string; | ||
includeComments?: boolean; | ||
includeSubCaseComments?: boolean; | ||
} | ||
|
||
export interface CasePush { | ||
actionsClient: ActionsClient; | ||
caseId: string; | ||
connectorId: string; | ||
} | ||
|
||
export interface CasesSubClient { | ||
create(theCase: CasePostRequest): Promise<CaseResponse>; | ||
find(args: CasesFindRequest): Promise<CasesFindResponse>; | ||
get(args: CaseGet): Promise<CaseResponse>; | ||
push(args: CasePush): Promise<CaseResponse>; | ||
update(args: CasesPatchRequest): Promise<CasesResponse>; | ||
} | ||
|
||
export const createCasesSubClient: CasesSubClientImplementation<CasesSubClient> = ( | ||
args, | ||
getClientsFactories | ||
) => { | ||
const { | ||
caseConfigureService, | ||
caseService, | ||
user, | ||
savedObjectsClient, | ||
userActionService, | ||
logger, | ||
authorization, | ||
} = args; | ||
|
||
const { getCasesClient, getCasesInternalClient } = getClientsFactories; | ||
|
||
const casesSubClient: CasesSubClient = { | ||
create: (theCase: CasePostRequest) => | ||
create({ | ||
savedObjectsClient, | ||
caseService, | ||
caseConfigureService, | ||
userActionService, | ||
user, | ||
theCase, | ||
logger, | ||
auth: authorization, | ||
}), | ||
find: (options: CasesFindRequest) => | ||
find({ | ||
savedObjectsClient, | ||
caseService, | ||
logger, | ||
auth: authorization, | ||
options, | ||
}), | ||
get: (params: CaseGet) => | ||
get({ | ||
...params, | ||
caseService, | ||
savedObjectsClient, | ||
logger, | ||
}), | ||
push: (params: CasePush) => | ||
push({ | ||
...params, | ||
savedObjectsClient, | ||
caseService, | ||
userActionService, | ||
user, | ||
getCasesClient, | ||
getCasesInternalClient, | ||
caseConfigureService, | ||
logger, | ||
}), | ||
update: (cases: CasesPatchRequest) => | ||
update({ | ||
savedObjectsClient, | ||
caseService, | ||
userActionService, | ||
user, | ||
cases, | ||
getCasesInternalClient, | ||
logger, | ||
}), | ||
}; | ||
|
||
return casesSubClient; | ||
}; |
Oops, something went wrong.