presenter refactoring
This commit is contained in:
@@ -40,7 +40,7 @@ describe('PaymentsController', () => {
|
||||
it('should return payments', async () => {
|
||||
const query: GetPaymentsQuery = { status: 'pending' };
|
||||
const result = { payments: [] };
|
||||
service.getPayments.mockResolvedValue(result);
|
||||
service.getPayments.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.getPayments(query);
|
||||
|
||||
@@ -53,7 +53,7 @@ describe('PaymentsController', () => {
|
||||
it('should create payment', async () => {
|
||||
const input: CreatePaymentInput = { amount: 100, type: 'membership_fee', payerId: 'payer-123', payerType: 'driver', leagueId: 'league-123' };
|
||||
const result = { payment: { id: 'pay-123' } };
|
||||
service.createPayment.mockResolvedValue(result);
|
||||
service.createPayment.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.createPayment(input);
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('PaymentsController', () => {
|
||||
it('should update payment status', async () => {
|
||||
const input: UpdatePaymentStatusInput = { paymentId: 'pay-123', status: 'completed' };
|
||||
const result = { payment: { id: 'pay-123', status: 'completed' } };
|
||||
service.updatePaymentStatus.mockResolvedValue(result);
|
||||
service.updatePaymentStatus.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.updatePaymentStatus(input);
|
||||
|
||||
@@ -79,7 +79,7 @@ describe('PaymentsController', () => {
|
||||
it('should return membership fees', async () => {
|
||||
const query: GetMembershipFeesQuery = { leagueId: 'league-123' };
|
||||
const result = { fees: [] };
|
||||
service.getMembershipFees.mockResolvedValue(result);
|
||||
service.getMembershipFees.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.getMembershipFees(query);
|
||||
|
||||
@@ -92,7 +92,7 @@ describe('PaymentsController', () => {
|
||||
it('should upsert membership fee', async () => {
|
||||
const input: UpsertMembershipFeeInput = { leagueId: 'league-123', amount: 50 };
|
||||
const result = { feeId: 'fee-123' };
|
||||
service.upsertMembershipFee.mockResolvedValue(result);
|
||||
service.upsertMembershipFee.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.upsertMembershipFee(input);
|
||||
|
||||
@@ -105,7 +105,7 @@ describe('PaymentsController', () => {
|
||||
it('should update member payment', async () => {
|
||||
const input: UpdateMemberPaymentInput = { memberId: 'member-123', paymentId: 'pay-123' };
|
||||
const result = { success: true };
|
||||
service.updateMemberPayment.mockResolvedValue(result);
|
||||
service.updateMemberPayment.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.updateMemberPayment(input);
|
||||
|
||||
@@ -118,7 +118,7 @@ describe('PaymentsController', () => {
|
||||
it('should return prizes', async () => {
|
||||
const query: GetPrizesQuery = { leagueId: 'league-123' };
|
||||
const result = { prizes: [] };
|
||||
service.getPrizes.mockResolvedValue(result);
|
||||
service.getPrizes.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.getPrizes(query);
|
||||
|
||||
@@ -131,7 +131,7 @@ describe('PaymentsController', () => {
|
||||
it('should create prize', async () => {
|
||||
const input: CreatePrizeInput = { name: 'Prize', amount: 100 };
|
||||
const result = { prizeId: 'prize-123' };
|
||||
service.createPrize.mockResolvedValue(result);
|
||||
service.createPrize.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.createPrize(input);
|
||||
|
||||
@@ -144,7 +144,7 @@ describe('PaymentsController', () => {
|
||||
it('should award prize', async () => {
|
||||
const input: AwardPrizeInput = { prizeId: 'prize-123', driverId: 'driver-123' };
|
||||
const result = { success: true };
|
||||
service.awardPrize.mockResolvedValue(result);
|
||||
service.awardPrize.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.awardPrize(input);
|
||||
|
||||
@@ -157,7 +157,7 @@ describe('PaymentsController', () => {
|
||||
it('should delete prize', async () => {
|
||||
const query: DeletePrizeInput = { prizeId: 'prize-123' };
|
||||
const result = { success: true };
|
||||
service.deletePrize.mockResolvedValue(result);
|
||||
service.deletePrize.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.deletePrize(query);
|
||||
|
||||
@@ -170,7 +170,7 @@ describe('PaymentsController', () => {
|
||||
it('should return wallet', async () => {
|
||||
const query: GetWalletQuery = { userId: 'user-123' };
|
||||
const result = { balance: 100 };
|
||||
service.getWallet.mockResolvedValue(result);
|
||||
service.getWallet.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.getWallet(query);
|
||||
|
||||
@@ -183,7 +183,7 @@ describe('PaymentsController', () => {
|
||||
it('should process wallet transaction', async () => {
|
||||
const input: ProcessWalletTransactionInput = { userId: 'user-123', amount: 50, type: 'deposit' };
|
||||
const result = { transactionId: 'tx-123' };
|
||||
service.processWalletTransaction.mockResolvedValue(result);
|
||||
service.processWalletTransaction.mockResolvedValue({ viewModel: result } as any);
|
||||
|
||||
const response = await controller.processWalletTransaction(input);
|
||||
|
||||
@@ -191,4 +191,4 @@ describe('PaymentsController', () => {
|
||||
expect(response).toEqual(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,7 +12,8 @@ export class PaymentsController {
|
||||
@ApiOperation({ summary: 'Get payments based on filters' })
|
||||
@ApiResponse({ status: 200, description: 'List of payments', type: GetPaymentsOutput })
|
||||
async getPayments(@Query() query: GetPaymentsQuery): Promise<GetPaymentsOutput> {
|
||||
return this.paymentsService.getPayments(query);
|
||||
const presenter = await this.paymentsService.getPayments(query);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
|
||||
@Post()
|
||||
@@ -20,21 +21,24 @@ export class PaymentsController {
|
||||
@ApiOperation({ summary: 'Create a new payment' })
|
||||
@ApiResponse({ status: 201, description: 'Payment created', type: CreatePaymentOutput })
|
||||
async createPayment(@Body() input: CreatePaymentInput): Promise<CreatePaymentOutput> {
|
||||
return this.paymentsService.createPayment(input);
|
||||
const presenter = await this.paymentsService.createPayment(input);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
|
||||
@Patch('status')
|
||||
@ApiOperation({ summary: 'Update the status of a payment' })
|
||||
@ApiResponse({ status: 200, description: 'Payment status updated', type: UpdatePaymentStatusOutput })
|
||||
async updatePaymentStatus(@Body() input: UpdatePaymentStatusInput): Promise<UpdatePaymentStatusOutput> {
|
||||
return this.paymentsService.updatePaymentStatus(input);
|
||||
const presenter = await this.paymentsService.updatePaymentStatus(input);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
|
||||
@Get('membership-fees')
|
||||
@ApiOperation({ summary: 'Get membership fees and member payments' })
|
||||
@ApiResponse({ status: 200, description: 'Membership fee configuration and member payments', type: GetMembershipFeesOutput })
|
||||
async getMembershipFees(@Query() query: GetMembershipFeesQuery): Promise<GetMembershipFeesOutput> {
|
||||
return this.paymentsService.getMembershipFees(query);
|
||||
const presenter = await this.paymentsService.getMembershipFees(query);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
|
||||
@Post('membership-fees')
|
||||
@@ -42,20 +46,23 @@ export class PaymentsController {
|
||||
@ApiOperation({ summary: 'Create or update membership fee configuration' })
|
||||
@ApiResponse({ status: 201, description: 'Membership fee configuration created or updated', type: UpsertMembershipFeeOutput })
|
||||
async upsertMembershipFee(@Body() input: UpsertMembershipFeeInput): Promise<UpsertMembershipFeeOutput> {
|
||||
return this.paymentsService.upsertMembershipFee(input);
|
||||
const presenter = await this.paymentsService.upsertMembershipFee(input);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
|
||||
@Patch('membership-fees/member-payment')
|
||||
@ApiOperation({ summary: 'Record or update a member payment' })
|
||||
@ApiResponse({ status: 200, description: 'Member payment recorded or updated', type: UpdateMemberPaymentOutput })
|
||||
async updateMemberPayment(@Body() input: UpdateMemberPaymentInput): Promise<UpdateMemberPaymentOutput> {
|
||||
return this.paymentsService.updateMemberPayment(input);
|
||||
const presenter = await this.paymentsService.updateMemberPayment(input);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
@Get('prizes')
|
||||
@ApiOperation({ summary: 'Get prizes for a league or season' })
|
||||
@ApiResponse({ status: 200, description: 'List of prizes', type: GetPrizesOutput })
|
||||
async getPrizes(@Query() query: GetPrizesQuery): Promise<GetPrizesOutput> {
|
||||
return this.paymentsService.getPrizes(query);
|
||||
const presenter = await this.paymentsService.getPrizes(query);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
|
||||
@Post('prizes')
|
||||
@@ -63,27 +70,31 @@ export class PaymentsController {
|
||||
@ApiOperation({ summary: 'Create a new prize' })
|
||||
@ApiResponse({ status: 201, description: 'Prize created', type: CreatePrizeOutput })
|
||||
async createPrize(@Body() input: CreatePrizeInput): Promise<CreatePrizeOutput> {
|
||||
return this.paymentsService.createPrize(input);
|
||||
const presenter = await this.paymentsService.createPrize(input);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
|
||||
@Patch('prizes/award')
|
||||
@ApiOperation({ summary: 'Award a prize to a driver' })
|
||||
@ApiResponse({ status: 200, description: 'Prize awarded', type: AwardPrizeOutput })
|
||||
async awardPrize(@Body() input: AwardPrizeInput): Promise<AwardPrizeOutput> {
|
||||
return this.paymentsService.awardPrize(input);
|
||||
const presenter = await this.paymentsService.awardPrize(input);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
|
||||
@Delete('prizes')
|
||||
@ApiOperation({ summary: 'Delete a prize' })
|
||||
@ApiResponse({ status: 200, description: 'Prize deleted', type: DeletePrizeOutput })
|
||||
async deletePrize(@Query() query: DeletePrizeInput): Promise<DeletePrizeOutput> {
|
||||
return this.paymentsService.deletePrize(query);
|
||||
const presenter = await this.paymentsService.deletePrize(query);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
@Get('wallets')
|
||||
@ApiOperation({ summary: 'Get wallet information and transactions' })
|
||||
@ApiResponse({ status: 200, description: 'Wallet and transaction data', type: GetWalletOutput })
|
||||
async getWallet(@Query() query: GetWalletQuery): Promise<GetWalletOutput> {
|
||||
return this.paymentsService.getWallet(query);
|
||||
const presenter = await this.paymentsService.getWallet(query);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
|
||||
@Post('wallets/transactions')
|
||||
@@ -91,6 +102,7 @@ export class PaymentsController {
|
||||
@ApiOperation({ summary: 'Process a wallet transaction (deposit or withdrawal)' })
|
||||
@ApiResponse({ status: 201, description: 'Wallet transaction processed', type: ProcessWalletTransactionOutput })
|
||||
async processWalletTransaction(@Body() input: ProcessWalletTransactionInput): Promise<ProcessWalletTransactionOutput> {
|
||||
return this.paymentsService.processWalletTransaction(input);
|
||||
const presenter = await this.paymentsService.processWalletTransaction(input);
|
||||
return presenter.viewModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,99 +92,99 @@ export class PaymentsService {
|
||||
@Inject(LOGGER_TOKEN) private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async getPayments(query: GetPaymentsQuery): Promise<GetPaymentsOutput> {
|
||||
async getPayments(query: GetPaymentsQuery): Promise<GetPaymentsPresenter> {
|
||||
this.logger.debug('[PaymentsService] Getting payments', { query });
|
||||
|
||||
const presenter = new GetPaymentsPresenter();
|
||||
await this.getPaymentsUseCase.execute(query, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async createPayment(input: CreatePaymentInput): Promise<CreatePaymentOutput> {
|
||||
async createPayment(input: CreatePaymentInput): Promise<CreatePaymentPresenter> {
|
||||
this.logger.debug('[PaymentsService] Creating payment', { input });
|
||||
|
||||
const presenter = new CreatePaymentPresenter();
|
||||
await this.createPaymentUseCase.execute(input, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async updatePaymentStatus(input: UpdatePaymentStatusInput): Promise<UpdatePaymentStatusOutput> {
|
||||
async updatePaymentStatus(input: UpdatePaymentStatusInput): Promise<UpdatePaymentStatusPresenter> {
|
||||
this.logger.debug('[PaymentsService] Updating payment status', { input });
|
||||
|
||||
const presenter = new UpdatePaymentStatusPresenter();
|
||||
await this.updatePaymentStatusUseCase.execute(input, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async getMembershipFees(query: GetMembershipFeesQuery): Promise<GetMembershipFeesOutput> {
|
||||
async getMembershipFees(query: GetMembershipFeesQuery): Promise<GetMembershipFeesPresenter> {
|
||||
this.logger.debug('[PaymentsService] Getting membership fees', { query });
|
||||
|
||||
const presenter = new GetMembershipFeesPresenter();
|
||||
await this.getMembershipFeesUseCase.execute(query, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async upsertMembershipFee(input: UpsertMembershipFeeInput): Promise<UpsertMembershipFeeOutput> {
|
||||
async upsertMembershipFee(input: UpsertMembershipFeeInput): Promise<UpsertMembershipFeePresenter> {
|
||||
this.logger.debug('[PaymentsService] Upserting membership fee', { input });
|
||||
|
||||
const presenter = new UpsertMembershipFeePresenter();
|
||||
await this.upsertMembershipFeeUseCase.execute(input, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async updateMemberPayment(input: UpdateMemberPaymentInput): Promise<UpdateMemberPaymentOutput> {
|
||||
async updateMemberPayment(input: UpdateMemberPaymentInput): Promise<UpdateMemberPaymentPresenter> {
|
||||
this.logger.debug('[PaymentsService] Updating member payment', { input });
|
||||
|
||||
const presenter = new UpdateMemberPaymentPresenter();
|
||||
await this.updateMemberPaymentUseCase.execute(input, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async getPrizes(query: GetPrizesQuery): Promise<GetPrizesOutput> {
|
||||
async getPrizes(query: GetPrizesQuery): Promise<GetPrizesPresenter> {
|
||||
this.logger.debug('[PaymentsService] Getting prizes', { query });
|
||||
|
||||
const presenter = new GetPrizesPresenter();
|
||||
await this.getPrizesUseCase.execute({ leagueId: query.leagueId!, seasonId: query.seasonId }, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async createPrize(input: CreatePrizeInput): Promise<CreatePrizeOutput> {
|
||||
async createPrize(input: CreatePrizeInput): Promise<CreatePrizePresenter> {
|
||||
this.logger.debug('[PaymentsService] Creating prize', { input });
|
||||
|
||||
const presenter = new CreatePrizePresenter();
|
||||
await this.createPrizeUseCase.execute(input, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async awardPrize(input: AwardPrizeInput): Promise<AwardPrizeOutput> {
|
||||
async awardPrize(input: AwardPrizeInput): Promise<AwardPrizePresenter> {
|
||||
this.logger.debug('[PaymentsService] Awarding prize', { input });
|
||||
|
||||
const presenter = new AwardPrizePresenter();
|
||||
await this.awardPrizeUseCase.execute(input, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async deletePrize(input: DeletePrizeInput): Promise<DeletePrizeOutput> {
|
||||
async deletePrize(input: DeletePrizeInput): Promise<DeletePrizePresenter> {
|
||||
this.logger.debug('[PaymentsService] Deleting prize', { input });
|
||||
|
||||
const presenter = new DeletePrizePresenter();
|
||||
await this.deletePrizeUseCase.execute(input, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async getWallet(query: GetWalletQuery): Promise<GetWalletOutput> {
|
||||
async getWallet(query: GetWalletQuery): Promise<GetWalletPresenter> {
|
||||
this.logger.debug('[PaymentsService] Getting wallet', { query });
|
||||
|
||||
const presenter = new GetWalletPresenter();
|
||||
await this.getWalletUseCase.execute({ leagueId: query.leagueId! }, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
|
||||
async processWalletTransaction(input: ProcessWalletTransactionInput): Promise<ProcessWalletTransactionOutput> {
|
||||
async processWalletTransaction(input: ProcessWalletTransactionInput): Promise<ProcessWalletTransactionPresenter> {
|
||||
this.logger.debug('[PaymentsService] Processing wallet transaction', { input });
|
||||
|
||||
const presenter = new ProcessWalletTransactionPresenter();
|
||||
await this.processWalletTransactionUseCase.execute(input, presenter);
|
||||
return presenter.viewModel;
|
||||
return presenter;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user