Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/topfullstack/nestjs-crud-mongoose
mongoose service adapter for @nestjsx/crud
https://github.com/topfullstack/nestjs-crud-mongoose
crud mongoose nestjs restful-api typegoose
Last synced: 2 months ago
JSON representation
mongoose service adapter for @nestjsx/crud
- Host: GitHub
- URL: https://github.com/topfullstack/nestjs-crud-mongoose
- Owner: topfullstack
- License: mit
- Created: 2019-09-27T07:30:01.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T02:52:26.000Z (11 months ago)
- Last Synced: 2024-11-07T01:07:25.184Z (2 months ago)
- Topics: crud, mongoose, nestjs, restful-api, typegoose
- Language: TypeScript
- Size: 15.6 KB
- Stars: 9
- Watchers: 2
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nestjs-crud-mongoose
Mongoose/Typegoose service adapter for [@nestjsx/crud](https://github.com/nestjsx/crud)> Nest.js + typegoose video (chinese):
>
> Nest.js + Typegoose 中文视频教程请移步哔哩哔哩全栈之巅:
>
> https://space.bilibili.com/341919508## How to
### Install
```bash
yarn add nestjs-crud-mongoose
# or
npm i nestjs-crud-mongoose
```### Create a service based on a mongoose/typegoose model
`/src/users/users.service.ts````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{
constructor(@Inject('UserModel') public model: ModelType) {
super(model)
}
}
```OR
```ts
// 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{
constructor(@Inject('UserModel') public model: Model) {
super(model)
}
}```
### Inject `UsersService` to your `UsersController`:
```ts
@Crud({
// ...
})
export class UsersController {
constructor(public service: UsersService) { }
}
```## Thanks to
- https://github.com/nestjsx/crud
- https://github.com/nestjsx/crud/tree/master/packages/crud-typeorm## Related docs
- https://github.com/nestjsx/crud/wiki/ServiceTypeorm