Skip to main content

Delete notification

DELETE 

/company/:id

Permanently delete a system notification. This action cannot be undone.

Use Cases:

  • When the user clears old notifications
  • Bulk deletion of notifications
  • Compliance with data deletion requests
  • Automated cleanup of expired notifications

Typical Flow:

  1. User selects Delete option on a notification
  2. Client displays confirmation to the user
  3. If confirmed:
    • Calls this endpoint with the notification ID
    • The server:
      • Validates the JWT token
      • Verifies the notification exists and belongs to the user's company
      • Permanently deletes the record from the database
    • Returns the deleted notification
  4. Client removes the notification from the UI locally

Considerations:

  • Only notifications belonging to the user's company can be deleted
  • Deletion is permanent and irreversible
  • Client-side confirmation is recommended before calling the endpoint
  • For bulk deletions, consider implementing a batch endpoint

Implementation Example:

// Example frontend call
async function deleteNotification(notificationId) {
if (confirm('Are you sure you want to delete this notification?')) {
try {
const response = await fetch(`/company/notifications/${notificationId}`, {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${userToken}`
}
});

if (response.ok) {
const deletedNotification = await response.json();
removeNotificationFromUI(deletedNotification._id);
}
} catch (error) {
console.error('Error deleting notification:', error);
}
}
}

System Impact:

  • Reduces storage usage
  • Improves performance in future queries
  • Permanently removes sensitive data

Request

Responses

Notification successfully deleted.