2025-02-16 19:30:20 +00:00
|
|
|
import { RegisterData } from "@contexts/auth/domain";
|
2025-02-15 21:30:12 +00:00
|
|
|
import { IAuthService } from "@contexts/auth/domain/services";
|
2025-04-22 15:09:57 +00:00
|
|
|
import { Result } from "core/common/helpers";
|
|
|
|
|
import { ITransactionManager } from "core/common/infrastructure/database";
|
|
|
|
|
import { logger } from "core/common/infrastructure/logger";
|
2025-02-15 21:30:12 +00:00
|
|
|
|
2025-02-16 19:30:20 +00:00
|
|
|
export class RegisterUseCase {
|
2025-02-15 21:30:12 +00:00
|
|
|
constructor(
|
|
|
|
|
private readonly authService: IAuthService,
|
|
|
|
|
private readonly transactionManager: ITransactionManager
|
|
|
|
|
) {}
|
|
|
|
|
|
2025-02-16 19:30:20 +00:00
|
|
|
public async execute(registerData: RegisterData) {
|
2025-02-15 21:30:12 +00:00
|
|
|
return await this.transactionManager.complete(async (transaction) => {
|
2025-04-01 14:26:15 +00:00
|
|
|
try {
|
|
|
|
|
return await this.authService.registerUser(registerData, transaction);
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
logger.error(error as Error);
|
|
|
|
|
return Result.fail(error as Error);
|
|
|
|
|
}
|
2025-02-15 21:30:12 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|