refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -5,7 +5,7 @@
* based on their preferences.
*/
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
import type { Logger } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import { v4 as uuid } from 'uuid';
@@ -52,7 +52,6 @@ export class SendNotificationUseCase {
private readonly notificationRepository: INotificationRepository,
private readonly preferenceRepository: INotificationPreferenceRepository,
private readonly gatewayRegistry: NotificationGatewayRegistry,
private readonly output: UseCaseOutputPort<SendNotificationResult>,
private readonly logger: Logger,
) {
this.logger.debug('SendNotificationUseCase initialized.');
@@ -60,7 +59,7 @@ export class SendNotificationUseCase {
async execute(
command: SendNotificationCommand,
): Promise<Result<void, ApplicationErrorCode<SendNotificationErrorCode, { message: string }>>> {
): Promise<Result<SendNotificationResult, ApplicationErrorCode<SendNotificationErrorCode, { message: string }>>> {
this.logger.debug('Executing SendNotificationUseCase', { command });
try {
// Get recipient's preferences
@@ -84,12 +83,10 @@ export class SendNotificationUseCase {
await this.notificationRepository.create(notification);
this.output.present({
return Result.ok<SendNotificationResult, ApplicationErrorCode<SendNotificationErrorCode, { message: string }>>({
notification,
deliveryResults: [],
});
return Result.ok(undefined);
}
// Determine which channels to use
@@ -142,20 +139,18 @@ export class SendNotificationUseCase {
deliveryResults.push(result);
}
}
this.output.present({
return Result.ok<SendNotificationResult, ApplicationErrorCode<SendNotificationErrorCode, { message: string }>>({
notification: primaryNotification!,
deliveryResults,
});
return Result.ok(undefined);
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
this.logger.error('Error sending notification', err);
return Result.err({
return Result.err<SendNotificationResult, ApplicationErrorCode<SendNotificationErrorCode, { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});
}
}
}
}