DEV Community

Discussion on: NestJS: Using a generic service to provide base CRUD functionality

alessandro profile image

Hello, can you show me your model ? I have the mongoose Schema and one class model for validation. (class-validator). But they dont extends form thype Document. Can i exend from the Document class on the validation model without any problems ?

best regards, alessandro

paularah profile image
Paul Arah • Edited on

you can extend the Document type by creating an intersection type like this export type UserDocument = User & Document;and then pass the UserDocument type when you inject in your service. This is assuming you're using the InjectModel decorator that from the nestjs/mongose module. An example of what you would pass into your user service constructor would look like this @InjectModel( private readonly userModel: Model<UserDocument>