This commit is contained in:
2025-12-21 17:05:36 +01:00
parent 08b0d59e45
commit f2d8a23583
66 changed files with 1131 additions and 1342 deletions

View File

@@ -6,12 +6,9 @@
import type { IMembershipFeeRepository } from '../../domain/repositories/IMembershipFeeRepository';
import type { MembershipFeeType, MembershipFee } from '../../domain/entities/MembershipFee';
import type {
IUpsertMembershipFeePresenter,
UpsertMembershipFeeResultDTO,
UpsertMembershipFeeViewModel,
} from '../presenters/IUpsertMembershipFeePresenter';
import type { UseCase } from '@core/shared/application/UseCase';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import { Result } from '@core/shared/application/Result';
export interface UpsertMembershipFeeInput {
leagueId: string;
@@ -20,26 +17,30 @@ export interface UpsertMembershipFeeInput {
amount: number;
}
export interface UpsertMembershipFeeResult {
fee: MembershipFee;
}
export type UpsertMembershipFeeErrorCode = never;
export class UpsertMembershipFeeUseCase
implements UseCase<UpsertMembershipFeeInput, UpsertMembershipFeeResultDTO, UpsertMembershipFeeViewModel, IUpsertMembershipFeePresenter>
implements UseCase<UpsertMembershipFeeInput, void, UpsertMembershipFeeErrorCode>
{
constructor(private readonly membershipFeeRepository: IMembershipFeeRepository) {}
async execute(
input: UpsertMembershipFeeInput,
presenter: IUpsertMembershipFeePresenter,
): Promise<void> {
presenter.reset();
constructor(
private readonly membershipFeeRepository: IMembershipFeeRepository,
private readonly output: UseCaseOutputPort<UpsertMembershipFeeResult>,
) {}
async execute(input: UpsertMembershipFeeInput): Promise<Result<void, never>> {
const { leagueId, seasonId, type, amount } = input;
let existingFee = await this.membershipFeeRepository.findByLeagueId(leagueId);
let fee: MembershipFee;
if (existingFee) {
existingFee.type = type;
existingFee.amount = amount;
existingFee.seasonId = seasonId;
if (seasonId !== undefined) existingFee.seasonId = seasonId;
existingFee.enabled = amount > 0;
existingFee.updatedAt = new Date();
fee = await this.membershipFeeRepository.update(existingFee);
@@ -48,29 +49,18 @@ export class UpsertMembershipFeeUseCase
const newFee: MembershipFee = {
id,
leagueId,
seasonId,
type,
amount,
enabled: amount > 0,
createdAt: new Date(),
updatedAt: new Date(),
...(seasonId !== undefined ? { seasonId } : {}),
};
fee = await this.membershipFeeRepository.create(newFee);
}
const dto: UpsertMembershipFeeResultDTO = {
fee: {
id: fee.id,
leagueId: fee.leagueId,
seasonId: fee.seasonId,
type: fee.type,
amount: fee.amount,
enabled: fee.enabled,
createdAt: fee.createdAt,
updatedAt: fee.updatedAt,
},
};
this.output.present({ fee });
presenter.present(dto);
return Result.ok(undefined);
}
}