[SIEM][CASE] Create comments sequentially (#63692)

This commit is contained in:
Christos Nasikas 2020-04-16 21:26:32 +03:00 committed by GitHub
parent dde3d96b14
commit 10ccc0a2f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -147,7 +147,14 @@ class ServiceNow {
comments: Comment[],
field: string
): Promise<CommentResponse[]> {
const res = await Promise.all(comments.map(c => this.createComment(incidentId, c, field)));
// Create comments sequentially.
const promises = comments.reduce(async (prevPromise, currentComment) => {
const totalComments = await prevPromise;
const res = await this.createComment(incidentId, currentComment, field);
return [...totalComments, res];
}, Promise.resolve([] as CommentResponse[]));
const res = await promises;
return res;
}

View file

@ -40,6 +40,10 @@ export function initGetCaseApi({ caseService, router }: RouteDeps) {
const theComments = await caseService.getAllCaseComments({
client,
caseId: request.params.case_id,
options: {
sortField: 'created_at',
sortOrder: 'asc',
},
});
return response.ok({