T
T
teertsneerg2021-06-04 12:12:45
Node.js
teertsneerg, 2021-06-04 12:12:45

How to solve the problem with dependencies?

I am using NestJS.

rememberLink.schema.ts

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';
import { User } from 'src/users/schemas/users.schema';

export type RememberLinkDocument = RememberLink & Document;

@Schema({versionKey: false, timestamps: true})
export class RememberLink {
    @Prop({ type: String, required: true })
    code: string;

    @Prop({ type: Types.ObjectId, ref: User.name, required: true })
    user: User;
}

export const RememberLinkSchema = SchemaFactory.createForClass(RememberLink);


remember-password.service.ts
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { UserDto } from 'src/users/dto/user.dto';
import { User } from 'src/users/schemas/users.schema';
import { RememberLinkDto } from './dto/rememberLink.dto';
import { RememberLink, RememberLinkDocument } from './schemas/rememberLink.schema';

@Injectable()
export class RememberPasswordService {

    constructor( @InjectModel(RememberLink.name) private readonly rememberLinkModel: Model<RememberLinkDocument> ) {}

    ...
}


remember-password.module.ts
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { RememberPasswordController } from './remember-password.controller';
import { RememberPasswordService } from './remember-password.service';
import { RememberLink, RememberLinkSchema } from './schemas/rememberLink.schema';

@Module({
    imports: [
        MongooseModule.forFeature([{
            name: RememberLink.name,
            schema: RememberLinkSchema
        }])
    ],
    controllers: [RememberPasswordController],
    providers: [RememberPasswordService],
    exports: [RememberPasswordService]
})
export class RememberPasswordModule {}


Error: Nest can't resolve dependencies of the RememberPasswordService (?). Please make sure that the argument RememberLinkModel at index [0] is available in the RememberPasswordService context.

MongooseModule.forRoot is in app.module. Connecting models in other modules works, everything seems to be the same. What is the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question