Mark notification as read
PUT/company/read/:id
Updates the status of a notification to mark it as read, recording the current date/time.
Use Cases:
- When a user opens/clicks a notification
- Synchronization between devices when reading notifications
- Bulk update of notification status
- Integration with activity tracking systems
Typical Flow:
- The client detects interaction with a notification (click, view in UI)
- Validates that the notification belongs to the current user
- Calls this endpoint with the notification ID
- The server:
- Validates the JWT token
- Verifies that the notification exists and belongs to the user's company
- Updates the isRead field to true
- Sets readedAt with the current date/time
- Returns the updated notification
- The client updates the UI locally
Considerations:
- Only notifications belonging to the user's company can be marked
- The operation is idempotent (multiple calls with the same ID cause no side effects)
- The readedAt field is set with the server's date/time, not the client's
Implementation Example:
// Example call from frontend
async function markNotificationAsRead(notificationId) {
try {
const response = await fetch(`/company/notifications/read/${notificationId}`, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${userToken}`,
'Content-Type': 'application/json'
}
});
if (response.ok) {
const updatedNotification = await response.json();
updateNotificationInUI(updatedNotification);
}
} catch (error) {
console.error('Error marking notification as read:', error);
}
}
Request
Responses
- 200
- 401
- 404
Notification marked as read.
Unauthorized - Invalid or missing JWT token
Notification not found - The ID does not correspond to an existing notification