#Uknown Column but other where cases are working

1 messages · Page 1 of 1 (latest)

summer pasture
#

Move the @Get(':id') route handler to below the other one

obsidian scarab
#

it worked but i dont undertstand why i mean what is difference if get id route was above

#

can you explain?

summer pasture
#

':id' is a wildcard route matcher, essentially a '*' where it captures what that value is. So when you call GET /getEnded it matches the ':id' route first and doesn't make it to your other route handler

obsidian scarab
#

if i call getended :id still executes?

#

i mean getone

#

?

summer pasture
#

Where is @Get('getOne') in your controller?

obsidian scarab
#

import {Controller, Get, Body, Param, UseGuards} from '@nestjs/common';
import { TechnologiesService } from "./technologies.service";
import {AuthGuard} from "@nestjs/passport";

@Controller('technologies')
export class TechnologiesController {
constructor(private readonly technologiesService: TechnologiesService) {}

@UseGuards(AuthGuard('jwt'))
@Get('getAll')
getAll() {
return this.technologiesService.getAll()
}
@UseGuards(AuthGuard('jwt'))
@Get('getEnded')
getEnded() {
return this.technologiesService.findByLevel()
}

@UseGuards(AuthGuard('jwt'))
@Get('/:id')
getOne(@Param('id') id: string) {
return this.technologiesService.getOne(+id)
}

}

summer pasture
obsidian scarab
#

i call getEnded but i dont understand why this wildcard works like this if it means * if i call getEnded why it still checks /:id

summer pasture
#

This is after moving theroute and re-compiling and restarting the server, right?

obsidian scarab
#

yes

#

it works

#

but i dont understand

summer pasture
#

What isn't clear?

obsidian scarab
#

can you explain me more why wildcard works like this like why it was not working when getone was written before getended

summer pasture
#

It's just how express runs through the routes. It checks each one that the router is aware of and checks "does this url match the route?" So, in the old case

  • Make GET /technoligies/getEnded
  • Match technologies router
  • Iterate over getOne, :id, getEnded, etc
  • Does getEnded match getOne? No, move on
  • Does getEnded match :id? This is essnetially a regex of .* so yes, it matches, call this handler
  • Return the response from the handler and stop checking other paths