refactor
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import type { Result } from './Result';
|
||||
import type { ApplicationErrorCode } from '../errors/ApplicationErrorCode';
|
||||
|
||||
/**
|
||||
* Async Use Case interface for queries.
|
||||
*
|
||||
* Queries do not change system state and return data directly.
|
||||
* The output is most often a Result<T, E> where T is the data and E is a domain error code,
|
||||
* The output must be a Result<T, ApplicationErrorCode<E>> where T is the data and E is an application error code,
|
||||
* to handle business rejections explicitly. Use cases do not throw errors; they use error codes in Result.
|
||||
*
|
||||
* Example:
|
||||
* ```typescript
|
||||
* export type YourUseCaseError =
|
||||
* export type YourUseCaseErrorCode =
|
||||
* | 'SPONSOR_NOT_FOUND'
|
||||
* | 'PRICING_NOT_CONFIGURED'
|
||||
* | 'APPLICATIONS_CLOSED'
|
||||
@@ -15,16 +18,17 @@
|
||||
* | 'DUPLICATE_PENDING_REQUEST'
|
||||
* | 'OFFER_BELOW_MINIMUM';
|
||||
*
|
||||
* export class ApplyForSponsorshipUseCase implements AsyncUseCase<Input, Result<SuccessDTO, YourUseCaseError>> {
|
||||
* async execute(input: Input): Promise<Result<SuccessDTO, YourUseCaseError>> {
|
||||
* export class ApplyForSponsorshipUseCase implements AsyncUseCase<Input, SuccessDTO, YourUseCaseErrorCode> {
|
||||
* async execute(input: Input): Promise<Result<SuccessDTO, ApplicationErrorCode<YourUseCaseErrorCode>>> {
|
||||
* // implementation
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @template Input - The input type for the use case
|
||||
* @template Output - The output type returned by the use case, often Result<T, DomainErrorCode>
|
||||
* @template Success - The success type returned in the Result
|
||||
* @template ErrorCode - The error code type for ApplicationErrorCode
|
||||
*/
|
||||
export interface AsyncUseCase<Input, Output> {
|
||||
execute(input: Input): Promise<Output>;
|
||||
export interface AsyncUseCase<Input, Success, ErrorCode extends string> {
|
||||
execute(input: Input): Promise<Result<Success, ApplicationErrorCode<ErrorCode>>>;
|
||||
}
|
||||
Reference in New Issue
Block a user