crud-api-express 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/readme.md +36 -24
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -13,11 +13,14 @@ npm install crud-api-express
|
|
|
13
13
|
|
|
14
14
|
This project provides a flexible and reusable CRUD (Create, Read, Update, Delete) API controller for MongoDB using Express.js and Mongoose.
|
|
15
15
|
|
|
16
|
-
## Support Me!
|
|
16
|
+
## Support Me! ❤️
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
If you find this package useful, consider supporting me:
|
|
19
|
+
[Buy Me a Coffee ☕](https://buymeacoffee.com/mrider007)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📌 Table of Contents
|
|
21
24
|
|
|
22
25
|
- [Introduction](#introduction)
|
|
23
26
|
- [Installation](#installation)
|
|
@@ -28,11 +31,15 @@ For Your Support [Visit](https://buymeacoffee.com/mrider007).
|
|
|
28
31
|
- [Contributing](#contributing)
|
|
29
32
|
- [License](#license)
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🚀 Introduction
|
|
32
37
|
|
|
33
38
|
The `CrudController` class simplifies the creation of RESTful APIs in Node.js applications using MongoDB. It abstracts away common CRUD operations, error handling, middleware integration, and supports custom routes and aggregation pipelines.
|
|
34
39
|
|
|
35
|
-
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🔧 Usage
|
|
36
43
|
|
|
37
44
|
Here's a basic example of how to use `CrudController`:
|
|
38
45
|
|
|
@@ -124,29 +131,34 @@ mongoose
|
|
|
124
131
|
});
|
|
125
132
|
```
|
|
126
133
|
|
|
127
|
-
|
|
134
|
+
---
|
|
128
135
|
|
|
129
|
-
|
|
136
|
+
## 📖 API
|
|
130
137
|
|
|
131
|
-
|
|
138
|
+
### `getRouter(): Router`
|
|
132
139
|
Returns the Express Router instance configured with CRUD routes.
|
|
133
140
|
|
|
134
|
-
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## ⚙️ Options
|
|
144
|
+
|
|
135
145
|
|
|
136
146
|
### `CrudOptions<T>`
|
|
137
147
|
|
|
138
|
-
| Option
|
|
139
|
-
|
|
140
|
-
| `middleware`
|
|
141
|
-
| `onSuccess`
|
|
142
|
-
| `onError`
|
|
143
|
-
| `methods`
|
|
144
|
-
| `relatedModel`
|
|
145
|
-
| `relatedField`
|
|
146
|
-
| `relatedMethods`
|
|
147
|
-
| `aggregatePipeline` | `object[]`
|
|
148
|
-
| `customRoutes`
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
| Option | Type | Description |
|
|
149
|
+
|--------------------|---------------------------------------------------------------------------------------------------------|------------------------------------------------------|
|
|
150
|
+
| `middleware` | `((req: Request, res: Response, next: NextFunction) => void)[]` | Array of middleware functions |
|
|
151
|
+
| `onSuccess` | `(res: Response, method: string, result: T \| T[]) => void` | Success handler function |
|
|
152
|
+
| `onError` | `(res: Response, method: string, error: Error) => void` | Error handler function |
|
|
153
|
+
| `methods` | `('POST' \| 'GET' \| 'PUT' \| 'DELETE')[]` | Array of HTTP methods to support |
|
|
154
|
+
| `relatedModel` | `Model<any>` | Related Mongoose model for relational operations |
|
|
155
|
+
| `relatedField` | `string` | Field name for related models |
|
|
156
|
+
| `relatedMethods` | `('POST' \| 'GET' \| 'PUT' \| 'DELETE')[]` | Methods to apply on related models |
|
|
157
|
+
| `aggregatePipeline` | `object[]` | MongoDB aggregation pipeline stages |
|
|
158
|
+
| `customRoutes` | `{ method: 'post' \| 'get' \| 'put' \| 'delete', path: string, handler: (req: Request, res: Response) => void }[]` | Array of custom route definitions |
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## 📜 License
|
|
163
|
+
|
|
164
|
+
This project is licensed under the **ISC License**.
|