Skip to content

feat(notifications): add minimal notification entity and service#127

Open
Spycall wants to merge 1 commit intoStarkHive:mainfrom
Spycall:feat/minimal-notification-entity-service
Open

feat(notifications): add minimal notification entity and service#127
Spycall wants to merge 1 commit intoStarkHive:mainfrom
Spycall:feat/minimal-notification-entity-service

Conversation

@Spycall
Copy link
Contributor

@Spycall Spycall commented Jul 3, 2025

add minimal notification entity and service

Summary by CodeRabbit

  • New Features

    • Added the ability to create notifications for users with a simplified notification type.
    • Introduced a method to retrieve a user's recent notifications, limited to a specified number.
  • Refactor

    • Simplified the notification structure by removing several fields and relations.
    • Streamlined notification types, reducing specific types and adding new general types ("ALERT" and "INFO").
    • Reduced module dependencies and removed the notifications controller.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Walkthrough

The changes simplify the notification system by reducing the Notification entity's fields and relations, streamlining the module's dependencies, and adding two basic methods to the service for creating and retrieving notifications. Several notification types and metadata fields were removed, and the controller was unregistered from the module.

Changes

File(s) Change Summary
src/notifications/entities/notification.entity.ts Simplified Notification entity: removed fields (title, user relation, relatedEntityId, etc.), reduced enum types, and cleaned imports.
src/notifications/notifications.module.ts Removed module dependencies and controller; only imports TypeOrmModule and provides/exports service.
src/notifications/notifications.service.ts Added createNotification and getUserNotifications methods for basic notification handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant NotificationsService
    participant NotificationRepository

    Client->>NotificationsService: createNotification(userId, message, type)
    NotificationsService->>NotificationRepository: save({userId, message, type})
    NotificationRepository-->>NotificationsService: Notification
    NotificationsService-->>Client: Notification

    Client->>NotificationsService: getUserNotifications(userId, limit)
    NotificationsService->>NotificationRepository: find({userId}, {order: createdAt DESC, take: limit})
    NotificationRepository-->>NotificationsService: [Notification]
    NotificationsService-->>Client: [Notification]
Loading

Possibly related PRs

  • StarkHive/starkhive_api#69: Modifies the Notification entity and service, focusing on job status update notifications.
  • StarkHive/starkhive_api#67: Introduces the original Notification entity with full relations and paginated retrieval, whereas this PR simplifies the entity and retrieval methods.

Suggested reviewers

  • Cybermaxi7

Poem

In the warren of code, a change takes flight,
Notifications trimmed, now feather-light.
Old fields and types have hopped away,
New methods leap in, here to stay.
With simpler forms and messages clear,
The rabbit cheers, "Less is more, my dear!"
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (3)
src/notifications/notifications.module.ts (1)

1-11: Restore required module dependencies in NotificationsModule

The current module setup only registers the Notification entity, but the service uses several other repositories and injected services whose providers are no longer available:

• TypeOrm repositories missing

  • NotificationDelivery (notification-delivery.entity.ts)
  • Preferences (preferences.entity.ts)
    • Injected services missing their modules
  • MailService ⇒ import MailModule
  • SmsService ⇒ import SmsModule
    • Auth entities used for typing (e.g. User) require either importing AuthModule or registering the User entity with TypeOrm
    • The ApplicationsModule import removal is safe if you only use the ApplicationStatus enum (no repository injection), otherwise re-add it

Please update src/notifications/notifications.module.ts to include these imports. For example:

 import { Module } from '@nestjs/common';
-import { TypeOrmModule } from '@nestjs/typeorm';
+import { TypeOrmModule } from '@nestjs/typeorm';
+import { MailModule } from '../mail/mail.module';
+import { SmsModule } from './services/sms.module';
+import { AuthModule } from '../auth/auth.module';        // for User metadata
 import { NotificationsService } from './notifications.service';
-import { Notification } from './entities/notification.entity';
+import { Notification } from './entities/notification.entity';
+import { NotificationDelivery } from './entities/notification-delivery.entity';
+import { Preferences } from './entities/preferences.entity';

 @Module({
-  imports: [TypeOrmModule.forFeature([Notification])],
+  imports: [
+    TypeOrmModule.forFeature([
+      Notification,
+      NotificationDelivery,
+      Preferences,
+    ]),
+    MailModule,
+    SmsModule,
+    AuthModule,
+  ],
   providers: [NotificationsService],
   exports: [NotificationsService],
 })
 export class NotificationsModule {}
src/notifications/notifications.service.ts (1)

1-44: Add missing module imports/providers for NotificationsService dependencies

The NotificationsModule currently only registers the Notification entity, but the service constructor also injects NotificationDelivery, Preferences, MailService, and SmsService. Without registering these, NestJS will throw unresolved provider errors.

• In src/notifications/notifications.module.ts
– Extend TypeOrmModule.forFeature to include NotificationDelivery and Preferences.
– Import and include the modules that provide MailService and SmsService (e.g. MailModule, SmsModule).

