-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(api): Endpoint for canceling events in bulk #6059
base: next
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsArray, IsBoolean, IsOptional, IsString } from 'class-validator'; | ||
|
||
export class TriggerBulkCancelResponseDto { | ||
@ApiProperty({ | ||
description: 'transaction id for trigger', | ||
}) | ||
@IsString() | ||
transactionId: string; | ||
|
||
@ApiProperty({ | ||
description: 'The success of the trigger', | ||
}) | ||
@IsBoolean() | ||
success: boolean; | ||
|
||
@ApiProperty({ | ||
description: 'In case of an error, this field will contain the error message', | ||
}) | ||
@IsArray() | ||
@IsOptional() | ||
error?: string[]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { ProcessBulkCancelCommand } from './process-bulk-cancel.command'; | ||
export { ProcessBulkCancel } from './process-bulk-cancel.usecase'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { EnvironmentWithUserCommand } from '../../../shared/commands/project.command'; | ||
import { IsArray } from 'class-validator'; | ||
|
||
export class ProcessBulkCancelCommand extends EnvironmentWithUserCommand { | ||
@IsArray() | ||
transactionIds: string[]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { TriggerBulkCancelResponseDto } from '../../dtos/trigger-bulk-cancel-response.dto'; | ||
import { CancelDelayed, CancelDelayedCommand } from '../cancel-delayed'; | ||
import { ProcessBulkCancelCommand } from './process-bulk-cancel.command'; | ||
|
||
@Injectable() | ||
export class ProcessBulkCancel { | ||
constructor(private cancelDelayed: CancelDelayed) {} | ||
|
||
async execute(command: ProcessBulkCancelCommand) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ☑ chore: Please add a return typing to this function using the Dto to fully enforce the use-case boundary with type-safety. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
const results: TriggerBulkCancelResponseDto[] = []; | ||
|
||
for (const transactionId of command.transactionIds) { | ||
let result: TriggerBulkCancelResponseDto; | ||
|
||
try { | ||
const promise = await this.cancelDelayed.execute( | ||
CancelDelayedCommand.create({ | ||
...command, | ||
transactionId: transactionId, | ||
}) | ||
); | ||
|
||
result = { | ||
transactionId, | ||
success: promise, | ||
}; | ||
} catch (e) { | ||
let error: string[]; | ||
if (e.response?.message) { | ||
error = Array.isArray(e.response?.message) ? e.response?.message : [e.response?.message]; | ||
} else { | ||
error = [e.message]; | ||
} | ||
|
||
result = { | ||
transactionId, | ||
success: false, | ||
error, | ||
}; | ||
} | ||
|
||
results.push(result); | ||
} | ||
|
||
return results; | ||
} | ||
} |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠ issue: The new endpoint takes an array of
transactionId
s, therefore the endpoint should produce an array of cancel response Dtos, one response Dto pertransactionId
. We can achieve specification of this with Nestjs swagger plugin by wrapping thetype
field with square braces.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done