mongodb-dynamic-api 1.3.1 → 1.3.2
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/CHANGELOG.md +2 -0
- package/README.md +29 -11
- package/package.json +1 -1
- package/src/version.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.2](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v1.3.1...v1.3.2) (2024-03-05)
|
|
4
|
+
|
|
3
5
|
## [1.3.1](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v1.3.0...v1.3.1) (2024-03-05)
|
|
4
6
|
|
|
5
7
|
## [1.3.0](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v1.2.1...v1.3.0) (2024-03-04)
|
package/README.md
CHANGED
|
@@ -103,7 +103,9 @@ export class AppModule {}
|
|
|
103
103
|
**Basic Usage**
|
|
104
104
|
|
|
105
105
|
- Ok, now let's add our first content with just 2 files. It will be a simple `User` with a `name` and an `email` field.
|
|
106
|
-
- We use the `@Schema` and `@Prop` decorators from the `@nestjs/mongoose` package to define our MongoDB model.
|
|
106
|
+
- We use the `@Schema` and `@Prop` decorators from the `@nestjs/mongoose` package to define our MongoDB model. <br>*See <strong>nestjs</strong> <a href="https://docs.nestjs.com/techniques/mongodb#model-injection" target="_blank">documentation</a> for more details.*
|
|
107
|
+
|
|
108
|
+
|
|
107
109
|
- You must extend the `BaseEntity` (or `SoftDeletableEntity`) class from the `mongodb-dynamic-api` package **for all your collection models**.
|
|
108
110
|
- Just create a new file `user.ts` and add the following code.
|
|
109
111
|
|
|
@@ -114,10 +116,10 @@ import { BaseEntity } from 'mongodb-dynamic-api';
|
|
|
114
116
|
|
|
115
117
|
@Schema({ collection: 'users' })
|
|
116
118
|
export class User extends BaseEntity {
|
|
117
|
-
@Prop({ type: String })
|
|
119
|
+
@Prop({ type: String, required: true })
|
|
118
120
|
name: string;
|
|
119
121
|
|
|
120
|
-
@Prop({ type: String })
|
|
122
|
+
@Prop({ type: String, required: true })
|
|
121
123
|
email: string;
|
|
122
124
|
}
|
|
123
125
|
```
|
|
@@ -165,7 +167,23 @@ export class AppModule {}
|
|
|
165
167
|
|
|
166
168
|
**And that's all !** *You now have a fully functional CRUD API for the `User` content at the `/users` path.*
|
|
167
169
|
|
|
168
|
-
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
| Endpoint | Body | Param | Query |
|
|
173
|
+
|:--------------------------------------------------|:----------------------------------------------:|:------------:|:---------------:|
|
|
174
|
+
| **GET /users** <br>*Get many* | x | x | x |
|
|
175
|
+
| **GET /users/:id** <br>*Get one* | x | `id: string` | x |
|
|
176
|
+
| **POST /users/many** <br>*Create many* | `{ list: [{ name: string; email: string; }] }` | x | x |
|
|
177
|
+
| **POST /users** <br>*Create one* | `{ name: string; email: string; }` | x | x |
|
|
178
|
+
| **PUT /users/:id** <br>*Replace one* | `{ name: string; email: string; }` | `id: string` | x |
|
|
179
|
+
| **PATCH /users** <br>*Update many* | `{ name?: string; email?: string; }` | x | `ids: string[]` |
|
|
180
|
+
| **PATCH /users/:id** <br>*Update one* | `{ name?: string; email?: string; }` | `id: string` | x |
|
|
181
|
+
| **DELETE /users** <br>*Delete many* | x | x | `ids: string[]` |
|
|
182
|
+
| **DELETE /users/:id** <br>*Delete one* | x | `id: string` | x |
|
|
183
|
+
| **POST /users/duplicate** <br>*Duplicate many* | `{ name?: string; email?: string; }` | x | `ids: string[]` |
|
|
184
|
+
| **POST /users/duplicate/:id**<br>*Duplicate one* | `{ name?: string; email?: string; }` | `id: string` | x |
|
|
185
|
+
|
|
186
|
+
|
|
169
187
|
### [Swagger UI](https://docs.nestjs.com/openapi/introduction#document-options) (optional but strongly recommended)
|
|
170
188
|
`function enableDynamicAPISwagger(app: INestApplication, options?: DynamicAPISwaggerOptions): void`
|
|
171
189
|
|
|
@@ -200,15 +218,15 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
|
200
218
|
@Schema({ collection: 'users' })
|
|
201
219
|
export class User extends BaseEntity {
|
|
202
220
|
@ApiProperty() // <- add this line
|
|
203
|
-
@Prop({ type: String })
|
|
221
|
+
@Prop({ type: String, required: true })
|
|
204
222
|
name: string;
|
|
205
223
|
|
|
206
224
|
@ApiProperty() // <- add this line
|
|
207
|
-
@Prop({ type: String })
|
|
225
|
+
@Prop({ type: String, required: true })
|
|
208
226
|
email: string;
|
|
209
227
|
|
|
210
228
|
@ApiPropertyOptional() // <- add this line
|
|
211
|
-
@Prop({ type: String
|
|
229
|
+
@Prop({ type: String })
|
|
212
230
|
company?: string;
|
|
213
231
|
}
|
|
214
232
|
```
|
|
@@ -284,16 +302,16 @@ import { IsEmail } from 'class-validator';
|
|
|
284
302
|
@Schema({ collection: 'users' })
|
|
285
303
|
export class User extends BaseEntity {
|
|
286
304
|
@ApiProperty()
|
|
287
|
-
@Prop({ type: String })
|
|
305
|
+
@Prop({ type: String, required: true })
|
|
288
306
|
name: string;
|
|
289
307
|
|
|
290
308
|
@ApiProperty()
|
|
291
309
|
@IsEmail()
|
|
292
|
-
@Prop({ type: String })
|
|
310
|
+
@Prop({ type: String, required: true })
|
|
293
311
|
email: string;
|
|
294
312
|
|
|
295
313
|
@ApiPropertyOptional()
|
|
296
|
-
@Prop({ type: String
|
|
314
|
+
@Prop({ type: String })
|
|
297
315
|
company?: string;
|
|
298
316
|
}
|
|
299
317
|
```
|
|
@@ -463,7 +481,7 @@ export class AppModule {}
|
|
|
463
481
|
|
|
464
482
|
**Usage**
|
|
465
483
|
|
|
466
|
-
|
|
484
|
+
When you request the `/users` route with the `GET` method, the response will be cached until the cache expires or until the maximum number of items is reached or until a request like `POST`, `PUT`, `PATCH`, or `DELETE` is made on the same route.
|
|
467
485
|
<br><br>Let's inspect the behavior in the network tab of our browser
|
|
468
486
|
<br>We expected to see a code `200` for the first GET request, a code `304`* for the second GET request, and again a code `200` for the third GET request made after the POST request.
|
|
469
487
|
|
package/package.json
CHANGED
package/src/version.json
CHANGED