Skip to content

Add request validation for server and channel mutation APIs #18

@chthonn

Description

@chthonn

Difficulty: Intermediate

Context

Server and channel mutation routes in server/routes/servers.js accept several request body fields and MongoDB IDs. Some paths can fail with generic server errors when required fields are missing or malformed.

Improving validation will make the API easier to use, safer for contributors, and more predictable for the frontend.

Expected work

  • Validate required fields for creating servers, categories, and channels.
  • Validate MongoDB ObjectId values before constructing mongoose.Types.ObjectId.
  • Return consistent 400 responses for malformed input.
  • Return useful 404 responses when a referenced server/category does not exist.
  • Keep existing successful response shapes compatible with the frontend.

Acceptance criteria

  • Missing server_id, category_id, channel_name, or category_name returns a clear 400.
  • Invalid MongoDB IDs do not throw uncaught errors.
  • Failed updates return appropriate status codes instead of generic success-shaped responses.
  • Existing create server/category/channel flows still work.
  • Manual API testing or backend tests cover at least one valid and one invalid case.

Suggested files

  • server/routes/servers.js
  • server/services/serverService.js

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions