The :id route is declared first, and it matches me too. With the Express platform, Nest registers routes in the order the handlers appear in the class. The :id pattern matches any single path segment, including the word me. So the :id handler matches /users/me first, and findOne("me") runs.
Fixes:
- Declare static routes before routes with params. Put
@Get("me")above@Get(":id"). - Make the param stricter by validating it, for example with
ParseUUIDPipeorParseIntPipe. Then a bad value fails with a 400 error, instead of silently reaching the wrong logic.
The general rule for any wildcard or param route: put the more specific routes first.
- Routes are matched in the order they are declared.
:idmatches any segment, includingme.- Declare static routes before routes with params.
- Validate params with
ParseUUIDPipeorParseIntPipe.
Read more
- Controllers (https://docs.nestjs.com/controllers)docs.nestjs.com