Skip to content

Notifications setup #45

@ndahimana154

Description

@ndahimana154

Task Description: Notifications Backend Setup

1. Database Setup

  • Create a Notification table in your database with fields for id, userId, title, description, isRead, createdAt, and updatedAt.
  • Ensure the userId is a foreign key linked to the Users table to associate notifications with specific users.
  • Add isRead as a boolean field to track whether a notification has been viewed by the user.

2. Notification Model

  • Define a Notification model in your ORM (e.g., Sequelize).
  • Set up an association between the Notification model and the User model, ensuring that each notification belongs to a specific user.

3. Middleware to Create a Notification on Login

  • Modify the login logic in your authentication controller to create a notification whenever a user logs in.
  • The notification should include a title (e.g., "New Login Detected") and a description (e.g., "You have logged in to your account").
  • Add this logic after successful user authentication and token generation.

4. Fetch Notifications

  • Create an endpoint to fetch all notifications for the logged-in user.
  • Ensure the notifications are filtered by userId and sorted by creation time (most recent first).
  • Return the list of notifications in the response for display on the frontend.

5. Mark Notification as Read

  • Create an endpoint to mark a specific notification as read.
  • Use the notification ID and the logged-in user's ID to find and update the relevant notification.
  • Update the isRead field to true and save the changes.

6. Testing

  • Test the system by logging in and verifying that a new notification is created in the database.
  • Fetch the notifications to ensure the logged-in user can view them.
  • Mark a notification as read and confirm the isRead field is updated in the database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions