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

@@ -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 },
});