For the purpose of spawning, I have created a unique custom decorator.
In order to utilize the decorator effectively, it is essential to provide the mongoose model.
This can be achieved by passing the 'mongoose' model to the provider as shown below:
export const dbModelsProviders: FactoryProvider[] = [
{
provide: Db.USER_MODEL,
useFactory: (connection: Connection): Model<IUser> => connection.model('User', userSchema),
inject: [Db.DATABASE_CONNECTION]
}
];
To facilitate seamless implementation, ensure to pass this provider parameter to another decorator or through an alternate method like so:
@Crud({
name: 'Test',
defaultDto: TestDto,
defaultResponseDto: TestDto,
model: <--
})
@Controller()
export class AppController {}