Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Support bulk creating cases though the cases client #170326

Merged
merged 15 commits into from
Nov 7, 2023
23 changes: 23 additions & 0 deletions x-pack/plugins/cases/common/types/api/case/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ export const CasePostRequestRt = rt.intersection([
),
]);

/**
* Bulk create cases
*/

const CaseCreateRequestWithOptionalId = rt.intersection([
CasePostRequestRt,
rt.exact(rt.partial({ id: rt.string })),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case action needs to provide the ids of the cases.

]);

export const BulkCreateCasesRequestRt = rt.strict({
cases: rt.array(CaseCreateRequestWithOptionalId),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the API contract as by default I would have thought about just an array of cases.

});

export const BulkCreateCasesResponseRt = rt.strict({
cases: rt.array(CaseRt),
});

/**
* Find cases
*/

export const CasesFindRequestSearchFieldsRt = rt.keyof({
description: null,
title: null,
Expand Down Expand Up @@ -480,3 +501,5 @@ export type CasesBulkGetRequest = rt.TypeOf<typeof CasesBulkGetRequestRt>;
export type CasesBulkGetResponse = rt.TypeOf<typeof CasesBulkGetResponseRt>;
export type GetRelatedCasesByAlertResponse = rt.TypeOf<typeof GetRelatedCasesByAlertResponseRt>;
export type CaseRequestCustomFields = rt.TypeOf<typeof CustomFieldsRt>;
export type BulkCreateCasesRequest = rt.TypeOf<typeof BulkCreateCasesRequestRt>;
export type BulkCreateCasesResponse = rt.TypeOf<typeof BulkCreateCasesResponseRt>;
16 changes: 9 additions & 7 deletions x-pack/plugins/cases/server/client/attachments/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ export async function deleteComment(
const attachmentRequestAttributes = decodeOrThrow(AttachmentRequestRt)(attachment.attributes);

await userActionService.creator.createUserAction({
type: UserActionTypes.comment,
action: UserActionActions.delete,
caseId: id,
attachmentId: attachmentID,
payload: { attachment: attachmentRequestAttributes },
user,
owner: attachment.attributes.owner,
userAction: {
type: UserActionTypes.comment,
action: UserActionActions.delete,
caseId: id,
attachmentId: attachmentID,
payload: { attachment: attachmentRequestAttributes },
user,
owner: attachment.attributes.owner,
},
});

await handleAlerts({ alertsService, attachments: [attachment.attributes], caseId: id });
Expand Down
Loading
Loading