refactor use cases
This commit is contained in:
@@ -7,7 +7,7 @@ import { ICompanyRepository } from '../../domain/repositories/ICompanyRepository
|
||||
import { IPasswordHashingService } from '../../domain/services/PasswordHashingService';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort, Logger, UseCase } from '@core/shared/application';
|
||||
import type { Logger, UseCase } from '@core/shared/application';
|
||||
|
||||
export type SignupSponsorInput = {
|
||||
email: string;
|
||||
@@ -31,16 +31,15 @@ export type SignupSponsorApplicationError = ApplicationErrorCode<SignupSponsorEr
|
||||
* Handles sponsor registration by creating both a User and a Company atomically.
|
||||
* If any step fails, the operation is rolled back.
|
||||
*/
|
||||
export class SignupSponsorUseCase implements UseCase<SignupSponsorInput, void, SignupSponsorErrorCode> {
|
||||
export class SignupSponsorUseCase implements UseCase<SignupSponsorInput, SignupSponsorResult, SignupSponsorErrorCode> {
|
||||
constructor(
|
||||
private readonly authRepo: IAuthRepository,
|
||||
private readonly companyRepo: ICompanyRepository,
|
||||
private readonly passwordService: IPasswordHashingService,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<SignupSponsorResult>,
|
||||
) {}
|
||||
|
||||
async execute(input: SignupSponsorInput): Promise<Result<void, SignupSponsorApplicationError>> {
|
||||
async execute(input: SignupSponsorInput): Promise<Result<SignupSponsorResult, SignupSponsorApplicationError>> {
|
||||
let createdCompany: Company | null = null;
|
||||
|
||||
try {
|
||||
@@ -118,8 +117,7 @@ export class SignupSponsorUseCase implements UseCase<SignupSponsorInput, void, S
|
||||
// Save user
|
||||
await this.authRepo.save(user);
|
||||
|
||||
this.output.present({ user, company });
|
||||
return Result.ok(undefined);
|
||||
return Result.ok({ user, company });
|
||||
} catch (error) {
|
||||
// Rollback: delete company if it was created
|
||||
if (createdCompany && typeof createdCompany.getId === 'function') {
|
||||
|
||||
Reference in New Issue
Block a user