Skip to content

[BUG] Notification creation fails silently due to schema mismatch when a new answer is posted #7

@akashnayak812

Description

@akashnayak812

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

  1. Log in as User A, post a question
  2. Log in as User B, post an answer to that question
  3. Check User A's notifications — nothing appears
  4. 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

  1. Audit the Notification schema fields and required types
  2. Update the notification payload in answersController.js to match the schema exactly
  3. Add try/catch around Notification.create() with proper error logging
  4. Add a test case verifying notification creation on answer submit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions