bug: notes/databases/[id] GET/PATCH/DELETE 500 on malformed id (missing ObjectId.isValid)

Open Beginner friendly
#47 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
mongodb, typescript
Domain
api, backend, database

Research direction

Start in src/app/api/notes/databases/[id]/route.ts and compare its GET, PATCH, and DELETE handlers with rows/route.ts and rows/[rowId]/route.ts, which show the existing validation pattern. Verify that malformed IDs return 404 rather than an uncaught CastError for all three handlers.

Written by the indexing model from the issue text.

Description

bug

Description

src/app/api/notes/databases/[id]/route.ts passes the raw id straight into Mongoose (findOne/findOneAndUpdate/deleteOne({ _id: id, ... })) with no ObjectId.isValid guard and no try/catch — GET (:13-15), PATCH (:36/:78), DELETE (:87-88). A non-ObjectId id throws a Mongoose CastError that is never caught. The sibling row routes already validate (rows/route.ts:14, rows/[rowId]/route.ts:22), confirming the inconsistency.

Failure scenario

GET /api/notes/databases/not-an-id → uncaught CastError500 instead of a clean 404.

Fix

Add the same mongoose.Types.ObjectId.isValid(id) early-return-404 used by the row routes to all three handlers.

Severity

Low-Medium (robustness).

Dominant language
TypeScript
Stars
2
Forks
4
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TemaDeveloper/personal_planner

All issues in TemaDeveloper/personal_planner

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.