Mongoose/Typegoose service adapter for @nestjsx/crud
Nest.js + typegoose video (chinese):
Nest.js + Typegoose 中文视频教程请移步哔哩哔哩全栈之巅:
yarn add nestjs-crud-mongoose
# or
npm i nestjs-crud-mongoose
/src/users/users.service.ts
// for typegoose users
import { User } from "../../common/users/user.model";
import { Injectable, Inject } from "@nestjs/common";
import { ModelType } from "@typegoose/typegoose/lib/types";
import { MongooseCrudService } from "./mongoose-crud.service";
@Injectable()
export class UsersService extends MongooseCrudService<User>{
constructor(@Inject('UserModel') public model: ModelType<User>) {
super(model)
}
}
OR
// for mongoose users
import { User } from "../../common/users/user.model";
import { Injectable, Inject } from "@nestjs/common";
import { Model } from "mongoose";
import { MongooseCrudService } from "./mongoose-crud.service";
@Injectable()
export class UsersService extends MongooseCrudService<User>{
constructor(@Inject('UserModel') public model: Model<User>) {
super(model)
}
}
@Crud({
// ...
})
export class UsersController {
constructor(public service: UsersService) { }
}