-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Task Description: Notifications Backend Setup
1. Database Setup
- Create a
Notificationtable in your database with fields forid,userId,title,description,isRead,createdAt, andupdatedAt. - Ensure the
userIdis a foreign key linked to theUserstable to associate notifications with specific users. - Add
isReadas a boolean field to track whether a notification has been viewed by the user.
2. Notification Model
- Define a
Notificationmodel in your ORM (e.g., Sequelize). - Set up an association between the
Notificationmodel and theUsermodel, 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
userIdand 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
isReadfield totrueand 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
isReadfield is updated in the database.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
No status