This commit is contained in:
2025-12-21 19:53:22 +01:00
parent f2d8a23583
commit 3c64f328e2
105 changed files with 3191 additions and 1706 deletions

View File

@@ -1,36 +1,62 @@
export interface CommandResultViewModel {
import type { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
export interface CommandResultDTO {
success: boolean;
errorCode?: string;
message?: string;
}
export class CommandResultPresenter {
private result: CommandResultViewModel | null = null;
export type CommandApplicationError<E extends string = string> = ApplicationErrorCode<
E,
{ message: string }
>;
export class CommandResultPresenter<E extends string = string> {
private model: CommandResultDTO | null = null;
reset(): void {
this.model = null;
}
present(result: Result<unknown, CommandApplicationError<E>>): void {
if (result.isErr()) {
const error = result.unwrapErr();
this.model = {
success: false,
errorCode: error.code,
message: error.details?.message,
};
return;
}
this.model = { success: true };
}
presentSuccess(message?: string): void {
this.result = {
this.model = {
success: true,
message,
};
}
presentFailure(errorCode: string, message?: string): void {
this.result = {
this.model = {
success: false,
errorCode,
message,
};
}
getViewModel(): CommandResultViewModel | null {
return this.result;
getResponseModel(): CommandResultDTO | null {
return this.model;
}
get viewModel(): CommandResultViewModel {
if (!this.result) {
get responseModel(): CommandResultDTO {
if (!this.model) {
throw new Error('Presenter not presented');
}
return this.result;
return this.model;
}
}