refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -116,8 +116,6 @@ export class AuthService {
async signupWithEmail(params: SignupParamsDTO): Promise<AuthSessionDTO> {
this.logger.debug(`[AuthService] Attempting signup for email: ${params.email}`);
this.authSessionPresenter.reset();
const input: SignupInput = {
email: params.email,
password: params.password,
@@ -131,6 +129,9 @@ export class AuthService {
throw new Error(mapApplicationErrorToMessage(error, 'Signup failed'));
}
const signupResult = result.unwrap();
this.authSessionPresenter.present(signupResult);
const userDTO = this.authSessionPresenter.responseModel;
const inferredRole = inferDemoRoleFromEmail(userDTO.email);
const session = await this.identitySessionPort.createSession({
@@ -149,8 +150,6 @@ export class AuthService {
async signupSponsor(params: SignupSponsorParamsDTO): Promise<AuthSessionDTO> {
this.logger.debug(`[AuthService] Attempting sponsor signup for email: ${params.email}`);
this.authSessionPresenter.reset();
const input: SignupSponsorInput = {
email: params.email,
password: params.password,
@@ -165,6 +164,9 @@ export class AuthService {
throw new Error(mapApplicationErrorToMessage(error, 'Sponsor signup failed'));
}
const signupResult = result.unwrap();
this.authSessionPresenter.present(signupResult);
const userDTO = this.authSessionPresenter.responseModel;
const inferredRole = inferDemoRoleFromEmail(userDTO.email);
const session = await this.identitySessionPort.createSession({
@@ -183,8 +185,6 @@ export class AuthService {
async loginWithEmail(params: LoginParamsDTO): Promise<AuthSessionDTO> {
this.logger.debug(`[AuthService] Attempting login for email: ${params.email}`);
this.authSessionPresenter.reset();
const input: LoginInput = {
email: params.email,
password: params.password,
@@ -197,6 +197,9 @@ export class AuthService {
throw new Error(mapApplicationErrorToMessage(error, 'Login failed'));
}
const loginResult = result.unwrap();
this.authSessionPresenter.present(loginResult);
const userDTO = this.authSessionPresenter.responseModel;
const sessionOptions = params.rememberMe !== undefined
? { rememberMe: params.rememberMe }
@@ -223,8 +226,6 @@ export class AuthService {
async logout(): Promise<CommandResultDTO> {
this.logger.debug('[AuthService] Attempting logout.');
this.commandResultPresenter.reset();
const result = await this.logoutUseCase.execute();
if (result.isErr()) {
@@ -232,6 +233,9 @@ export class AuthService {
throw new Error(mapApplicationErrorToMessage(error, 'Logout failed'));
}
const logoutResult = result.unwrap();
this.commandResultPresenter.present(logoutResult);
return this.commandResultPresenter.responseModel;
}
@@ -285,8 +289,6 @@ export class AuthService {
async forgotPassword(params: { email: string }): Promise<{ message: string; magicLink?: string }> {
this.logger.debug(`[AuthService] Attempting forgot password for email: ${params.email}`);
this.forgotPasswordPresenter.reset();
const input: ForgotPasswordInput = {
email: params.email,
};
@@ -298,6 +300,9 @@ export class AuthService {
throw new Error(mapApplicationErrorToMessage(error, 'Forgot password failed'));
}
const forgotPasswordResult = executeResult.unwrap();
this.forgotPasswordPresenter.present(forgotPasswordResult);
const response = this.forgotPasswordPresenter.responseModel;
const result: { message: string; magicLink?: string } = {
message: response.message,
@@ -311,8 +316,6 @@ export class AuthService {
async resetPassword(params: { token: string; newPassword: string }): Promise<{ message: string }> {
this.logger.debug('[AuthService] Attempting reset password');
this.resetPasswordPresenter.reset();
const input: ResetPasswordInput = {
token: params.token,
newPassword: params.newPassword,
@@ -325,6 +328,9 @@ export class AuthService {
throw new Error(mapApplicationErrorToMessage(error, 'Reset password failed'));
}
const resetResult = result.unwrap();
this.resetPasswordPresenter.present(resetResult);
return this.resetPasswordPresenter.responseModel;
}
}