fix issues in core

This commit is contained in:
2025-12-23 11:25:08 +01:00
parent 1efd971032
commit 2854ae3c5c
113 changed files with 1142 additions and 458 deletions

View File

@@ -8,7 +8,7 @@ import type { Logger, UseCaseOutputPort } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { INotificationRepository } from '../../domain/repositories/INotificationRepository';
import { NotificationDomainError } from '../../domain/errors/NotificationDomainError';
// import { NotificationDomainError } from '../../domain/errors/NotificationDomainError';
export interface MarkNotificationReadCommand {
notificationId: string;
@@ -45,7 +45,7 @@ export class MarkNotificationReadUseCase {
if (!notification) {
this.logger.warn(`Notification not found for ID: ${command.notificationId}`);
return Result.err({
return Result.err<void, ApplicationErrorCode<MarkNotificationReadErrorCode, { message: string }>>({
code: 'NOTIFICATION_NOT_FOUND',
details: { message: 'Notification not found' },
});
@@ -55,7 +55,7 @@ export class MarkNotificationReadUseCase {
this.logger.warn(
`Unauthorized attempt to mark notification ${command.notificationId}. Recipient ID mismatch.`,
);
return Result.err({
return Result.err<void, ApplicationErrorCode<MarkNotificationReadErrorCode, { message: string }>>({
code: 'RECIPIENT_MISMATCH',
details: { message: "Cannot mark another user's notification as read" },
});
@@ -91,7 +91,7 @@ export class MarkNotificationReadUseCase {
this.logger.error(
`Failed to mark notification ${command.notificationId} as read: ${err.message}`,
);
return Result.err({
return Result.err<void, ApplicationErrorCode<MarkNotificationReadErrorCode, { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});
@@ -129,7 +129,7 @@ export class MarkAllNotificationsReadUseCase {
return Result.ok(undefined);
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
return Result.err({
return Result.err<void, ApplicationErrorCode<MarkAllNotificationsReadErrorCode, { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});
@@ -174,14 +174,14 @@ export class DismissNotificationUseCase {
);
if (!notification) {
return Result.err({
return Result.err<void, ApplicationErrorCode<DismissNotificationErrorCode, { message: string }>>({
code: 'NOTIFICATION_NOT_FOUND',
details: { message: 'Notification not found' },
});
}
if (notification.recipientId !== command.recipientId) {
return Result.err({
return Result.err<void, ApplicationErrorCode<DismissNotificationErrorCode, { message: string }>>({
code: 'RECIPIENT_MISMATCH',
details: { message: "Cannot dismiss another user's notification" },
});
@@ -197,7 +197,7 @@ export class DismissNotificationUseCase {
}
if (!notification.canDismiss()) {
return Result.err({
return Result.err<void, ApplicationErrorCode<DismissNotificationErrorCode, { message: string }>>({
code: 'CANNOT_DISMISS_REQUIRING_RESPONSE',
details: { message: 'Cannot dismiss notification that requires response' },
});
@@ -215,7 +215,7 @@ export class DismissNotificationUseCase {
return Result.ok(undefined);
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
return Result.err({
return Result.err<void, ApplicationErrorCode<DismissNotificationErrorCode, { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});

View File

@@ -11,7 +11,7 @@ import { NotificationPreference } from '../../domain/entities/NotificationPrefer
import type { ChannelPreference, TypePreference } from '../../domain/entities/NotificationPreference';
import type { INotificationPreferenceRepository } from '../../domain/repositories/INotificationPreferenceRepository';
import type { NotificationType, NotificationChannel } from '../../domain/types/NotificationTypes';
import { NotificationDomainError } from '../../domain/errors/NotificationDomainError';
// import { NotificationDomainError } from '../../domain/errors/NotificationDomainError';
/**
* Query: GetNotificationPreferencesQuery
@@ -46,7 +46,7 @@ export class GetNotificationPreferencesQuery {
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
this.logger.error(`Failed to fetch preferences for driver: ${driverId}`, err);
return Result.err({
return Result.err<void, ApplicationErrorCode<'REPOSITORY_ERROR', { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});
@@ -101,7 +101,7 @@ export class UpdateChannelPreferenceUseCase {
`Failed to update channel preference for driver: ${command.driverId}, channel: ${command.channel}`,
err,
);
return Result.err({
return Result.err<void, ApplicationErrorCode<UpdateChannelPreferenceErrorCode, { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});
@@ -155,7 +155,7 @@ export class UpdateTypePreferenceUseCase {
`Failed to update type preference for driver: ${command.driverId}, type: ${command.type}`,
err,
);
return Result.err({
return Result.err<void, ApplicationErrorCode<GetNotificationPreferencesErrorCode, { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});
@@ -202,7 +202,7 @@ export class UpdateQuietHoursUseCase {
this.logger.warn(
`Invalid start hour provided for driver: ${command.driverId}. startHour: ${command.startHour}`,
);
return Result.err({
return Result.err<void, ApplicationErrorCode<UpdateQuietHoursErrorCode, { message: string }>>({
code: 'INVALID_START_HOUR',
details: { message: 'Start hour must be between 0 and 23' },
});
@@ -211,7 +211,7 @@ export class UpdateQuietHoursUseCase {
this.logger.warn(
`Invalid end hour provided for driver: ${command.driverId}. endHour: ${command.endHour}`,
);
return Result.err({
return Result.err<void, ApplicationErrorCode<UpdateQuietHoursErrorCode, { message: string }>>({
code: 'INVALID_END_HOUR',
details: { message: 'End hour must be between 0 and 23' },
});
@@ -235,7 +235,7 @@ export class UpdateQuietHoursUseCase {
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
this.logger.error(`Failed to update quiet hours for driver: ${command.driverId}`, err);
return Result.err({
return Result.err<void, ApplicationErrorCode<UpdateTypePreferenceErrorCode, { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});
@@ -255,7 +255,7 @@ export interface SetDigestModeCommand {
export interface SetDigestModeResult {
driverId: string;
enabled: boolean;
frequencyHours?: number;
frequencyHours?: number | undefined;
}
export type SetDigestModeErrorCode =
@@ -272,7 +272,7 @@ export class SetDigestModeUseCase {
command: SetDigestModeCommand,
): Promise<Result<void, ApplicationErrorCode<SetDigestModeErrorCode, { message: string }>>> {
if (command.frequencyHours !== undefined && command.frequencyHours < 1) {
return Result.err({
return Result.err<void, ApplicationErrorCode<SetDigestModeErrorCode, { message: string }>>({
code: 'INVALID_FREQUENCY',
details: { message: 'Digest frequency must be at least 1 hour' },
});
@@ -287,15 +287,16 @@ export class SetDigestModeUseCase {
command.frequencyHours,
);
await this.preferenceRepository.save(updated);
this.output.present({
const result: SetDigestModeResult = {
driverId: command.driverId,
enabled: command.enabled,
frequencyHours: command.frequencyHours,
});
};
this.output.present(result);
return Result.ok(undefined);
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
return Result.err({
return Result.err<void, ApplicationErrorCode<SetDigestModeErrorCode, { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});