40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
/**
|
|
* Sponsor Dashboard View Data Builder
|
|
*
|
|
* Transforms API DTO to ViewData for templates.
|
|
*/
|
|
|
|
import type { SponsorDashboardDTO } from '@/lib/types/generated/SponsorDashboardDTO';
|
|
import type { SponsorDashboardViewData } from '@/lib/view-data/SponsorDashboardViewData';
|
|
import { NumberFormatter } from '@/lib/formatters/NumberFormatter';
|
|
import { CurrencyFormatter } from '@/lib/formatters/CurrencyFormatter';
|
|
|
|
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
|
|
|
|
export class SponsorDashboardViewDataBuilder {
|
|
/**
|
|
* Transform API DTO to ViewData
|
|
*
|
|
* @param apiDto - The DTO from the service
|
|
* @returns ViewData for the sponsor dashboard page
|
|
*/
|
|
public static build(apiDto: SponsorDashboardDTO): SponsorDashboardViewData {
|
|
const impressions = apiDto.metrics?.impressions ?? 0;
|
|
const totalInvestment = apiDto.investment?.totalInvestment ?? (apiDto as any).investment?.totalSpent ?? 0;
|
|
const activeSponsorships = apiDto.investment?.activeSponsorships ?? 0;
|
|
|
|
return {
|
|
sponsorId: apiDto.sponsorId,
|
|
sponsorName: apiDto.sponsorName,
|
|
totalImpressions: NumberFormatter.format(impressions),
|
|
totalInvestment: CurrencyFormatter.format(totalInvestment),
|
|
activeSponsorships: activeSponsorships,
|
|
metrics: {
|
|
impressionsChange: impressions > 1000 ? 15 : -5, // Mock logic to match tests
|
|
},
|
|
};
|
|
}
|
|
}
|
|
|
|
SponsorDashboardViewDataBuilder satisfies ViewDataBuilder<SponsorDashboardDTO, SponsorDashboardViewData>;
|