Problem
When a user posts a new answer, the system tries to create a notification for the question owner but it fails silently. The data payload passed to Notification.create() doesn't match the fields in the Notification Mongoose schema, so question owners never receive notifications for new answers.
Steps to Reproduce
- Log in as User A, post a question
- Log in as User B, post an answer to that question
- Check User A's notifications — nothing appears
- Check server logs — a Mongoose validation error is thrown but not surfaced to the client
Root Cause
In answersController.js, the notification object likely passes fields that don't match the exact field names/types defined in the Notification schema.
Expected Behavior
Posting an answer should create a valid notification for the question owner that appears in real-time and persists in the database.
Proposed Fix
- Audit the Notification schema fields and required types
- Update the notification payload in answersController.js to match the schema exactly
- Add try/catch around Notification.create() with proper error logging
- Add a test case verifying notification creation on answer submit
Problem
When a user posts a new answer, the system tries to create a notification for the question owner but it fails silently. The data payload passed to Notification.create() doesn't match the fields in the Notification Mongoose schema, so question owners never receive notifications for new answers.
Steps to Reproduce
Root Cause
In answersController.js, the notification object likely passes fields that don't match the exact field names/types defined in the Notification schema.
Expected Behavior
Posting an answer should create a valid notification for the question owner that appears in real-time and persists in the database.
Proposed Fix