#I meet such as this error, but owing to my lack of knowledge, I can't handle error asap.

4 messages · Page 1 of 1 (latest)

warm mortar
#
// repository
import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Model } from 'mongoose'
import { Role, RoleDocument } from '../schemas/role.schema'
import { CreateRoleDto } from '../dtos'

@Injectable()
export class RoleRepository {
  constructor(
    @InjectModel(Role.name)
    private readonly roleModel: Model<Role>,
  ) { }
  async roleRegist(body: CreateRoleDto): Promise<RoleDocument> {
    console.log("roleRegist", body);
    return
  }
}

// controller
import { Controller, Body, Post, Req, Res, UseGuards } from '@nestjs/common'
import { RoleService } from './role.service'
import { AuthGuard } from '@nestjs/passport'

@Controller('role')
export class RoleController {
    constructor(
        private readonly roleService: RoleService,
    ) { }
    @Post('regist')
    async regit(@Body() body: any) {
        const result = await this.roleService.roleRegist(body)
        console.log('result', result);
        return []
    }
}

// module
import { Module } from '@nestjs/common'
import { RoleController } from './role.controller'
import { RoleService } from './role.service'
import { MongooseModule } from '@nestjs/mongoose';
import { Role, RoleSchema } from './schemas/role.schema';

@Module({
    imports: [MongooseModule.forFeature([{ name: Role.name, schema: RoleSchema }])],
    controllers: [RoleController],
    providers: [
        RoleService
    ],
})
export class RoleModule { }

// service
import { Module } from '@nestjs/common'
import { RoleController } from './role.controller'
import { RoleService } from './role.service'
import { MongooseModule } from '@nestjs/mongoose';
import { Role, RoleSchema } from './schemas/role.schema';

@Module({
    imports: [MongooseModule.forFeature([{ name: Role.name, schema: RoleSchema }])],
    controllers: [RoleController],
    providers: [
        RoleService
    ],
})
export class RoleModule { }

what is the essential of this matter?

blazing halo
#

WHat's the RoleService look like?

#

More than likely, you need to add the RoleRepository to the providers array of the RoleMdoule

warm mortar
#

amazing! Thank you@ really