view models

This commit is contained in:
2025-12-18 01:20:23 +01:00
parent 7c449af311
commit cc2553876a
216 changed files with 485 additions and 10179 deletions

View File

@@ -1,5 +1,7 @@
import { AnalyticsApiClient } from '../../api/analytics/AnalyticsApiClient';
import type { RecordPageViewInputDto, RecordPageViewOutputDto, RecordEngagementInputDto, RecordEngagementOutputDto } from '../../dtos';
import { RecordPageViewOutputDTO, RecordEngagementOutputDTO } from '../../types/generated';
import { RecordPageViewInputViewModel } from '../../view-models/RecordPageViewInputViewModel';
import { RecordEngagementInputViewModel } from '../../view-models/RecordEngagementInputViewModel';
/**
* Analytics Service
@@ -15,22 +17,29 @@ export class AnalyticsService {
/**
* Record a page view
*/
async recordPageView(input: RecordPageViewInputDto): Promise<RecordPageViewOutputDto> {
try {
return await this.apiClient.recordPageView(input);
} catch (error) {
throw error;
async recordPageView(input: RecordPageViewInputViewModel): Promise<RecordPageViewOutputDTO> {
const apiInput: { path: string; userId?: string } = {
path: input.path,
};
if (input.userId) {
apiInput.userId = input.userId;
}
return await this.apiClient.recordPageView(apiInput);
}
/**
* Record an engagement event
*/
async recordEngagement(input: RecordEngagementInputDto): Promise<RecordEngagementOutputDto> {
try {
return await this.apiClient.recordEngagement(input);
} catch (error) {
throw error;
async recordEngagement(input: RecordEngagementInputViewModel): Promise<RecordEngagementOutputDTO> {
const apiInput: { eventType: string; userId?: string; metadata?: Record<string, unknown> } = {
eventType: input.eventType,
};
if (input.userId) {
apiInput.userId = input.userId;
}
if (input.metadata) {
apiInput.metadata = input.metadata;
}
return await this.apiClient.recordEngagement(apiInput);
}
}