presenter refactoring
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
export interface ReviewProtestViewModel {
|
||||
success: boolean;
|
||||
errorCode?: string;
|
||||
message?: string;
|
||||
protestId?: string;
|
||||
stewardId?: string;
|
||||
decision?: 'uphold' | 'dismiss';
|
||||
}
|
||||
|
||||
export class ReviewProtestPresenter {
|
||||
private result: ReviewProtestViewModel | null = null;
|
||||
|
||||
reset(): void {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
presentSuccess(payload: { protestId: string; stewardId: string; decision: 'uphold' | 'dismiss' }): void {
|
||||
this.result = {
|
||||
success: true,
|
||||
protestId: payload.protestId,
|
||||
stewardId: payload.stewardId,
|
||||
decision: payload.decision,
|
||||
};
|
||||
}
|
||||
|
||||
presentError(errorCode: string, message?: string): void {
|
||||
this.result = {
|
||||
success: false,
|
||||
errorCode,
|
||||
message,
|
||||
};
|
||||
}
|
||||
|
||||
getViewModel(): ReviewProtestViewModel | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): ReviewProtestViewModel {
|
||||
if (!this.result) {
|
||||
throw new Error('Presenter not presented');
|
||||
}
|
||||
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user