joseph bandawe
joseph bandawe

Reputation: 1

Controller methods not being mapped in nestjs

I have a nestjs module called AuthModule

    import { Module } from '@nestjs/common';

import { AuthService } from './auth.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersEntity } from './user-auth-credentials.entity';
import { UsersRepository } from './users.repository';
import { AuthController } from './auth.controller';

@Module({
  imports: [TypeOrmModule.forFeature([UsersRepository])],
  controllers: [AuthController],
  providers: [AuthService],
})
export class AuthModule {}

a controller called **AuthController**.

    import { Controller, Get } from '@nestjs/common';
import { AuthService } from './auth.service';

@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}

  @Get()
  findAll() {
    return 'Hello World';
  }
}

The methods in the controller findAll as an example are not being mapped during compiling as shown by the output of npm run start:dev below.

[12:36:39] File change detected. Starting incremental compilation...

[12:36:39] Found 0 errors. Watching for file changes.

[Nest] 4262  - 09/03/2022, 12:36:40     LOG [NestFactory] Starting Nest application...
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TypeOrmModule dependencies initialized +122ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +73ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] AuthModule dependencies initialized +0ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TeachersModule dependencies initialized +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RoutesResolver] AppController {/}: +7ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/, GET} route +4ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RoutesResolver] TeachersController {/teachers}: +0ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers, GET} route +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers/id, GET} route +2ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers, POST} route +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers/id, PATCH} route +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers/id, DELETE} route +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RoutesResolver] AuthController {/auth}: +0ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [NestApplication] Nest application successfully started +4ms

When I access the route using Insomnia i get this

output of Insomnia

Is there something Im not doing right?

Upvotes: 0

Views: 1412

Answers (1)

Micael Levi
Micael Levi

Reputation: 6665

your code looks fine but the output didn't show any Mapped {/auth, GET}. I'd say that you're probably running an old version of the your code (which doesn't have that findAll method)

Try rm -rf dist and start it again.

Upvotes: 0

Related Questions