#Nest can't resolve dependencies of the ...

8 messages · Page 1 of 1 (latest)

vivid goblet
#

Hey i have trouble to solve the dependency of my controller. I got this problem very often, and i have no idea how to sole them quickly and clean.
If anybody have a process, or anything that can help me to solve those quickly, i would appreciate it alot, because when i have this kind of problems, im just jugling randomly with the import / export /provider in the module awaiting magic to happen.

In my current case i can't find wich changes i need to make...

// groupe.module.ts
@Module({
  imports: [TypeOrmModule.forFeature([Group, Draw, Calls])],
  providers: [GroupService],
  controllers: [GroupController],
  exports:[GroupService]
})
export class GroupeModule {}

My entity

// groupe.entity.ts

@Entity()
export class Group {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToMany(() => Calls)
  @JoinTable()
  calls: Calls[];

  @ManyToMany(() => Draw)
  @JoinTable()
  draws: Draw[];
}

app module


@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'happidb',
      autoLoadEntities: true,
      entities: [],
      synchronize: true,
    }),
    CallsModule,
    ResponseModule,
    DrawModule,
    GroupeModule
],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

ERROR [ExceptionHandler] Nest can't resolve dependencies of the GroupController (?). Please make sure that the argument GroupService at index [0] is available in the GroupeModule context.

smoky glade
#

you need to show us the controller's constructor, the basic logic is that whatever you inject in an "injectable" class should be imported in the current module.

drifting mason
#

@vivid goblet -
export class GroupeModule
Is it Group or Groupe? 🤔

#

I'm surprised you aren't seeing different errors.

solar stirrup
#

what is the code inside GroupCotroller ?

vivid goblet
#

This is the group controller :

// Group.controller.ts

import { Controller, Get, Post, Param, Body } from '@nestjs/common';
import { GroupService } from './Group.service';
import { Group } from './models/group.entity';


@Controller('groups')
export class GroupController {
  constructor(private readonly GroupService: GroupService) {}

  @Post()
  async create(@Body() GroupData: Group): Promise<Group> {
    return await this.GroupService.createGroup(GroupData);
  }

  @Get()
  async findAll(): Promise<Group[]> {
    return await this.GroupService.findAllGroups();
  }

  @Get(':id')
  async findOne(@Param('id') id: string): Promise<Group> {
    return await this.GroupService.findGroupById(+id);
  }
}```
vivid goblet
languid pewter