|
1 |
| - |
| 1 | +****strong text**** |
2 | 2 | # json-api-nestjs
|
3 | 3 |
|
4 | 4 | ## Installation
|
@@ -90,23 +90,79 @@ export class ExtendUserController extends JsonBaseController<Users> {
|
90 | 90 | }
|
91 | 91 | ```
|
92 | 92 |
|
| 93 | +You can overwrite default config for current controller using options in decorator **JsonAPi**. |
| 94 | +The same you can mention api method needing for you, using **allowMethod** |
| 95 | + |
93 | 96 | ## Swagger UI
|
94 | 97 |
|
95 | 98 | For using swagger, you should only add [@nestjs/swagger](https://docs.nestjs.com/openapi/introduction)
|
96 | 99 |
|
| 100 | +## Available end point method |
| 101 | +Using **Users** entity and relation **Roles** entity as example |
| 102 | + |
| 103 | +include |
| 104 | + |
| 105 | + |
| 106 | +### List item of Users |
| 107 | + GET /users |
| 108 | +Available query params: |
| 109 | + |
| 110 | +- **include** - you can extend result with relation(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 needing filed 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 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 request will be sort filed *name* of **Users** by *ASC* and filed *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 filed of **Users** entity |
| 143 | + The "roles.name" is *name* filed of **Roles** entity |
| 144 | + The "eq", "ne" is *[Filter operand](#filter-operand)* |
| 145 | + |
| 146 | + So, this query will be transform like sql: |
| 147 | + ```sql |
| 148 | + WHERE users.name = 1 AND roles.name <> 'test' AND roles.status = true |
| 149 | + ``` |
| 150 | + |
97 | 151 | ## Filter operand
|
98 | 152 |
|
99 | 153 | ```typescript
|
100 |
| -type FilterOperand = { |
101 |
| - in: string[], // is equal to the conditional of query "WHERE 'attribute_name' IN ('value1', 'value2')" |
102 |
| - nin: string[], // is equal to the conditional of query "WHERE 'attribute_name' NOT IN ('value1', 'value1')" |
103 |
| - eq: string, // is equal to the conditional of query "WHERE 'attribute_name' = 'value1' |
104 |
| - ne: string, // is equal to the conditional of query "WHERE 'attribute_name' <> 'value1' |
105 |
| - gte: string, // is equal to the conditional of query "WHERE 'attribute_name' >= 'value1' |
106 |
| - gt: string, // is equal to the conditional of query "WHERE 'attribute_name' > 'value1' |
107 |
| - lt: string, // is equal to the conditional of query "WHERE 'attribute_name' < 'value1' |
108 |
| - lte:string, // is equal to the conditional of query "WHERE 'attribute_name' <= 'value1' |
109 |
| - regexp: string, // is equal to the conditional of query "WHERE 'attribute_name' ~* value1 |
110 |
| - 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] |
111 | 165 | }
|
112 | 166 | ```
|
| 167 | + |
| 168 | + |
0 commit comments