1-
1+ **** strong text ****
22# json-api-nestjs
33
44## Installation
@@ -25,7 +25,7 @@ import { Users } from 'database';
2525})
2626export class AppModule {}
2727```
28- After this, you have prepare crude with ready to use end point :
28+ After this, you have to prepare CRUDs with ready-to- use endpoints :
2929
3030
3131- GET /users
@@ -53,7 +53,7 @@ export interface ModuleOptions {
5353 };
5454}
5555```
56- You can extend default controller:
56+ You can extend the default controller:
5757``` typescript
5858import { Get , Param , Inject , BadRequestException } from ' @nestjs/common' ;
5959
@@ -90,24 +90,79 @@ export class ExtendUserController extends JsonBaseController<Users> {
9090}
9191```
9292
93+ You can overwrite the default config for the current controller using options in the decorator ** JsonAPi** .
94+ Also you can specify an API method necessary for you, using ** allowMethod**
95+
9396## Swagger UI
9497
9598For using swagger, you should only add [ @nestjs/swagger ] ( https://docs.nestjs.com/openapi/introduction )
9699
100+ ## Available endpoint method
101+ Using ** Users** entity and relation ** Roles** entity as example
102+
103+ ### List item of Users
104+
105+ ```
106+ GET /users
107+ ```
108+ Available query params:
109+
110+ - ** include** - you can extend result with relations (aka join)
111+ ```
112+ GET /users?include=roles
113+ ```
114+ result of request will have role relation for each ** Users** item
115+
116+ - ** fields** - you can specify required fields of result query
117+
118+ ```
119+ GET /users?fields[target]=login,lastName&fileds[roles]=name,key
120+ ```
121+ The "target" is ** Users** entity
122+ The "roles" is ** Roles** entity
123+ So, result of request will be have only fields * login* and * lastName* for ** Users** entity and fields * name* and * key* for ** Roles** entity
124+ - ** sort** - you can sort result of the request
125+
126+ ```
127+ GET /users?sort=target.name,-roles.key
128+ ```
129+ The "target" is ** Users** entity
130+ The "roles" is ** Roles** entity
131+ So, result of the request will be sorted by field * name* of ** Users** by * ASC* and field * key* of ** Roles** entity by ** DESC** .
132+ - ** page** - pagination for you request
133+
134+ ```
135+ GET /users?page[number]=1page[size]=20
136+ ```
137+ - ** filter** - filter for query
138+
139+ ```
140+ GET /users?filter[name][eq]=1&filter[roles.name][ne]=test&filter[roles.status][eq]=true
141+ ```
142+ The "name" is a field of ** Users** entity
143+ The "roles.name" is * name* field of ** Roles** entity
144+ The "eq", "ne" is * [ Filter operand] ( #filter-operand ) *
145+
146+ So, this query will be transformed like sql:
147+ ``` sql
148+ WHERE users .name = 1 AND roles .name <> ' test' AND roles .status = true
149+ ```
97150
98151## Filter operand
99152
100153``` typescript
101- type FilterOperand = {
102- in: string [], // is equal to the conditional of query "WHERE 'attribute_name' IN ('value1', 'value2')"
103- nin: string [], // is equal to the conditional of query "WHERE 'attribute_name' NOT IN ('value1', 'value1')"
104- eq: string , // is equal to the conditional of query "WHERE 'attribute_name' = 'value1'
105- ne: string , // is equal to the conditional of query "WHERE 'attribute_name' <> 'value1'
106- gte: string , // is equal to the conditional of query "WHERE 'attribute_name' >= 'value1'
107- gt: string , // is equal to the conditional of query "WHERE 'attribute_name' > 'value1'
108- lt: string , // is equal to the conditional of query "WHERE 'attribute_name' < 'value1'
109- lte: string , // is equal to the conditional of query "WHERE 'attribute_name' <= 'value1'
110- regexp: string , // is equal to the conditional of query "WHERE 'attribute_name' ~* value1
111- some: string , // is equal to the conditional of query "WHERE 'attribute_name' && [value1]
154+ type FilterOperand {
155+ in: string[] // is equal to the conditional of query "WHERE 'attribute_name' IN ('value1', 'value2')"
156+ nin: string[] // is equal to the conditional of query "WHERE 'attribute_name' NOT IN ('value1', 'value1')"
157+ eq: string // is equal to the conditional of query "WHERE 'attribute_name' = 'value1'
158+ ne: string // is equal to the conditional of query "WHERE 'attribute_name' <> 'value1'
159+ gte: string // is equal to the conditional of query "WHERE 'attribute_name' >= 'value1'
160+ gt: string // is equal to the conditional of query "WHERE 'attribute_name' > 'value1'
161+ lt: string // is equal to the conditional of query "WHERE 'attribute_name' < 'value1'
162+ lte:string // is equal to the conditional of query "WHERE 'attribute_name' <= 'value1'
163+ regexp: string // is equal to the conditional of query "WHERE 'attribute_name' ~* value1
164+ some: string // is equal to the conditional of query "WHERE 'attribute_name' && [value1]
112165}
113166```
167+
168+
0 commit comments