Skip to content

Add PUT /announcements/:id and Harden DELETE Route #18

@divyamagrawal06

Description

@divyamagrawal06

Description

Implement an update endpoint for announcements and improve validation on the existing delete endpoint.

1. Create PUT /api/announcements/:id

  • Allow partial updates for title, content, and priority.
  • Validate input:
    • At least one field must be present.
    • priority must be one of low, medium, high.
  • Use runValidators: true and return the updated document.
  • (Optional: Enable timestamps: true in the Announcement.js schema).

2. Harden DELETE /api/announcements/:id

  • Add ObjectId validation for the :id param.

Acceptance Criteria:

  • PUT /:id updates the correct document and returns it.
  • PUT /:id returns 400 if the body is empty or validation fails.
  • PUT /:id returns 404 for a valid ID that doesn't exist.
  • PUT and DELETE both return 400 for an invalid ObjectId format.
  • Existing frontend delete functionality continues to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions