refactor api modules
This commit is contained in:
@@ -7,19 +7,19 @@ export interface CommandResultDTO {
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export type CommandApplicationError<E extends string = string> = ApplicationErrorCode<
|
||||
E,
|
||||
export type CommandApplicationError = ApplicationErrorCode<
|
||||
string,
|
||||
{ message: string }
|
||||
>;
|
||||
|
||||
export class CommandResultPresenter<E extends string = string> {
|
||||
export class CommandResultPresenter {
|
||||
private model: CommandResultDTO | null = null;
|
||||
|
||||
reset(): void {
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
present(result: Result<unknown, CommandApplicationError<E>>): void {
|
||||
present(result: Result<unknown, CommandApplicationError>): void {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
this.model = {
|
||||
@@ -36,7 +36,7 @@ export class CommandResultPresenter<E extends string = string> {
|
||||
presentSuccess(message?: string): void {
|
||||
this.model = {
|
||||
success: true,
|
||||
message,
|
||||
...(message !== undefined && { message }),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class CommandResultPresenter<E extends string = string> {
|
||||
this.model = {
|
||||
success: false,
|
||||
errorCode,
|
||||
message,
|
||||
...(message !== undefined && { message }),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,4 +59,8 @@ export class CommandResultPresenter<E extends string = string> {
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): CommandResultDTO {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user