Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d99dfd7

Browse files
Feature: 新增、修改接口,显示所有可用table接口;修改entity config结构
1 parent 39913c7 commit d99dfd7

File tree

14 files changed

+179
-31
lines changed

14 files changed

+179
-31
lines changed

‎README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ This example repo uses the NestJS swagger module for API documentation. [NestJS
5656

5757
# 使用文档
5858

59+
5960
> 以下例子中 默认存在两张表(Comment, User),实际使用时,需要在添加对应的entity,在service中引入即可
6061
62+
查看当前可用的table 可访问 `GET /table`
63+
64+
- 通用查询接口 `POST /apijson/get`
65+
- 通用新增接口 `POST /apijson/add`
66+
- 通用修改接口 `POST /apijson/update`
6167

6268
已经实现的操作符
6369

@@ -85,7 +91,6 @@ This example repo uses the NestJS swagger module for API documentation. [NestJS
8591
}
8692
}
8793
```
88-
![list](./asserts/list.png)
8994
- \#
9095

9196
操作符名称: 别名
@@ -113,10 +118,6 @@ This example repo uses the NestJS swagger module for API documentation. [NestJS
113118
}
114119
}
115120
```
116-
117-
![column](./asserts/column.png)
118-
119-
120121
- 联表查询
121122

122123
例子:
@@ -132,8 +133,6 @@ This example repo uses the NestJS swagger module for API documentation. [NestJS
132133
}
133134
}
134135
```
135-
![union-query](./asserts/union-query.png)
136-
137136
```json
138137
// 查询所有符合条件的comment 显示 第1页 每页2条
139138
// (因为默认page = 1 count = 10 所以默认最多为10条)
@@ -151,8 +150,6 @@ This example repo uses the NestJS swagger module for API documentation. [NestJS
151150
}
152151

153152
```
154-
![union-list-query](./asserts/union-list-query.png)
155-
156153

157154
- 综合例子
158155

@@ -174,6 +171,4 @@ This example repo uses the NestJS swagger module for API documentation. [NestJS
174171
}
175172
}
176173
}
177-
```
178-
179-
![mix](./asserts/mix.png)
174+
```

‎asserts/column.png

-41.4 KB
Binary file not shown.

‎asserts/list.png

-57.2 KB
Binary file not shown.

‎asserts/mix.png

-83.6 KB
Binary file not shown.

‎asserts/union-list-query.png

-74.7 KB
Binary file not shown.

‎asserts/union-query.png

-56.8 KB
Binary file not shown.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "nestjs-realworld-example-app",
2+
"name": "apijson-node",
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",

‎pm2.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"apps": [{
3-
"name": "api-json-node",
3+
"name": "apijson-node",
44
"script": "./dist/http/main.js",
55
"log_date_format": "YYYY-MM-DD HH:mm:ss",
66
"instances" : 4,

‎src/core/traverse.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export interface JobInterface {
77
table: string,
88
options: any,
99
ListOptions?: any,
10-
replacePath: string[]
10+
replacePath: string[],
11+
config?: any
1112
}
1213

1314
interface listUnionOptionsInterface {
@@ -74,7 +75,7 @@ export class RequestParser {
7475
return
7576
}
7677
// 校验column合法性,entity合法性,或为别名(#结尾)的情况
77-
const COLUMN_LIST = safeGet(TABLE_CONFIG, `${parentTableName}.column`, [])
78+
const COLUMN_LIST = safeGet(TABLE_CONFIG, `${parentTableName}.column`, []).map(i=>i.key)
7879
if ([
7980
...ENTITY_LIST,
8081
...COLUMN_LIST,
@@ -161,7 +162,7 @@ export class RequestParser {
161162
return
162163
} else {
163164
let queryTable = targetTables[0]
164-
const {column }= TABLE_CONFIG[queryTable] || []
165+
const column = TABLE_CONFIG[queryTable]&&TABLE_CONFIG[queryTable].column.map(i=>i.key) || []
165166
const options = {}
166167
const ListOptions = {
167168
page: 1,
@@ -180,7 +181,6 @@ export class RequestParser {
180181
} else if (column.indexOf(normalizedKey) > -1) {
181182
// 数组中的联表查询
182183
LIST_JOB_FLAG = false
183-
console.log('??', key, subKey, field, parentPath)
184184
listUnionOptions = {
185185
key: subKey,
186186
body: body[field][subKey],
@@ -223,7 +223,7 @@ export class RequestParser {
223223

224224
handleSingleJob(key: string, body: any, parentPath: string[]): void {
225225
console.log('start SINGLE_JOB', key, body, parentPath)
226-
const column = TABLE_CONFIG[key] && TABLE_CONFIG[key].column || []
226+
const column = TABLE_CONFIG[key] && TABLE_CONFIG[key].column.map(i=>i.key) || []
227227

228228
let SINGLE_JOB_FLAG = true
229229

@@ -263,6 +263,12 @@ export class RequestParser {
263263
}
264264

265265
createJob (job: JobInterface, tail: boolean = true) {
266+
job = {
267+
config: {
268+
primary: safeGet(TABLE_CONFIG, `${job.table}.primary`, '')
269+
},
270+
...job
271+
}
266272
if (tail) {
267273
this.queue.push(job)
268274
} else {

‎src/entities/comment.entity.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,16 @@ export class CommentEntity {
1313
}
1414

1515
export const Comment = {
16-
column: ['id', 'comment', 'userId']
16+
column: [{
17+
key: 'id',
18+
desc: 'ID'
19+
}, {
20+
key: 'comment',
21+
desc: '评论'
22+
}, {
23+
key: 'userId',
24+
desc: '关联的用户Id'
25+
}],
26+
primary: 'id',
27+
desc: '评论表'
1728
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /