Skip to content

Notification Module

Overview

The Notification module manages all system notifications in the BidScript application. It provides mechanisms for creating, retrieving, and managing notifications for users, supporting various notification types and delivery methods.

Key Components

Notification Module

The main module that registers all notification-related components:

@Module({
  imports: [
    // Dependencies
  ],
  controllers: [NotificationController],
  providers: [NotificationService],
  exports: [NotificationService],
})
export class NotificationModule {}

Notification Service

The NotificationService handles core notification functionality:

  • Creating notifications
  • Retrieving user notifications
  • Marking notifications as read
  • Deleting notifications

Notification Controller

The NotificationController exposes REST endpoints for notification management:

@Controller("notifications")
export class NotificationController {
  constructor(private notificationService: NotificationService) {}

  @Get("user/:userId")
  getUserNotifications(@Param("userId") userId: string) {
    return this.notificationService.getUserNotifications(userId);
  }

  @Post()
  createNotification(@Body() notification: CreateNotificationDto) {
    return this.notificationService.createNotification(notification);
  }

  @Patch(":id/read")
  markAsRead(@Param("id") id: string) {
    return this.notificationService.markAsRead(id);
  }

  @Delete(":id")
  deleteNotification(@Param("id") id: string) {
    return this.notificationService.deleteNotification(id);
  }
}

Notification Data Types

The module uses several data types:

// Example notification data structure
interface Notification {
  id: string;
  userId: string;
  title: string;
  description: string;
  type: "info" | "warning" | "error" | "success";
  isRead: boolean;
  requiresAction: boolean;
  links?: {
    text: string;
    path: string;
    description: string;
  }[];
  createdAt: Date;
}

API Endpoints

Method Endpoint Description
GET /notifications/user/:userId Get all notifications for a user
POST /notifications Create a new notification
PATCH /notifications/:id/read Mark a notification as read
DELETE /notifications/:id Delete a notification

Integration with Other Modules

The Notification module integrates with:

  • Authentication Module: For user identification
  • Event System: For triggering notifications based on system events
  • WebSocket Module: For real-time notification delivery

Usage Example

To create a notification when a document is processed:

@Injectable()
export class DocumentService {
  constructor(private notificationService: NotificationService) {}

  async processDocument(documentId: string, userId: string) {
    // Process document...

    // Create notification
    await this.notificationService.createNotification({
      userId,
      title: "Document Processed",
      description: "Your document has been successfully processed.",
      type: "success",
      requiresAction: false,
      links: [
        {
          text: "View Document",
          path: `/documents/${documentId}`,
          description: "View the processed document",
        },
      ],
    });
  }
}

Dependencies

  • Database connection for notification storage
  • Event system for notification triggers