@steedos/service-rest 2.7.0-beta.13 → 2.7.0-beta.16
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/package.json +4 -4
- package/package.service.js +110 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-rest",
|
|
3
|
-
"version": "2.7.0-beta.
|
|
3
|
+
"version": "2.7.0-beta.16",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"repository": {},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@steedos/objectql": "2.7.0-beta.
|
|
20
|
-
"@steedos/service-object-mixin": "2.7.0-beta.
|
|
19
|
+
"@steedos/objectql": "2.7.0-beta.16",
|
|
20
|
+
"@steedos/service-object-mixin": "2.7.0-beta.16",
|
|
21
21
|
"lodash": "^4.17.21"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "6000bab910fb5fa326cca58c4f396ed6f9779aa4"
|
|
24
24
|
}
|
package/package.service.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: sunhaolin@hotoa.com
|
|
3
3
|
* @Date: 2023-03-23 15:12:14
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
-
* @LastEditTime: 2024-03-
|
|
5
|
+
* @LastEditTime: 2024-03-30 16:32:08
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
"use strict";
|
|
@@ -47,6 +47,114 @@ module.exports = {
|
|
|
47
47
|
return 'ok'
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
+
/**
|
|
51
|
+
* @api {POST} /api/v1/batch 批处理接口
|
|
52
|
+
* @apiVersion 0.0.0
|
|
53
|
+
* @apiGroup @steedos/service-rest
|
|
54
|
+
* @apiBody {Object[]} find 查询条件, 例如:[{objectName: 'contracts', filters: [['name', '=', 'test']], fields: ['name', 'description'], top: 10, skip: 0, sort: 'name desc'}]
|
|
55
|
+
* @apiBody {Object[]} count 查询条件, 例如:[{objectName: 'contracts', filters: [['name', '=', 'test']]}]
|
|
56
|
+
* @apiBody {Object[]} findOne 查询条件, 例如:[{objectName: 'contracts', id: "xxx", fields: ['name', 'description']}]
|
|
57
|
+
* @apiBody {Object[]} insert 插入数据, 例如: [{objectName: 'contracts', doc: {name: 'test', description: 'test'}}]
|
|
58
|
+
* @apiBody {Object[]} update 更新数据, 例如: [{objectName: 'contracts', id: "xxx", doc: {name: 'test', description: 'test'}}]
|
|
59
|
+
* @apiBody {Object[]} delete 删除数据, 例如: [{objectName: 'contracts', id: "xxx"}]
|
|
60
|
+
* @apiName batch
|
|
61
|
+
*/
|
|
62
|
+
batch: {
|
|
63
|
+
rest: {
|
|
64
|
+
method: "POST",
|
|
65
|
+
path: "/batch"
|
|
66
|
+
},
|
|
67
|
+
async handler(ctx){
|
|
68
|
+
|
|
69
|
+
const { find, count, findOne, insert, update, delete: deleteAs } = ctx.params;
|
|
70
|
+
|
|
71
|
+
const res = {}
|
|
72
|
+
|
|
73
|
+
const findRes = [];
|
|
74
|
+
if(find){
|
|
75
|
+
for (const item of find) {
|
|
76
|
+
const args = {...item};
|
|
77
|
+
if(_.has(item, 'fields') && !_.isString(item.fields) ){
|
|
78
|
+
args.fields = JSON.stringify(item.fields)
|
|
79
|
+
}
|
|
80
|
+
if(_.has(item, 'uiFields') && !_.isString(item.uiFields) ){
|
|
81
|
+
args.uiFields = JSON.stringify(item.uiFields)
|
|
82
|
+
}
|
|
83
|
+
if(_.has(item, 'expandFields') && !_.isString(item.expandFields) ){
|
|
84
|
+
args.expandFields = JSON.stringify(item.expandFields)
|
|
85
|
+
}
|
|
86
|
+
if(_.has(item, 'filters') && !_.isString(item.filters) ){
|
|
87
|
+
args.filters = JSON.stringify(item.filters)
|
|
88
|
+
}
|
|
89
|
+
findRes.push(ctx.broker.call(`rest.find`, args).catch(err => {
|
|
90
|
+
return err;
|
|
91
|
+
}))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
res.find = await Promise.all(findRes);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const countRes = [];
|
|
98
|
+
if(count){
|
|
99
|
+
for (const item of count) {
|
|
100
|
+
const args = {...item};
|
|
101
|
+
if(_.has(item, 'filters') && !_.isString(item.filters) ){
|
|
102
|
+
args.filters = JSON.stringify(item.filters)
|
|
103
|
+
}
|
|
104
|
+
countRes.push(ctx.broker.call(`rest.count`, args).catch(err => {
|
|
105
|
+
return err;
|
|
106
|
+
}))
|
|
107
|
+
}
|
|
108
|
+
res.count = await Promise.all(countRes);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const findOneRes = []
|
|
112
|
+
if(findOne){
|
|
113
|
+
for (const item of findOne) {
|
|
114
|
+
const args = {...item};
|
|
115
|
+
if(_.has(item, 'fields') && !_.isString(item.fields) ){
|
|
116
|
+
args.fields = JSON.stringify(item.fields)
|
|
117
|
+
}
|
|
118
|
+
findOneRes.push(ctx.broker.call(`rest.findOne`, args).catch(err => {
|
|
119
|
+
return err;
|
|
120
|
+
}))
|
|
121
|
+
}
|
|
122
|
+
res.findOne = await Promise.all(findOneRes);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const insertRes = []
|
|
126
|
+
if(insert){
|
|
127
|
+
for (const item of insert) {
|
|
128
|
+
insertRes.push(ctx.broker.call(`rest.insert`, item).catch(err => {
|
|
129
|
+
return err;
|
|
130
|
+
}))
|
|
131
|
+
}
|
|
132
|
+
res.insert = await Promise.all(insertRes);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const updateRes = []
|
|
136
|
+
if(update){
|
|
137
|
+
for (const item of update) {
|
|
138
|
+
updateRes.push(ctx.broker.call(`rest.update`, item).catch(err => {
|
|
139
|
+
return err;
|
|
140
|
+
}))
|
|
141
|
+
}
|
|
142
|
+
res.update = await Promise.all(updateRes);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const deleteRes = []
|
|
146
|
+
if(deleteAs){
|
|
147
|
+
for (const item of deleteAs) {
|
|
148
|
+
deleteRes.push(ctx.broker.call(`rest.delete`, item).catch(err => {
|
|
149
|
+
return err;
|
|
150
|
+
}))
|
|
151
|
+
}
|
|
152
|
+
res.delete = await Promise.all(deleteRes);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return res;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
50
158
|
/**
|
|
51
159
|
* @api {GET} /api/v1/:objectName 获取列表记录
|
|
52
160
|
* @apiVersion 0.0.0
|
|
@@ -602,8 +710,7 @@ module.exports = {
|
|
|
602
710
|
}
|
|
603
711
|
}
|
|
604
712
|
}
|
|
605
|
-
}
|
|
606
|
-
|
|
713
|
+
}
|
|
607
714
|
},
|
|
608
715
|
|
|
609
716
|
/**
|