NestJs MongoDB Base Crud Api
Usage
Installation
npm i nestjs-mongo-crud-base
Importing library
In your service you can import the BaseRepositoryService and extends your custom service
;;;;; @<Hero> { superheroModel; }
In your controller you can import the BaseController and extends your custom controller
; ;;;;; @@<Hero> { superheroService }
IBaseService<T> : Promise<T>; : Promise<T>; : Promise<T>; : Promise<T>; : Promise<T>; : Promise<any>; deleteid: any ...args: any: Promise<any>;
Service functions
Function | Description |
---|---|
findAll | Return all collection data with pagination if provided. |
findOne | Return a collection data by id. |
findOneBy | Return one corresponding collection data with the query provided. |
findBy | Return all corresponding collection data with the query provided. |
update | Update data by id. |
create | Create new data. |
delete | Remove data by id. |
Examples Hero Endpoins
endpoint | method | description |
---|---|---|
/heros OR /heros?page=1&limit=10 | GET | Return all heros with pagination if provided. |
/heros/:id | GET | Return a hero by id. |
/heros/:id | put | update a hero by id. |
/heros | post | Create new data. |
/heros/:id | delete | Remove data by id. |