refactor
This commit is contained in:
@@ -22,13 +22,14 @@ export interface RecordPageViewOutput {
|
||||
|
||||
export type RecordPageViewErrorCode = 'REPOSITORY_ERROR';
|
||||
|
||||
export class RecordPageViewUseCase implements UseCase<RecordPageViewInput, RecordPageViewOutput, RecordPageViewErrorCode> {
|
||||
export class RecordPageViewUseCase implements UseCase<RecordPageViewInput, void, RecordPageViewErrorCode> {
|
||||
constructor(
|
||||
private readonly pageViewRepository: IPageViewRepository,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<RecordPageViewOutput>,
|
||||
) {}
|
||||
|
||||
async execute(input: RecordPageViewInput): Promise<Result<RecordPageViewOutput, ApplicationErrorCode<RecordPageViewErrorCode, { message: string }>>> {
|
||||
async execute(input: RecordPageViewInput): Promise<Result<void, ApplicationErrorCode<RecordPageViewErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const pageView = PageView.create({
|
||||
id: crypto.randomUUID(),
|
||||
@@ -44,24 +45,26 @@ export class RecordPageViewUseCase implements UseCase<RecordPageViewInput, Recor
|
||||
|
||||
await this.pageViewRepository.save(pageView);
|
||||
|
||||
const resultModel: RecordPageViewOutput = {
|
||||
pageViewId: pageView.id,
|
||||
};
|
||||
|
||||
this.output.present(resultModel);
|
||||
|
||||
this.logger.info('Page view recorded', {
|
||||
pageViewId: pageView.id,
|
||||
entityId: input.entityId,
|
||||
entityType: input.entityType,
|
||||
});
|
||||
|
||||
const result = Result.ok<RecordPageViewOutput, ApplicationErrorCode<RecordPageViewErrorCode, { message: string }>>({
|
||||
pageViewId: pageView.id,
|
||||
});
|
||||
return result;
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
const err = error as Error;
|
||||
this.logger.error('Failed to record page view', err, { input });
|
||||
const result = Result.err<RecordPageViewOutput, ApplicationErrorCode<RecordPageViewErrorCode, { message: string }>>({
|
||||
return Result.err({
|
||||
code: 'REPOSITORY_ERROR',
|
||||
details: { message: err.message ?? 'Failed to record page view' },
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user