Example diff:

 import { Module, forwardRef } from '@nestjs/common';
 import { TypeOrmModule } from '@nestjs/typeorm';
-import { NotificationsService } from './notifications.service';
-import { Notification } from './entities/notification.entity';
+import { NotificationsService } from './notifications.service';
+import { Notification } from './entities/notification.entity';
+import { NotificationDelivery } from './entities/notification-delivery.entity';
+import { Preferences } from './entities/preferences.entity';
+import { MailModule } from '../mail/mail.module';
+import { SmsModule } from './services/sms.module';

 @Module({
-  imports: [TypeOrmModule.forFeature([Notification])],
+  imports: [
+    TypeOrmModule.forFeature([Notification, NotificationDelivery, Preferences]),
+    forwardRef(() => MailModule),
+    forwardRef(() => SmsModule),
+  ],
   providers: [NotificationsService],
   exports: [NotificationsService],
 })
 export class NotificationsModule {}

This will align your module imports/providers with the service’s constructor.

src/notifications/entities/notification.entity.ts (1)

9-33: Add a migration for Notification entity changes

No existing migrations touch the notifications table, so you’ll need to author one to keep your database schema in sync with the new entity:

• Create a TypeORM migration that alters the notifications table to match the updated Notification fields (e.g., new/modified columns, defaults).
• If you’re dropping or renaming any columns, ensure you handle data migration or deprecation in stages (make columns nullable → backfill → drop).
• Verify the migration runs cleanly against a copy of your production data.

🧹 Nitpick comments (4)
src/notifications/notifications.service.ts (2)

219-222: Fix code formatting issues.

The method implementation looks correct but has formatting issues flagged by ESLint. The logic for creating notifications with default type is sound.

-  async createNotification(userId: string, message: string, type: NotificationType = NotificationType.GENERAL): Promise<Notification> {
-    const notification = this.notificationRepository.create({ userId, message, type });
+  async createNotification(
+    userId: string,
+    message: string,
+    type: NotificationType = NotificationType.GENERAL,
+  ): Promise<Notification> {
+    const notification = this.notificationRepository.create({
+      userId,
+      message,
+      type,
+    });

224-230: Fix code formatting and approve method logic.

The method correctly retrieves user notifications with proper ordering and limiting. However, there are formatting issues to address.

-  async getUserNotifications(userId: string, limit = 20): Promise<Notification[]> {
+  async getUserNotifications(
+    userId: string,
+    limit = 20,
+  ): Promise<Notification[]> {
src/notifications/entities/notification.entity.ts (2)

1-1: Fix import formatting.

-import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index } from 'typeorm';
+import {
+  Entity,
+  PrimaryGeneratedColumn,
+  Column,
+  CreateDateColumn,
+  UpdateDateColumn,
+  Index,
+} from 'typeorm';

22-23: Fix column definition formatting.

-  @Column({ type: 'enum', enum: NotificationType, default: NotificationType.GENERAL })
+  @Column({
+    type: 'enum',
+    enum: NotificationType,
+    default: NotificationType.GENERAL,
+  })
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa0bd1f and dd16bfa.

📒 Files selected for processing (3)
  • src/notifications/entities/notification.entity.ts (2 hunks)
  • src/notifications/notifications.module.ts (1 hunks)
  • src/notifications/notifications.service.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/notifications/notifications.module.ts (4)
src/auth/auth.module.ts (1)
  • Module (31-89)
src/app.module.ts (1)
  • Module (35-107)
src/feed/feed.module.ts (1)
  • Module (14-31)
src/applications/applications.module.ts (1)
  • Module (11-17)
🪛 ESLint
src/notifications/notifications.service.ts

[error] 219-219: Replace userId:·string,·message:·string,·type:·NotificationType·=·NotificationType.GENERAL with ⏎····userId:·string,⏎····message:·string,⏎····type:·NotificationType·=·NotificationType.GENERAL,⏎··

(prettier/prettier)


[error] 220-220: Replace ·userId,·message,·type with ⏎······userId,⏎······message,⏎······type,⏎···

(prettier/prettier)


[error] 224-224: Replace userId:·string,·limit·=·20 with ⏎····userId:·string,⏎····limit·=·20,⏎··

(prettier/prettier)

src/notifications/entities/notification.entity.ts

[error] 1-1: Replace ·Entity,·PrimaryGeneratedColumn,·Column,·CreateDateColumn,·UpdateDateColumn,·Index· with ⏎··Entity,⏎··PrimaryGeneratedColumn,⏎··Column,⏎··CreateDateColumn,⏎··UpdateDateColumn,⏎··Index,⏎

(prettier/prettier)


[error] 22-22: Replace ·type:·'enum',·enum:·NotificationType,·default:·NotificationType.GENERAL with ⏎····type:·'enum',⏎····enum:·NotificationType,⏎····default:·NotificationType.GENERAL,⏎·

(prettier/prettier)

@Cybermaxi7
Copy link
Contributor

resolve conflicts @Spycall let's close this

@Cybermaxi7
Copy link
Contributor

please resolve your conflict so we can close this!
@Spycall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants