fix issues in adapters
This commit is contained in:
@@ -5,18 +5,18 @@
|
||||
* Currently a stub - to be implemented when Discord integration is needed.
|
||||
*/
|
||||
|
||||
import type { Notification } from '../../domain/entities/Notification';
|
||||
import type {
|
||||
INotificationGateway,
|
||||
NotificationDeliveryResult
|
||||
} from '../../application/ports/INotificationGateway';
|
||||
import type { NotificationChannel } from '../../domain/types/NotificationTypes';
|
||||
import type { Notification } from '@core/notifications/domain/entities/Notification';
|
||||
import type {
|
||||
NotificationGateway,
|
||||
NotificationDeliveryResult
|
||||
} from '@core/notifications/application/ports/NotificationGateway';
|
||||
import type { NotificationChannel } from '@core/notifications/domain/types/NotificationTypes';
|
||||
|
||||
export interface DiscordAdapterConfig {
|
||||
webhookUrl?: string;
|
||||
}
|
||||
|
||||
export class DiscordNotificationAdapter implements INotificationGateway {
|
||||
export class DiscordNotificationAdapter implements NotificationGateway {
|
||||
private readonly channel: NotificationChannel = 'discord';
|
||||
private webhookUrl: string | undefined;
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
* Currently a stub - to be implemented when email integration is needed.
|
||||
*/
|
||||
|
||||
import type { Notification } from '../../domain/entities/Notification';
|
||||
import type { Notification } from '@core/notifications/domain/entities/Notification';
|
||||
import type {
|
||||
INotificationGateway,
|
||||
NotificationGateway,
|
||||
NotificationDeliveryResult
|
||||
} from '../../application/ports/INotificationGateway';
|
||||
import type { NotificationChannel } from '../../domain/types/NotificationTypes';
|
||||
} from '@core/notifications/application/ports/NotificationGateway';
|
||||
import type { NotificationChannel } from '@core/notifications/domain/types/NotificationTypes';
|
||||
|
||||
export interface EmailAdapterConfig {
|
||||
smtpHost?: string;
|
||||
@@ -20,7 +20,7 @@ export interface EmailAdapterConfig {
|
||||
fromAddress?: string;
|
||||
}
|
||||
|
||||
export class EmailNotificationAdapter implements INotificationGateway {
|
||||
export class EmailNotificationAdapter implements NotificationGateway {
|
||||
private readonly channel: NotificationChannel = 'email';
|
||||
private config: EmailAdapterConfig;
|
||||
|
||||
|
||||
@@ -1,27 +1,34 @@
|
||||
/**
|
||||
* Infrastructure Adapter: InAppNotificationAdapter
|
||||
* Infrastructure Adapter: InAppNotificationAdapter (Stub)
|
||||
*
|
||||
* Handles in-app notifications (stored in database, shown in UI).
|
||||
* This is the primary/default notification channel.
|
||||
* Handles in-app notifications.
|
||||
* Currently a stub - to be implemented when in-app notification system is needed.
|
||||
*/
|
||||
|
||||
import type { Notification } from '../../domain/entities/Notification';
|
||||
import type { Notification } from '@core/notifications/domain/entities/Notification';
|
||||
import type {
|
||||
INotificationGateway,
|
||||
NotificationGateway,
|
||||
NotificationDeliveryResult
|
||||
} from '../../application/ports/INotificationGateway';
|
||||
import type { NotificationChannel } from '../../domain/types/NotificationTypes';
|
||||
} from '@core/notifications/application/ports/NotificationGateway';
|
||||
import type { NotificationChannel } from '@core/notifications/domain/types/NotificationTypes';
|
||||
|
||||
export class InAppNotificationAdapter implements INotificationGateway {
|
||||
export class InAppNotificationAdapter implements NotificationGateway {
|
||||
private readonly channel: NotificationChannel = 'in_app';
|
||||
|
||||
/**
|
||||
* For in_app, sending is essentially a no-op since the notification
|
||||
* is already persisted by the use case. This just confirms delivery.
|
||||
*/
|
||||
constructor() {
|
||||
// In-app notifications don't need external configuration
|
||||
}
|
||||
|
||||
async send(notification: Notification): Promise<NotificationDeliveryResult> {
|
||||
// In-app notifications are stored directly in the repository
|
||||
// This adapter just confirms the "delivery" was successful
|
||||
// In-app notifications are stored in the database, so this is a stub
|
||||
// that simulates successful delivery
|
||||
console.log(`[InApp Stub] Notification stored in database:`, {
|
||||
id: notification.id,
|
||||
recipientId: notification.recipientId,
|
||||
title: notification.title,
|
||||
body: notification.body,
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
channel: this.channel,
|
||||
@@ -35,7 +42,8 @@ export class InAppNotificationAdapter implements INotificationGateway {
|
||||
}
|
||||
|
||||
isConfigured(): boolean {
|
||||
return true; // Always configured
|
||||
// In-app notifications are always configured
|
||||
return true;
|
||||
}
|
||||
|
||||
getChannel(): NotificationChannel {
|
||||
|
||||
@@ -4,31 +4,31 @@
|
||||
* Manages notification gateways and routes notifications to appropriate channels.
|
||||
*/
|
||||
|
||||
import type { Notification } from '../../domain/entities/Notification';
|
||||
import type { NotificationChannel } from '../../domain/types/NotificationTypes';
|
||||
import type {
|
||||
INotificationGateway,
|
||||
INotificationGatewayRegistry,
|
||||
NotificationDeliveryResult
|
||||
} from '../../application/ports/INotificationGateway';
|
||||
import type { Notification } from '@core/notifications/domain/entities/Notification';
|
||||
import type { NotificationChannel } from '@core/notifications/domain/types/NotificationTypes';
|
||||
import type {
|
||||
NotificationGateway,
|
||||
NotificationGatewayRegistry as INotificationGatewayRegistry,
|
||||
NotificationDeliveryResult
|
||||
} from '@core/notifications/application/ports/NotificationGateway';
|
||||
|
||||
export class NotificationGatewayRegistry implements INotificationGatewayRegistry {
|
||||
private gateways: Map<NotificationChannel, INotificationGateway> = new Map();
|
||||
private gateways: Map<NotificationChannel, NotificationGateway> = new Map();
|
||||
|
||||
constructor(initialGateways: INotificationGateway[] = []) {
|
||||
constructor(initialGateways: NotificationGateway[] = []) {
|
||||
initialGateways.forEach(gateway => this.register(gateway));
|
||||
}
|
||||
|
||||
register(gateway: INotificationGateway): void {
|
||||
register(gateway: NotificationGateway): void {
|
||||
const channel = gateway.getChannel();
|
||||
this.gateways.set(channel, gateway);
|
||||
}
|
||||
|
||||
getGateway(channel: NotificationChannel): INotificationGateway | null {
|
||||
getGateway(channel: NotificationChannel): NotificationGateway | null {
|
||||
return this.gateways.get(channel) || null;
|
||||
}
|
||||
|
||||
getAllGateways(): INotificationGateway[] {
|
||||
getAllGateways(): NotificationGateway[] {
|
||||
return Array.from(this.gateways.values());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Provides an in-memory storage implementation for notifications.
|
||||
*/
|
||||
|
||||
import { Notification } from '../../domain/entities/Notification';
|
||||
import type { INotificationRepository } from '../../domain/repositories/INotificationRepository';
|
||||
import type { NotificationType } from '../../domain/types/NotificationTypes';
|
||||
import { Notification } from '@core/notifications/domain/entities/Notification';
|
||||
import type { INotificationRepository } from '@core/notifications/domain/repositories/INotificationRepository';
|
||||
import type { NotificationType } from '@core/notifications/domain/types/NotificationTypes';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
|
||||
export class InMemoryNotificationRepository implements INotificationRepository {
|
||||
@@ -75,7 +75,7 @@ export class InMemoryNotificationRepository implements INotificationRepository {
|
||||
this.logger.info(`Found ${notifications.length} notifications for recipient ID: ${recipientId}, type: ${type}.`);
|
||||
return notifications;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error finding notifications for recipient ID ${recipientId}, type ${type}:`, error);
|
||||
this.logger.error(`Error finding notifications for recipient ID ${recipientId}, type ${type}:`, error instanceof Error ? error : new Error(String(error)));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,6 @@ export class InMemoryNotificationRepository implements INotificationRepository {
|
||||
async deleteAllByRecipientId(recipientId: string): Promise<void> {
|
||||
this.logger.debug(`Deleting all notifications for recipient ID: ${recipientId}`);
|
||||
try {
|
||||
const initialCount = this.notifications.size;
|
||||
const toDelete = Array.from(this.notifications.values())
|
||||
.filter(n => n.recipientId === recipientId)
|
||||
.map(n => n.id);
|
||||
|
||||
Reference in New Issue
Block a user