website refactor
This commit is contained in:
@@ -32,7 +32,7 @@ export class InAppNotificationAdapter implements NotificationGateway {
|
||||
return {
|
||||
success: true,
|
||||
channel: this.channel,
|
||||
externalId: notification.id,
|
||||
externalId: notification.id.value,
|
||||
attemptedAt: new Date(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NotificationPreference } from '@core/notifications/domain/entities/NotificationPreference';
|
||||
import { NotificationPreferenceRepository } from '@core/notifications/domain/repositories/NotificationPreferenceRepository';
|
||||
import { Logger } from '@core/shared/domain';
|
||||
import type { NotificationPreferenceRepository } from '@core/notifications/domain/repositories/NotificationPreferenceRepository';
|
||||
import type { Logger } from '@core/shared/domain/Logger';
|
||||
|
||||
export class InMemoryNotificationPreferenceRepository implements NotificationPreferenceRepository {
|
||||
private preferences: Map<string, NotificationPreference> = new Map();
|
||||
|
||||
@@ -17,8 +17,8 @@ export class InMemoryNotificationRepository implements NotificationRepository {
|
||||
this.logger = logger;
|
||||
this.logger.info('InMemoryNotificationRepository initialized.');
|
||||
initialNotifications.forEach(notification => {
|
||||
this.notifications.set(notification.id, notification);
|
||||
this.logger.debug(`Seeded notification: ${notification.id}`);
|
||||
this.notifications.set(notification.id.value, notification);
|
||||
this.logger.debug(`Seeded notification: ${notification.id.value}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,31 +95,31 @@ export class InMemoryNotificationRepository implements NotificationRepository {
|
||||
}
|
||||
|
||||
async create(notification: Notification): Promise<void> {
|
||||
this.logger.debug(`Creating notification: ${notification.id}`);
|
||||
this.logger.debug(`Creating notification: ${notification.id.value}`);
|
||||
try {
|
||||
if (this.notifications.has(notification.id)) {
|
||||
this.logger.warn(`Notification with ID ${notification.id} already exists. Throwing error.`);
|
||||
throw new Error(`Notification with ID ${notification.id} already exists`);
|
||||
if (this.notifications.has(notification.id.value)) {
|
||||
this.logger.warn(`Notification with ID ${notification.id.value} already exists. Throwing error.`);
|
||||
throw new Error(`Notification with ID ${notification.id.value} already exists`);
|
||||
}
|
||||
this.notifications.set(notification.id, notification);
|
||||
this.logger.info(`Notification ${notification.id} created successfully.`);
|
||||
this.notifications.set(notification.id.value, notification);
|
||||
this.logger.info(`Notification ${notification.id.value} created successfully.`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Error creating notification ${notification.id}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
this.logger.error(`Error creating notification ${notification.id.value}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async update(notification: Notification): Promise<void> {
|
||||
this.logger.debug(`Updating notification: ${notification.id}`);
|
||||
this.logger.debug(`Updating notification: ${notification.id.value}`);
|
||||
try {
|
||||
if (!this.notifications.has(notification.id)) {
|
||||
this.logger.warn(`Notification with ID ${notification.id} not found for update. Throwing error.`);
|
||||
throw new Error(`Notification with ID ${notification.id} not found`);
|
||||
if (!this.notifications.has(notification.id.value)) {
|
||||
this.logger.warn(`Notification with ID ${notification.id.value} not found for update. Throwing error.`);
|
||||
throw new Error(`Notification with ID ${notification.id.value} not found`);
|
||||
}
|
||||
this.notifications.set(notification.id, notification);
|
||||
this.logger.info(`Notification ${notification.id} updated successfully.`);
|
||||
this.notifications.set(notification.id.value, notification);
|
||||
this.logger.info(`Notification ${notification.id.value} updated successfully.`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Error updating notification ${notification.id}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
this.logger.error(`Error updating notification ${notification.id.value}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ export class InMemoryNotificationRepository implements NotificationRepository {
|
||||
try {
|
||||
const toDelete = Array.from(this.notifications.values())
|
||||
.filter(n => n.recipientId === recipientId)
|
||||
.map(n => n.id);
|
||||
.map(n => n.id.value);
|
||||
|
||||
toDelete.forEach(id => this.notifications.delete(id));
|
||||
this.logger.info(`Deleted ${toDelete.length} notifications for recipient ID: ${recipientId}.`);
|
||||
@@ -163,7 +163,7 @@ export class InMemoryNotificationRepository implements NotificationRepository {
|
||||
|
||||
toUpdate.forEach(n => {
|
||||
const updated = n.markAsRead();
|
||||
this.notifications.set(updated.id, updated);
|
||||
this.notifications.set(updated.id.value, updated);
|
||||
});
|
||||
this.logger.info(`Marked ${toUpdate.length} notifications as read for recipient ID: ${recipientId}.`);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MagicLinkNotificationInput, MagicLinkNotificationPort } from '@core/identity/domain/ports/MagicLinkNotificationPort';
|
||||
import { Logger } from '@core/shared/domain';
|
||||
import type { MagicLinkNotificationInput, MagicLinkNotificationPort } from '@core/identity/domain/ports/MagicLinkNotificationPort';
|
||||
import type { Logger } from '@core/shared/domain/Logger';
|
||||
|
||||
/**
|
||||
* Console adapter for magic link notifications
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { NotificationGatewayRegistry } from '@core/notifications/application/ports/NotificationGateway';
|
||||
import type { NotificationService, SendNotificationCommand } from '@core/notifications/application/ports/NotificationService';
|
||||
import { SendNotificationUseCase } from '@core/notifications/application/use-cases/SendNotificationUseCase';
|
||||
import type { NotificationRepository } from '@core/notifications/domain/repositories/NotificationRepository';
|
||||
import type { NotificationPreferenceRepository } from '@core/notifications/domain/repositories/NotificationPreferenceRepository';
|
||||
import type { Logger } from '@core/shared/domain/Logger';
|
||||
|
||||
export class NotificationServiceAdapter implements NotificationService {
|
||||
@@ -8,8 +10,8 @@ export class NotificationServiceAdapter implements NotificationService {
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(
|
||||
notificationRepository: INotificationRepository,
|
||||
preferenceRepository: INotificationPreferenceRepository,
|
||||
notificationRepository: NotificationRepository,
|
||||
preferenceRepository: NotificationPreferenceRepository,
|
||||
gatewayRegistry: NotificationGatewayRegistry,
|
||||
logger: Logger,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user