You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+74-67
Original file line number
Diff line number
Diff line change
@@ -33,15 +33,16 @@
33
33
-[Service](#service)
34
34
-[Controller](#controller)
35
35
-[API Endpoints](#api-endpoints)
36
+
-[Swagger](#swagger)
36
37
-[Query Parameters](#query-parameters)
37
38
-[Repository Service](#repository-service)
38
39
-[Restful Options](#restful-options)
39
40
-[Crud Controller](#crud-controller)
41
+
-[Restful Options merge](#restful-options-merge)
42
+
-[Path Filter](#path-filter)
40
43
-[Validation](#validation)
41
44
-[IntelliSense](#intellisense)
42
45
-[Method Override](#method-override)
43
-
-[Restful Options merge](#restful-options-merge)
44
-
-[Path Filter](#path-filter)
45
46
-[Additional Decorators](#additional-decorators)
46
47
-[Example Project](#example-project)
47
48
-[Contribution](#contribution)
@@ -184,6 +185,10 @@ _Request Params:_ `:id` - entity id
184
185
_Result:_: empty | error object
185
186
_Status codes:_ 200 | 404
186
187
188
+
## Swagger
189
+
190
+
[Swagger](https://docs.nestjs.com/recipes/swagger) support is present out of the box, including [Query Parameters](#query-parameters) and [Path Filter](#path-filter).
191
+
187
192
## Query Parameters
188
193
189
194
`GET` endpoints that are generated by CRUD controller support some useful query parameters (all of them are _optional_):
@@ -533,7 +538,70 @@ Cache can be [reseted](#cache) by using the query parameter in your `GET` reques
533
538
534
539
## Crud Controller
535
540
536
-
Our newly generated working horse. Let's dive in some details.
541
+
Our newly generated working horse. `@Crud()` decorator accepts two arguments - Entity class and `CrudOptions` object. Let's dive in some details.
542
+
543
+
### Restful Options merge
544
+
545
+
```typescript
546
+
...
547
+
import { Crud } from'@nestjsx/crud';
548
+
549
+
@Crud(Hero, {
550
+
options: {
551
+
// RestfulOptions goes here
552
+
}
553
+
})
554
+
@Controller('heroes')
555
+
exportclassHeroesCrudController {
556
+
constructor(publicservice:HeroesService) {}
557
+
}
558
+
```
559
+
560
+
`CrudOptions` object may have `options` parameter which is the same object as [Restful Options](#restful-options).
561
+
562
+
**_Notice:_** If you have this options set up in your `RepositoryService`, in that case they will be **merged**.
563
+
564
+
### Path Filter
565
+
566
+
`CrudOptions` object may have `params` parameter that will be used for auto filtering by URL path parameters.
567
+
568
+
Assume, you have an entity `User` that belongs to some `Company` and has a field `companyId`. And you whant to create `UsersController` so that an admin could access users from his own Company only. Let's do this:
569
+
570
+
```typescript
571
+
...
572
+
import { Crud } from'@nestjsx/crud';
573
+
574
+
@Crud(Hero, {
575
+
params: ['companyId']
576
+
})
577
+
@Controller('/company/:companyId/users')
578
+
exportclassUsersCrud {
579
+
constructor(publicservice:UsersService) {}
580
+
}
581
+
```
582
+
583
+
In this example you're URL param name `companyId` should match the name of `User.companyId` field. If not, you can do mapping, like this:
584
+
585
+
```typescript
586
+
...
587
+
import { Crud } from'@nestjsx/crud';
588
+
589
+
@Crud(Hero, {
590
+
params: {
591
+
company: 'companyId'
592
+
}
593
+
})
594
+
@Controller('/company/:company/users')
595
+
exportclassUsersCrud {
596
+
constructor(publicservice:UsersService) {}
597
+
}
598
+
```
599
+
600
+
Where `company` is the name of the URL param, and `companyId` is the name of the entity field.
601
+
602
+
As you might guess, all request will add `companyId` to the DB queries alongside with the `:id` of `GET`, `PATCH`, `DELETE` requests. On `POST` (both: one and bulk) requests, `companyId` will be added to the `dto` automatically.
603
+
604
+
When you done with the controller, you'll need to add some logic to your `AuthGuard` or any other interface, where you do the authorization of a requester. You will need to match `companyId` URL param with the `user.companyId` entity that has been validated from the DB.
Controller can accept optioanl `options` parameter and it's the same object as [Restful Options](#restful-options). It's very useful when you have one `RepositoryService` and several controllers.
742
-
743
-
**_Notice:_** If you have this options set up in your `RepositoryService`, in that case they will be **merged**.
744
-
745
-
### Path Filter
746
-
747
-
Assume, you have an entity `User` that belongs to some `Company` and has a field `companyId`. And you whant to create `UsersController` so that an admin could access users from his own Company only. Let's do this:
Where `company` - name of the URL param, and `companyId` - name of the entity field.
782
-
783
-
As you might guess, all request will add `companyId` to the DB queries alongside with the `:id` of `GET`, `PATCH`, `DELETE` requests. On `POST` (both: one and bulk) requests, `companyId` will be added to the `dto` automatically.
784
-
785
-
When you done with the controller, you'll need to add some logic to your `AuthGuard` or any other interface, where you do the authorization of a requester. You will need to match `companyId` URL param with the `user.companyId` entity that has been validated from the DB.
786
-
787
794
### Additional Decorators
788
795
789
796
There are two additional decorators that come out of the box: `@Feature()` and `@Action()`:
Copy file name to clipboardexpand all lines: dist/README.md
+74-67
Original file line number
Diff line number
Diff line change
@@ -33,15 +33,16 @@
33
33
-[Service](#service)
34
34
-[Controller](#controller)
35
35
-[API Endpoints](#api-endpoints)
36
+
-[Swagger](#swagger)
36
37
-[Query Parameters](#query-parameters)
37
38
-[Repository Service](#repository-service)
38
39
-[Restful Options](#restful-options)
39
40
-[Crud Controller](#crud-controller)
41
+
-[Restful Options merge](#restful-options-merge)
42
+
-[Path Filter](#path-filter)
40
43
-[Validation](#validation)
41
44
-[IntelliSense](#intellisense)
42
45
-[Method Override](#method-override)
43
-
-[Restful Options merge](#restful-options-merge)
44
-
-[Path Filter](#path-filter)
45
46
-[Additional Decorators](#additional-decorators)
46
47
-[Example Project](#example-project)
47
48
-[Contribution](#contribution)
@@ -184,6 +185,10 @@ _Request Params:_ `:id` - entity id
184
185
_Result:_: empty | error object
185
186
_Status codes:_ 200 | 404
186
187
188
+
## Swagger
189
+
190
+
[Swagger](https://docs.nestjs.com/recipes/swagger) support is present out of the box, including [Query Parameters](#query-parameters) and [Path Filter](#path-filter).
191
+
187
192
## Query Parameters
188
193
189
194
`GET` endpoints that are generated by CRUD controller support some useful query parameters (all of them are _optional_):
@@ -533,7 +538,70 @@ Cache can be [reseted](#cache) by using the query parameter in your `GET` reques
533
538
534
539
## Crud Controller
535
540
536
-
Our newly generated working horse. Let's dive in some details.
541
+
Our newly generated working horse. `@Crud()` decorator accepts two arguments - Entity class and `CrudOptions` object. Let's dive in some details.
542
+
543
+
### Restful Options merge
544
+
545
+
```typescript
546
+
...
547
+
import { Crud } from'@nestjsx/crud';
548
+
549
+
@Crud(Hero, {
550
+
options: {
551
+
// RestfulOptions goes here
552
+
}
553
+
})
554
+
@Controller('heroes')
555
+
exportclassHeroesCrudController {
556
+
constructor(publicservice:HeroesService) {}
557
+
}
558
+
```
559
+
560
+
`CrudOptions` object may have `options` parameter which is the same object as [Restful Options](#restful-options).
561
+
562
+
**_Notice:_** If you have this options set up in your `RepositoryService`, in that case they will be **merged**.
563
+
564
+
### Path Filter
565
+
566
+
`CrudOptions` object may have `params` parameter that will be used for auto filtering by URL path parameters.
567
+
568
+
Assume, you have an entity `User` that belongs to some `Company` and has a field `companyId`. And you whant to create `UsersController` so that an admin could access users from his own Company only. Let's do this:
569
+
570
+
```typescript
571
+
...
572
+
import { Crud } from'@nestjsx/crud';
573
+
574
+
@Crud(Hero, {
575
+
params: ['companyId']
576
+
})
577
+
@Controller('/company/:companyId/users')
578
+
exportclassUsersCrud {
579
+
constructor(publicservice:UsersService) {}
580
+
}
581
+
```
582
+
583
+
In this example you're URL param name `companyId` should match the name of `User.companyId` field. If not, you can do mapping, like this:
584
+
585
+
```typescript
586
+
...
587
+
import { Crud } from'@nestjsx/crud';
588
+
589
+
@Crud(Hero, {
590
+
params: {
591
+
company: 'companyId'
592
+
}
593
+
})
594
+
@Controller('/company/:company/users')
595
+
exportclassUsersCrud {
596
+
constructor(publicservice:UsersService) {}
597
+
}
598
+
```
599
+
600
+
Where `company` is the name of the URL param, and `companyId` is the name of the entity field.
601
+
602
+
As you might guess, all request will add `companyId` to the DB queries alongside with the `:id` of `GET`, `PATCH`, `DELETE` requests. On `POST` (both: one and bulk) requests, `companyId` will be added to the `dto` automatically.
603
+
604
+
When you done with the controller, you'll need to add some logic to your `AuthGuard` or any other interface, where you do the authorization of a requester. You will need to match `companyId` URL param with the `user.companyId` entity that has been validated from the DB.
Controller can accept optioanl `options` parameter and it's the same object as [Restful Options](#restful-options). It's very useful when you have one `RepositoryService` and several controllers.
742
-
743
-
**_Notice:_** If you have this options set up in your `RepositoryService`, in that case they will be **merged**.
744
-
745
-
### Path Filter
746
-
747
-
Assume, you have an entity `User` that belongs to some `Company` and has a field `companyId`. And you whant to create `UsersController` so that an admin could access users from his own Company only. Let's do this:
Where `company` - name of the URL param, and `companyId` - name of the entity field.
782
-
783
-
As you might guess, all request will add `companyId` to the DB queries alongside with the `:id` of `GET`, `PATCH`, `DELETE` requests. On `POST` (both: one and bulk) requests, `companyId` will be added to the `dto` automatically.
784
-
785
-
When you done with the controller, you'll need to add some logic to your `AuthGuard` or any other interface, where you do the authorization of a requester. You will need to match `companyId` URL param with the `user.companyId` entity that has been validated from the DB.
786
-
787
794
### Additional Decorators
788
795
789
796
There are two additional decorators that come out of the box: `@Feature()` and `@Action()`:
0 commit comments