refactor core presenters
This commit is contained in:
@@ -2,6 +2,12 @@ import { ApiProperty } from '@nestjs/swagger';
|
||||
import { SponsorshipPricingItemDTO } from './SponsorshipPricingItemDTO';
|
||||
|
||||
export class GetEntitySponsorshipPricingResultDTO {
|
||||
@ApiProperty()
|
||||
entityType: string;
|
||||
|
||||
@ApiProperty()
|
||||
entityId: string;
|
||||
|
||||
@ApiProperty({ type: [SponsorshipPricingItemDTO] })
|
||||
pricing: SponsorshipPricingItemDTO[];
|
||||
}
|
||||
@@ -7,9 +7,15 @@ export class SponsorDTO {
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
contactEmail?: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
logoUrl?: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
websiteUrl?: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
createdAt?: Date;
|
||||
}
|
||||
@@ -10,9 +10,9 @@ describe('CreateSponsorPresenter', () => {
|
||||
|
||||
describe('reset', () => {
|
||||
it('should reset the result to null', () => {
|
||||
const mockResult = { id: 'sponsor-1', name: 'Test Sponsor' };
|
||||
presenter.present(mockResult);
|
||||
expect(presenter.viewModel).toEqual(mockResult);
|
||||
const mockPort = { sponsor: { id: 'sponsor-1', name: 'Test Sponsor', contactEmail: 'test@example.com', createdAt: new Date() } };
|
||||
presenter.present(mockPort);
|
||||
expect(presenter.viewModel).toEqual({ sponsor: mockPort.sponsor });
|
||||
|
||||
presenter.reset();
|
||||
expect(() => presenter.viewModel).toThrow('Presenter not presented');
|
||||
@@ -21,11 +21,11 @@ describe('CreateSponsorPresenter', () => {
|
||||
|
||||
describe('present', () => {
|
||||
it('should store the result', () => {
|
||||
const mockResult = { id: 'sponsor-1', name: 'Test Sponsor', contactEmail: 'test@example.com' };
|
||||
const mockPort = { sponsor: { id: 'sponsor-1', name: 'Test Sponsor', contactEmail: 'test@example.com', createdAt: new Date() } };
|
||||
|
||||
presenter.present(mockResult);
|
||||
presenter.present(mockPort);
|
||||
|
||||
expect(presenter.viewModel).toEqual(mockResult);
|
||||
expect(presenter.viewModel).toEqual({ sponsor: mockPort.sponsor });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,10 +35,10 @@ describe('CreateSponsorPresenter', () => {
|
||||
});
|
||||
|
||||
it('should return the result when presented', () => {
|
||||
const mockResult = { id: 'sponsor-1', name: 'Test Sponsor' };
|
||||
presenter.present(mockResult);
|
||||
const mockPort = { sponsor: { id: 'sponsor-1', name: 'Test Sponsor', contactEmail: 'test@example.com', createdAt: new Date() } };
|
||||
presenter.present(mockPort);
|
||||
|
||||
expect(presenter.getViewModel()).toEqual(mockResult);
|
||||
expect(presenter.getViewModel()).toEqual({ sponsor: mockPort.sponsor });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,10 +48,10 @@ describe('CreateSponsorPresenter', () => {
|
||||
});
|
||||
|
||||
it('should return the result when presented', () => {
|
||||
const mockResult = { id: 'sponsor-1', name: 'Test Sponsor' };
|
||||
presenter.present(mockResult);
|
||||
const mockPort = { sponsor: { id: 'sponsor-1', name: 'Test Sponsor', contactEmail: 'test@example.com', createdAt: new Date() } };
|
||||
presenter.present(mockPort);
|
||||
|
||||
expect(presenter.viewModel).toEqual(mockResult);
|
||||
expect(presenter.viewModel).toEqual({ sponsor: mockPort.sponsor });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,21 +1,31 @@
|
||||
import { CreateSponsorViewModel, CreateSponsorOutputPort, ICreateSponsorPresenter } from '@core/racing/application/presenters/ICreateSponsorPresenter';
|
||||
import type { CreateSponsorOutputPort } from '@core/racing/application/ports/output/CreateSponsorOutputPort';
|
||||
import type { CreateSponsorOutputDTO } from '../dtos/CreateSponsorOutputDTO';
|
||||
|
||||
export class CreateSponsorPresenter implements ICreateSponsorPresenter {
|
||||
private result: CreateSponsorViewModel | null = null;
|
||||
export class CreateSponsorPresenter {
|
||||
private result: CreateSponsorOutputDTO | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(dto: CreateSponsorOutputPort) {
|
||||
this.result = dto;
|
||||
present(port: CreateSponsorOutputPort) {
|
||||
this.result = {
|
||||
sponsor: {
|
||||
id: port.sponsor.id,
|
||||
name: port.sponsor.name,
|
||||
contactEmail: port.sponsor.contactEmail,
|
||||
logoUrl: port.sponsor.logoUrl,
|
||||
websiteUrl: port.sponsor.websiteUrl,
|
||||
createdAt: port.sponsor.createdAt,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
getViewModel(): CreateSponsorViewModel | null {
|
||||
getViewModel(): CreateSponsorOutputDTO | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): CreateSponsorViewModel {
|
||||
get viewModel(): CreateSponsorOutputDTO {
|
||||
if (!this.result) throw new Error('Presenter not presented');
|
||||
return this.result;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,41 @@
|
||||
import type { GetEntitySponsorshipPricingResultDTO } from '@core/racing/application/use-cases/GetEntitySponsorshipPricingUseCase';
|
||||
import type { IEntitySponsorshipPricingPresenter } from '@core/racing/application/presenters/IEntitySponsorshipPricingPresenter';
|
||||
import type { GetEntitySponsorshipPricingOutputPort } from '@core/racing/application/ports/output/GetEntitySponsorshipPricingOutputPort';
|
||||
import { GetEntitySponsorshipPricingResultDTO } from '../dtos/GetEntitySponsorshipPricingResultDTO';
|
||||
|
||||
export class GetEntitySponsorshipPricingPresenter implements IEntitySponsorshipPricingPresenter {
|
||||
export class GetEntitySponsorshipPricingPresenter {
|
||||
private result: GetEntitySponsorshipPricingResultDTO | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(dto: GetEntitySponsorshipPricingResultDTO | null) {
|
||||
this.result = dto;
|
||||
async present(output: GetEntitySponsorshipPricingOutputPort | null) {
|
||||
if (!output) {
|
||||
this.result = { pricing: [] };
|
||||
return;
|
||||
}
|
||||
|
||||
const pricing = [];
|
||||
if (output.mainSlot) {
|
||||
pricing.push({
|
||||
id: `${output.entityType}-${output.entityId}-main`,
|
||||
level: 'main',
|
||||
price: output.mainSlot.price,
|
||||
currency: output.mainSlot.currency,
|
||||
});
|
||||
}
|
||||
if (output.secondarySlot) {
|
||||
pricing.push({
|
||||
id: `${output.entityType}-${output.entityId}-secondary`,
|
||||
level: 'secondary',
|
||||
price: output.secondarySlot.price,
|
||||
currency: output.secondarySlot.currency,
|
||||
});
|
||||
}
|
||||
|
||||
this.result = { pricing };
|
||||
}
|
||||
|
||||
getViewModel(): GetEntitySponsorshipPricingResultDTO | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): GetEntitySponsorshipPricingResultDTO | null {
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { PendingSponsorshipRequestsOutputPort } from '@core/racing/application/ports/output/PendingSponsorshipRequestsOutputPort';
|
||||
import { GetPendingSponsorshipRequestsOutputDTO } from '../dtos/GetPendingSponsorshipRequestsOutputDTO';
|
||||
|
||||
export class GetPendingSponsorshipRequestsPresenter {
|
||||
present(outputPort: PendingSponsorshipRequestsOutputPort): GetPendingSponsorshipRequestsOutputDTO {
|
||||
return {
|
||||
entityType: outputPort.entityType,
|
||||
entityId: outputPort.entityId,
|
||||
requests: outputPort.requests,
|
||||
totalCount: outputPort.totalCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,8 @@
|
||||
import type { SponsorDashboardDTO } from '@core/racing/application/use-cases/GetSponsorDashboardUseCase';
|
||||
import type { ISponsorDashboardPresenter, SponsorDashboardViewModel } from '@core/racing/application/presenters/ISponsorDashboardPresenter';
|
||||
import type { SponsorDashboardOutputPort } from '@core/racing/application/ports/output/SponsorDashboardOutputPort';
|
||||
import { SponsorDashboardDTO } from '../dtos/SponsorDashboardDTO';
|
||||
|
||||
export class GetSponsorDashboardPresenter implements ISponsorDashboardPresenter {
|
||||
private result: SponsorDashboardViewModel | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(dto: SponsorDashboardDTO | null) {
|
||||
this.result = dto;
|
||||
}
|
||||
|
||||
getViewModel(): SponsorDashboardViewModel | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): SponsorDashboardViewModel | null {
|
||||
return this.result;
|
||||
export class GetSponsorDashboardPresenter {
|
||||
present(outputPort: SponsorDashboardOutputPort | null): SponsorDashboardDTO | null {
|
||||
return outputPort;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,8 @@
|
||||
import type { SponsorSponsorshipsDTO } from '@core/racing/application/use-cases/GetSponsorSponsorshipsUseCase';
|
||||
import type { ISponsorSponsorshipsPresenter, SponsorSponsorshipsViewModel } from '@core/racing/application/presenters/ISponsorSponsorshipsPresenter';
|
||||
import type { SponsorSponsorshipsOutputPort } from '@core/racing/application/ports/output/SponsorSponsorshipsOutputPort';
|
||||
import { SponsorSponsorshipsDTO } from '../dtos/SponsorSponsorshipsDTO';
|
||||
|
||||
export class GetSponsorSponsorshipsPresenter implements ISponsorSponsorshipsPresenter {
|
||||
private result: SponsorSponsorshipsViewModel | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(dto: SponsorSponsorshipsDTO | null) {
|
||||
this.result = dto;
|
||||
}
|
||||
|
||||
getViewModel(): SponsorSponsorshipsViewModel | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): SponsorSponsorshipsViewModel | null {
|
||||
return this.result;
|
||||
export class GetSponsorSponsorshipsPresenter {
|
||||
present(outputPort: SponsorSponsorshipsOutputPort | null): SponsorSponsorshipsDTO | null {
|
||||
return outputPort;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,10 @@
|
||||
import { GetSponsorsViewModel, GetSponsorsResultDTO, IGetSponsorsPresenter } from '@core/racing/application/presenters/IGetSponsorsPresenter';
|
||||
import type { GetSponsorsOutputPort } from '@core/racing/application/ports/output/GetSponsorsOutputPort';
|
||||
import { GetSponsorsOutputDTO } from '../dtos/GetSponsorsOutputDTO';
|
||||
|
||||
export class GetSponsorsPresenter implements IGetSponsorsPresenter {
|
||||
private result: GetSponsorsViewModel | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(dto: GetSponsorsResultDTO) {
|
||||
this.result = dto;
|
||||
}
|
||||
|
||||
getViewModel(): GetSponsorsViewModel | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): GetSponsorsViewModel {
|
||||
if (!this.result) throw new Error('Presenter not presented');
|
||||
return this.result;
|
||||
export class GetSponsorsPresenter {
|
||||
present(outputPort: GetSponsorsOutputPort): GetSponsorsOutputDTO {
|
||||
return {
|
||||
sponsors: outputPort.sponsors,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,12 @@
|
||||
import { GetSponsorshipPricingViewModel, GetSponsorshipPricingResultDTO, IGetSponsorshipPricingPresenter } from '@core/racing/application/presenters/IGetSponsorshipPricingPresenter';
|
||||
import type { GetSponsorshipPricingOutputPort } from '@core/racing/application/ports/output/GetSponsorshipPricingOutputPort';
|
||||
import { GetEntitySponsorshipPricingResultDTO } from '../dtos/GetEntitySponsorshipPricingResultDTO';
|
||||
|
||||
export class GetSponsorshipPricingPresenter implements IGetSponsorshipPricingPresenter {
|
||||
private result: GetSponsorshipPricingViewModel | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(dto: GetSponsorshipPricingResultDTO) {
|
||||
this.result = dto;
|
||||
}
|
||||
|
||||
getViewModel(): GetSponsorshipPricingViewModel | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): GetSponsorshipPricingViewModel {
|
||||
if (!this.result) throw new Error('Presenter not presented');
|
||||
return this.result;
|
||||
export class GetSponsorshipPricingPresenter {
|
||||
present(outputPort: GetSponsorshipPricingOutputPort): GetEntitySponsorshipPricingResultDTO {
|
||||
return {
|
||||
entityType: outputPort.entityType,
|
||||
entityId: outputPort.entityId,
|
||||
pricing: outputPort.pricing,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user