@steedos/service-ui 3.0.0-beta.13 → 3.0.0-beta.131
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/main/default/client/liveblocks.client.js +3 -0
- package/main/default/routes/excel_export.router.d.ts +1 -0
- package/main/default/routes/excel_export.router.js +306 -0
- package/main/default/routes/objects.router.js +22 -11
- package/package.json +5 -6
- package/public/static/liveblocks.css +7 -0
- package/src/routes/excel_export.router.ts +350 -0
- package/src/routes/objects.router.ts +134 -67
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const querystring = require("querystring");
|
|
5
|
+
const odataV4Mongodb = require("@steedos/odata-v4-mongodb");
|
|
6
|
+
const filters_1 = require("@steedos/filters");
|
|
7
|
+
const auth_1 = require("@steedos/auth");
|
|
8
|
+
const moment = require("moment");
|
|
9
|
+
const json2xls = require("json2xls");
|
|
10
|
+
const objectql = require("@steedos/objectql");
|
|
11
|
+
const _ = require("lodash");
|
|
12
|
+
const objectql_1 = require("@steedos/objectql");
|
|
13
|
+
const express = require("express");
|
|
14
|
+
const router = express.Router();
|
|
15
|
+
const MAX_EXPORT = 5000;
|
|
16
|
+
const exportRecordData = function (req, res) {
|
|
17
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
try {
|
|
19
|
+
const userSession = req.user;
|
|
20
|
+
let userId = userSession.userId;
|
|
21
|
+
let urlParams = req.params;
|
|
22
|
+
let queryParams = req.query;
|
|
23
|
+
let filename = queryParams.filename;
|
|
24
|
+
delete queryParams.filename;
|
|
25
|
+
if (!filename) {
|
|
26
|
+
filename = "导出";
|
|
27
|
+
}
|
|
28
|
+
if (queryParams.filters) {
|
|
29
|
+
queryParams.$filter = (0, filters_1.formatFiltersToODataQuery)(JSON.parse(queryParams.filters), userSession);
|
|
30
|
+
}
|
|
31
|
+
const objectName = urlParams.objectName;
|
|
32
|
+
const collection = yield objectql.getObject(objectName);
|
|
33
|
+
if (!collection) {
|
|
34
|
+
res.status(404).send({ msg: `collection not exists: ${objectName}` });
|
|
35
|
+
}
|
|
36
|
+
removeInvalidMethod(queryParams);
|
|
37
|
+
let qs = decodeURIComponent(querystring.stringify(queryParams));
|
|
38
|
+
if (qs) {
|
|
39
|
+
var createQuery = odataV4Mongodb.createQuery(qs);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
var createQuery = {
|
|
43
|
+
query: {},
|
|
44
|
+
sort: undefined,
|
|
45
|
+
projection: {},
|
|
46
|
+
includes: [],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
let permissions = yield collection.getUserObjectPermission(userSession);
|
|
50
|
+
if (permissions.allowExport != true) {
|
|
51
|
+
return res
|
|
52
|
+
.status(403)
|
|
53
|
+
.send({ status: 403, error: 403, msg: `access failed` });
|
|
54
|
+
}
|
|
55
|
+
if (permissions.viewAllRecords ||
|
|
56
|
+
permissions.viewCompanyRecords ||
|
|
57
|
+
(permissions.allowRead && userId)) {
|
|
58
|
+
let entities = [];
|
|
59
|
+
let filters = queryParams.$filter || "";
|
|
60
|
+
let fields = [];
|
|
61
|
+
if (queryParams.$select) {
|
|
62
|
+
fields = _.keys(createQuery.projection);
|
|
63
|
+
}
|
|
64
|
+
if (isPlatformDriver(collection.datasource.driver)) {
|
|
65
|
+
filters = excludeDeleted(filters);
|
|
66
|
+
}
|
|
67
|
+
if (queryParams.$top !== "0") {
|
|
68
|
+
let query = {
|
|
69
|
+
filters: filters,
|
|
70
|
+
fields: fields,
|
|
71
|
+
top: Number(queryParams.$top),
|
|
72
|
+
};
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(queryParams, "$skip")) {
|
|
74
|
+
query["skip"] = Number(queryParams.$skip);
|
|
75
|
+
}
|
|
76
|
+
if (queryParams.$orderby) {
|
|
77
|
+
query["sort"] = queryParams.$orderby;
|
|
78
|
+
}
|
|
79
|
+
entities = yield collection.find(query, userSession);
|
|
80
|
+
}
|
|
81
|
+
if (entities.length > MAX_EXPORT) {
|
|
82
|
+
return res.status(403).send({
|
|
83
|
+
status: 403,
|
|
84
|
+
error: 403,
|
|
85
|
+
msg: `超出允许的导出记录数(${MAX_EXPORT}条), 请调整搜索条件后重试.`,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (entities) {
|
|
89
|
+
const fieldConfigs = (yield objectql
|
|
90
|
+
.getSteedosSchema()
|
|
91
|
+
.broker.call(`objectql.getRecordView`, { objectName }, { meta: { user: userSession } })).fields;
|
|
92
|
+
for (let i = 0; i < entities.length; i++) {
|
|
93
|
+
let record = entities[i];
|
|
94
|
+
delete record._id;
|
|
95
|
+
let parsedRecord = {};
|
|
96
|
+
let keys;
|
|
97
|
+
if (fields && fields.length > 0) {
|
|
98
|
+
keys = fields;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
keys = _.keys(record);
|
|
102
|
+
}
|
|
103
|
+
for (let fieldName of keys) {
|
|
104
|
+
let fieldConfig = fieldConfigs[fieldName];
|
|
105
|
+
let fieldValue = record[fieldName];
|
|
106
|
+
if (!fieldConfig) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (fieldValue || fieldValue == false) {
|
|
110
|
+
parsedRecord = Object.assign(parsedRecord, {
|
|
111
|
+
[fieldConfig.label]: yield key2value(fieldValue, fieldConfig, userSession),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
parsedRecord = Object.assign(parsedRecord, {
|
|
116
|
+
[fieldConfig.label]: null,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
entities[i] = parsedRecord;
|
|
121
|
+
}
|
|
122
|
+
if (_.isEmpty(entities)) {
|
|
123
|
+
entities.push({ "": "" });
|
|
124
|
+
}
|
|
125
|
+
var xls = json2xls(entities);
|
|
126
|
+
res.writeHead(200, {
|
|
127
|
+
"Content-Type": "application/octet-stream",
|
|
128
|
+
"Content-Disposition": "attachment;filename=" + encodeURI(filename + ".xlsx"),
|
|
129
|
+
"Content-Length": xls.length,
|
|
130
|
+
"Access-Control-Expose-Headers": "Content-Disposition",
|
|
131
|
+
});
|
|
132
|
+
res.end(xls, "binary");
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
res
|
|
136
|
+
.status(404)
|
|
137
|
+
.send({ code: 404, error: 404, message: "no record found" });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
res.status(403).send({ code: 403, error: 403, message: `access failed` });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
let _handleError = handleError(error);
|
|
146
|
+
res.status(_handleError.statusCode).send(_handleError.body);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
const handleError = function (e) {
|
|
151
|
+
console.log(e);
|
|
152
|
+
let body = {};
|
|
153
|
+
let error = {};
|
|
154
|
+
error["message"] = e.message;
|
|
155
|
+
let statusCode = 500;
|
|
156
|
+
if (e.error && _.isNumber(e.error)) {
|
|
157
|
+
statusCode = e.error;
|
|
158
|
+
}
|
|
159
|
+
error["code"] = statusCode;
|
|
160
|
+
error["error"] = statusCode;
|
|
161
|
+
error["details"] = e.details;
|
|
162
|
+
error["reason"] = e.reason;
|
|
163
|
+
body["error"] = error;
|
|
164
|
+
return {
|
|
165
|
+
statusCode: statusCode,
|
|
166
|
+
body: body,
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
const removeInvalidMethod = function (queryParams) {
|
|
170
|
+
if (queryParams.$filter && queryParams.$filter.indexOf("tolower(") > -1) {
|
|
171
|
+
let removeMethod = function ($1) {
|
|
172
|
+
return $1.replace("tolower(", "").replace(")", "");
|
|
173
|
+
};
|
|
174
|
+
queryParams.$filter = queryParams.$filter.replace(/tolower\(([^\)]+)\)/g, removeMethod);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
function isPlatformDriver(driverName) {
|
|
178
|
+
if (driverName == objectql_1.SteedosDatabaseDriverType.Mongo ||
|
|
179
|
+
driverName == objectql_1.SteedosDatabaseDriverType.MeteorMongo) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const excludeDeleted = function (filters) {
|
|
185
|
+
if (filters && filters.indexOf("(is_deleted eq true)") > -1) {
|
|
186
|
+
return filters;
|
|
187
|
+
}
|
|
188
|
+
return filters
|
|
189
|
+
? `(${filters}) and (is_deleted ne true)`
|
|
190
|
+
: `(is_deleted ne true)`;
|
|
191
|
+
};
|
|
192
|
+
const getOptionLabel = function (optionValue, options) {
|
|
193
|
+
let option = _.find(options, function (o) {
|
|
194
|
+
return o.value == optionValue;
|
|
195
|
+
});
|
|
196
|
+
if (option && option.label) {
|
|
197
|
+
return option.label;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return optionValue;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const key2value = function (fieldValue, fieldConfig, userSession) {
|
|
204
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
var _a;
|
|
206
|
+
switch (fieldConfig.type) {
|
|
207
|
+
case "boolean":
|
|
208
|
+
if (fieldValue) {
|
|
209
|
+
return t("form_field_checkbox_yes", {}, userSession.language);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
return t("form_field_checkbox_no", {}, userSession.language);
|
|
213
|
+
}
|
|
214
|
+
case "select":
|
|
215
|
+
let options = fieldConfig.options;
|
|
216
|
+
if (fieldConfig.multiple && _.isArray(fieldValue)) {
|
|
217
|
+
for (let i = 0; i < fieldValue.length; i++) {
|
|
218
|
+
let newValue = getOptionLabel(fieldValue[i], options);
|
|
219
|
+
fieldValue[i] = newValue;
|
|
220
|
+
}
|
|
221
|
+
return fieldValue;
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
return getOptionLabel(fieldValue, options);
|
|
225
|
+
}
|
|
226
|
+
case "master_detail":
|
|
227
|
+
case "lookup":
|
|
228
|
+
let reference_to = fieldConfig.reference_to;
|
|
229
|
+
let ref_coll;
|
|
230
|
+
let id = fieldValue;
|
|
231
|
+
if (_.isFunction(reference_to) ||
|
|
232
|
+
(fieldConfig._reference_to &&
|
|
233
|
+
fieldConfig._reference_to.startsWith("function"))) {
|
|
234
|
+
reference_to = fieldValue.o;
|
|
235
|
+
id = fieldConfig.multiple ? fieldValue.ids : fieldValue.ids[0];
|
|
236
|
+
}
|
|
237
|
+
ref_coll = yield objectql.getObject(reference_to);
|
|
238
|
+
const nameFieldKey = yield ref_coll.getNameFieldKey();
|
|
239
|
+
let reference_to_field = fieldConfig.reference_to_field;
|
|
240
|
+
let filters = [];
|
|
241
|
+
if (reference_to_field) {
|
|
242
|
+
filters[0] = reference_to_field;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
filters[0] = "_id";
|
|
246
|
+
}
|
|
247
|
+
if (!fieldConfig.multiple) {
|
|
248
|
+
filters[1] = "=";
|
|
249
|
+
filters[2] = id;
|
|
250
|
+
let ref_record = yield ref_coll.find({
|
|
251
|
+
filters: filters,
|
|
252
|
+
fields: [filters[0], nameFieldKey],
|
|
253
|
+
});
|
|
254
|
+
if (ref_record && ref_record.length == 1) {
|
|
255
|
+
return ref_record[0][nameFieldKey];
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
return id;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
filters[1] = "in";
|
|
263
|
+
filters[2] = id;
|
|
264
|
+
if (!_.isArray(id)) {
|
|
265
|
+
return id;
|
|
266
|
+
}
|
|
267
|
+
let ref_record = yield ref_coll.find({
|
|
268
|
+
filters: filters,
|
|
269
|
+
fields: [filters[0], nameFieldKey],
|
|
270
|
+
});
|
|
271
|
+
for (let i = 0; i < id.length; i++) {
|
|
272
|
+
let _record = _.find(ref_record, function (r) {
|
|
273
|
+
return r[filters[0]] == id[i];
|
|
274
|
+
});
|
|
275
|
+
if (_record) {
|
|
276
|
+
id[i] = _record[nameFieldKey];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return id;
|
|
280
|
+
}
|
|
281
|
+
case "date":
|
|
282
|
+
return moment(fieldValue).format("YYYY-MM-DD");
|
|
283
|
+
case "datetime":
|
|
284
|
+
return moment(fieldValue)
|
|
285
|
+
.utcOffset((_a = userSession.utcOffset) !== null && _a !== void 0 ? _a : 8)
|
|
286
|
+
.format("YYYY-MM-DD H:mm");
|
|
287
|
+
case "time":
|
|
288
|
+
return moment(fieldValue).utcOffset(0).format("HH:mm");
|
|
289
|
+
case "summary":
|
|
290
|
+
let summaryObj = yield objectql.getObject(fieldConfig.summary_object);
|
|
291
|
+
let summaryField = summaryObj.fields[fieldConfig.summary_field];
|
|
292
|
+
if (summaryField) {
|
|
293
|
+
return yield key2value(fieldValue, summaryField, userSession);
|
|
294
|
+
}
|
|
295
|
+
return fieldValue;
|
|
296
|
+
default:
|
|
297
|
+
return fieldValue;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
router.get("/api/record/export/:objectName", auth_1.requireAuthentication, function (req, res) {
|
|
302
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
return yield exportRecordData(req, res);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
exports.default = router;
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const objectql_1 = require("@steedos/objectql");
|
|
5
|
-
const express = require(
|
|
5
|
+
const express = require("express");
|
|
6
6
|
const router = express.Router();
|
|
7
|
-
const auth = require(
|
|
7
|
+
const auth = require("@steedos/auth");
|
|
8
|
+
const _ = require("lodash");
|
|
8
9
|
const callObjectServiceAction = function (actionName, userSession, data) {
|
|
9
10
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
10
11
|
const broker = (0, objectql_1.getSteedosSchema)().broker;
|
|
@@ -14,12 +15,20 @@ const callObjectServiceAction = function (actionName, userSession, data) {
|
|
|
14
15
|
const getObjectName = function (objectServiceName) {
|
|
15
16
|
return objectServiceName.substring(1);
|
|
16
17
|
};
|
|
17
|
-
router.get(
|
|
18
|
+
router.get("/service/api/:objectServiceName/fields", auth.requireAuthentication, function (req, res) {
|
|
18
19
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
20
|
const userSession = req.user;
|
|
20
21
|
try {
|
|
21
22
|
const { objectServiceName } = req.params;
|
|
23
|
+
const { fields } = req.query;
|
|
22
24
|
const result = yield callObjectServiceAction(`objectql.getFields`, userSession, { objectName: getObjectName(objectServiceName) });
|
|
25
|
+
if (fields) {
|
|
26
|
+
const result2 = {};
|
|
27
|
+
_.each(result, function (item, k) {
|
|
28
|
+
return (result2[k] = _.pick(item, _.split(fields, ",")));
|
|
29
|
+
});
|
|
30
|
+
return res.status(200).send(result2);
|
|
31
|
+
}
|
|
23
32
|
res.status(200).send(result);
|
|
24
33
|
}
|
|
25
34
|
catch (error) {
|
|
@@ -27,7 +36,7 @@ router.get('/service/api/:objectServiceName/fields', auth.requireAuthentication,
|
|
|
27
36
|
}
|
|
28
37
|
});
|
|
29
38
|
});
|
|
30
|
-
router.get(
|
|
39
|
+
router.get("/service/api/:objectServiceName/getUserObjectPermission", auth.requireAuthentication, function (req, res) {
|
|
31
40
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
41
|
const userSession = req.user;
|
|
33
42
|
try {
|
|
@@ -40,14 +49,14 @@ router.get('/service/api/:objectServiceName/getUserObjectPermission', auth.requi
|
|
|
40
49
|
}
|
|
41
50
|
});
|
|
42
51
|
});
|
|
43
|
-
router.get(
|
|
52
|
+
router.get("/service/api/:objectServiceName/recordPermissions/:recordId", auth.requireAuthentication, function (req, res) {
|
|
44
53
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
54
|
const userSession = req.user;
|
|
46
55
|
try {
|
|
47
56
|
const { objectServiceName, recordId } = req.params;
|
|
48
57
|
const result = yield callObjectServiceAction(`objectql.getRecordPermissionsById`, userSession, {
|
|
49
58
|
objectName: getObjectName(objectServiceName),
|
|
50
|
-
recordId: recordId
|
|
59
|
+
recordId: recordId,
|
|
51
60
|
});
|
|
52
61
|
res.status(200).send(result);
|
|
53
62
|
}
|
|
@@ -56,14 +65,16 @@ router.get('/service/api/:objectServiceName/recordPermissions/:recordId', auth.r
|
|
|
56
65
|
}
|
|
57
66
|
});
|
|
58
67
|
});
|
|
59
|
-
router.get(
|
|
68
|
+
router.get("/service/api/:objectServiceName/uiSchema", auth.requireAuthentication, function (req, res) {
|
|
60
69
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
61
70
|
const userSession = req.user;
|
|
62
71
|
try {
|
|
63
72
|
const { objectServiceName } = req.params;
|
|
64
73
|
const objectName = objectServiceName.substring(1);
|
|
65
74
|
const [result] = yield Promise.all([
|
|
66
|
-
callObjectServiceAction(`objectql.getRecordView`, userSession, {
|
|
75
|
+
callObjectServiceAction(`objectql.getRecordView`, userSession, {
|
|
76
|
+
objectName,
|
|
77
|
+
}),
|
|
67
78
|
]);
|
|
68
79
|
res.status(200).send(result);
|
|
69
80
|
}
|
|
@@ -72,7 +83,7 @@ router.get('/service/api/:objectServiceName/uiSchema', auth.requireAuthenticatio
|
|
|
72
83
|
}
|
|
73
84
|
});
|
|
74
85
|
});
|
|
75
|
-
router.post(
|
|
86
|
+
router.post("/service/api/:objectServiceName/defUiSchema", auth.requireAuthentication, function (req, res) {
|
|
76
87
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
77
88
|
const userSession = req.user;
|
|
78
89
|
try {
|
|
@@ -85,7 +96,7 @@ router.post('/service/api/:objectServiceName/defUiSchema', auth.requireAuthentic
|
|
|
85
96
|
}
|
|
86
97
|
});
|
|
87
98
|
});
|
|
88
|
-
router.get(
|
|
99
|
+
router.get("/service/api/:objectServiceName/uiSchemaTemplate", auth.requireAuthentication, function (req, res) {
|
|
89
100
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
90
101
|
const userSession = req.user;
|
|
91
102
|
try {
|
|
@@ -98,7 +109,7 @@ router.get('/service/api/:objectServiceName/uiSchemaTemplate', auth.requireAuthe
|
|
|
98
109
|
}
|
|
99
110
|
});
|
|
100
111
|
});
|
|
101
|
-
router.get(
|
|
112
|
+
router.get("/service/api/:objectServiceName/relateds", auth.requireAuthentication, function (req, res) {
|
|
102
113
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
103
114
|
const userSession = req.user;
|
|
104
115
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-ui",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.131",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"steedos"
|
|
@@ -11,15 +11,14 @@
|
|
|
11
11
|
"description": "steedos package",
|
|
12
12
|
"repository": {},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@steedos/auth": "3.0.0-beta.
|
|
15
|
-
"@steedos/i18n": "3.0.0-beta.
|
|
16
|
-
"@steedos/objectql": "3.0.0-beta.
|
|
14
|
+
"@steedos/auth": "3.0.0-beta.131",
|
|
15
|
+
"@steedos/i18n": "3.0.0-beta.131",
|
|
16
|
+
"@steedos/objectql": "3.0.0-beta.131",
|
|
17
17
|
"express": "4.18.1"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
|
-
"private": false,
|
|
21
20
|
"publishConfig": {
|
|
22
21
|
"access": "public"
|
|
23
22
|
},
|
|
24
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "be17fae35ef8081798c61d30e4633e0f0f433cef"
|
|
25
24
|
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import querystring = require("querystring");
|
|
2
|
+
import odataV4Mongodb = require("@steedos/odata-v4-mongodb");
|
|
3
|
+
import { formatFiltersToODataQuery } from "@steedos/filters";
|
|
4
|
+
import { requireAuthentication } from "@steedos/auth";
|
|
5
|
+
// const Fiber = require('fibers');
|
|
6
|
+
const moment = require("moment");
|
|
7
|
+
const json2xls = require("json2xls");
|
|
8
|
+
const objectql = require("@steedos/objectql");
|
|
9
|
+
const _ = require("lodash");
|
|
10
|
+
// export const exportExcelExpress = require('@steedos/router').staticRouter();;
|
|
11
|
+
import { SteedosDatabaseDriverType } from "@steedos/objectql";
|
|
12
|
+
const express = require("express");
|
|
13
|
+
const router = express.Router();
|
|
14
|
+
|
|
15
|
+
const MAX_EXPORT = 5000;
|
|
16
|
+
|
|
17
|
+
const exportRecordData = async function (req: any, res: any) {
|
|
18
|
+
try {
|
|
19
|
+
const userSession = req.user;
|
|
20
|
+
let userId = userSession.userId;
|
|
21
|
+
let urlParams = req.params;
|
|
22
|
+
let queryParams = req.query;
|
|
23
|
+
let filename = queryParams.filename;
|
|
24
|
+
delete queryParams.filename;
|
|
25
|
+
if (!filename) {
|
|
26
|
+
filename = "导出";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (queryParams.filters) {
|
|
30
|
+
queryParams.$filter = formatFiltersToODataQuery(
|
|
31
|
+
JSON.parse(queryParams.filters),
|
|
32
|
+
userSession,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const objectName = urlParams.objectName;
|
|
37
|
+
|
|
38
|
+
const collection = await objectql.getObject(objectName);
|
|
39
|
+
if (!collection) {
|
|
40
|
+
res.status(404).send({ msg: `collection not exists: ${objectName}` });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
removeInvalidMethod(queryParams);
|
|
44
|
+
let qs = decodeURIComponent(
|
|
45
|
+
querystring.stringify(queryParams as querystring.ParsedUrlQueryInput),
|
|
46
|
+
);
|
|
47
|
+
if (qs) {
|
|
48
|
+
var createQuery = odataV4Mongodb.createQuery(qs);
|
|
49
|
+
} else {
|
|
50
|
+
var createQuery: any = {
|
|
51
|
+
query: {},
|
|
52
|
+
sort: undefined,
|
|
53
|
+
projection: {},
|
|
54
|
+
includes: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
let permissions = await collection.getUserObjectPermission(userSession);
|
|
58
|
+
if (permissions.allowExport != true) {
|
|
59
|
+
return res
|
|
60
|
+
.status(403)
|
|
61
|
+
.send({ status: 403, error: 403, msg: `access failed` });
|
|
62
|
+
}
|
|
63
|
+
if (
|
|
64
|
+
permissions.viewAllRecords ||
|
|
65
|
+
permissions.viewCompanyRecords ||
|
|
66
|
+
(permissions.allowRead && userId)
|
|
67
|
+
) {
|
|
68
|
+
let entities: any[] = [];
|
|
69
|
+
let filters = (queryParams.$filter as string) || "";
|
|
70
|
+
let fields = [];
|
|
71
|
+
|
|
72
|
+
if (queryParams.$select) {
|
|
73
|
+
fields = _.keys(createQuery.projection);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isPlatformDriver(collection.datasource.driver)) {
|
|
77
|
+
filters = excludeDeleted(filters);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (queryParams.$top !== "0") {
|
|
81
|
+
let query = {
|
|
82
|
+
filters: filters,
|
|
83
|
+
fields: fields,
|
|
84
|
+
top: Number(queryParams.$top),
|
|
85
|
+
};
|
|
86
|
+
if (Object.prototype.hasOwnProperty.call(queryParams, "$skip")) {
|
|
87
|
+
query["skip"] = Number(queryParams.$skip);
|
|
88
|
+
}
|
|
89
|
+
if (queryParams.$orderby) {
|
|
90
|
+
query["sort"] = queryParams.$orderby;
|
|
91
|
+
}
|
|
92
|
+
entities = await collection.find(query, userSession);
|
|
93
|
+
}
|
|
94
|
+
if (entities.length > MAX_EXPORT) {
|
|
95
|
+
return res.status(403).send({
|
|
96
|
+
status: 403,
|
|
97
|
+
error: 403,
|
|
98
|
+
msg: `超出允许的导出记录数(${MAX_EXPORT}条), 请调整搜索条件后重试.`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (entities) {
|
|
102
|
+
const fieldConfigs = (
|
|
103
|
+
await objectql
|
|
104
|
+
.getSteedosSchema()
|
|
105
|
+
.broker.call(
|
|
106
|
+
`objectql.getRecordView`,
|
|
107
|
+
{ objectName },
|
|
108
|
+
{ meta: { user: userSession } },
|
|
109
|
+
)
|
|
110
|
+
).fields;
|
|
111
|
+
|
|
112
|
+
for (let i = 0; i < entities.length; i++) {
|
|
113
|
+
let record = entities[i];
|
|
114
|
+
delete record._id;
|
|
115
|
+
let parsedRecord = {};
|
|
116
|
+
|
|
117
|
+
let keys;
|
|
118
|
+
if (fields && fields.length > 0) {
|
|
119
|
+
keys = fields;
|
|
120
|
+
} else {
|
|
121
|
+
keys = _.keys(record);
|
|
122
|
+
}
|
|
123
|
+
for (let fieldName of keys) {
|
|
124
|
+
let fieldConfig = fieldConfigs[fieldName];
|
|
125
|
+
let fieldValue = record[fieldName];
|
|
126
|
+
|
|
127
|
+
if (!fieldConfig) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (fieldValue || fieldValue == false) {
|
|
131
|
+
// record[fieldName] = await key2value(fieldValue, fieldConfig);
|
|
132
|
+
parsedRecord = Object.assign(parsedRecord, {
|
|
133
|
+
[fieldConfig.label]: await key2value(
|
|
134
|
+
fieldValue,
|
|
135
|
+
fieldConfig,
|
|
136
|
+
userSession,
|
|
137
|
+
),
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
parsedRecord = Object.assign(parsedRecord, {
|
|
141
|
+
[fieldConfig.label]: null,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
entities[i] = parsedRecord;
|
|
147
|
+
}
|
|
148
|
+
if (_.isEmpty(entities)) {
|
|
149
|
+
//生成空表格
|
|
150
|
+
entities.push({ "": "" });
|
|
151
|
+
}
|
|
152
|
+
var xls = json2xls(entities);
|
|
153
|
+
// fs.writeFileSync("test.xlsx", xls, 'binary');
|
|
154
|
+
res.writeHead(200, {
|
|
155
|
+
"Content-Type": "application/octet-stream",
|
|
156
|
+
"Content-Disposition":
|
|
157
|
+
"attachment;filename=" + encodeURI(filename + ".xlsx"),
|
|
158
|
+
"Content-Length": xls.length,
|
|
159
|
+
"Access-Control-Expose-Headers": "Content-Disposition",
|
|
160
|
+
});
|
|
161
|
+
res.end(xls, "binary");
|
|
162
|
+
} else {
|
|
163
|
+
res
|
|
164
|
+
.status(404)
|
|
165
|
+
.send({ code: 404, error: 404, message: "no record found" });
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
res.status(403).send({ code: 403, error: 403, message: `access failed` });
|
|
169
|
+
}
|
|
170
|
+
} catch (error) {
|
|
171
|
+
let _handleError = handleError(error);
|
|
172
|
+
res.status(_handleError.statusCode).send(_handleError.body);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const handleError = function (e: any) {
|
|
177
|
+
console.log(e);
|
|
178
|
+
let body = {};
|
|
179
|
+
let error = {};
|
|
180
|
+
error["message"] = e.message;
|
|
181
|
+
let statusCode = 500;
|
|
182
|
+
if (e.error && _.isNumber(e.error)) {
|
|
183
|
+
statusCode = e.error;
|
|
184
|
+
}
|
|
185
|
+
error["code"] = statusCode;
|
|
186
|
+
error["error"] = statusCode;
|
|
187
|
+
error["details"] = e.details;
|
|
188
|
+
error["reason"] = e.reason;
|
|
189
|
+
body["error"] = error;
|
|
190
|
+
return {
|
|
191
|
+
statusCode: statusCode,
|
|
192
|
+
body: body,
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const removeInvalidMethod = function (queryParams: any) {
|
|
197
|
+
if (queryParams.$filter && queryParams.$filter.indexOf("tolower(") > -1) {
|
|
198
|
+
let removeMethod = function ($1: string) {
|
|
199
|
+
return $1.replace("tolower(", "").replace(")", "");
|
|
200
|
+
};
|
|
201
|
+
queryParams.$filter = queryParams.$filter.replace(
|
|
202
|
+
/tolower\(([^\)]+)\)/g,
|
|
203
|
+
removeMethod,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* 判断是否是mongo或meteor-mongo驱动
|
|
210
|
+
* @param driverName 驱动名
|
|
211
|
+
* @returns
|
|
212
|
+
*/
|
|
213
|
+
function isPlatformDriver(driverName: string): boolean {
|
|
214
|
+
if (
|
|
215
|
+
driverName == SteedosDatabaseDriverType.Mongo ||
|
|
216
|
+
driverName == SteedosDatabaseDriverType.MeteorMongo
|
|
217
|
+
) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const excludeDeleted = function (filters: string) {
|
|
224
|
+
if (filters && filters.indexOf("(is_deleted eq true)") > -1) {
|
|
225
|
+
return filters;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return filters
|
|
229
|
+
? `(${filters}) and (is_deleted ne true)`
|
|
230
|
+
: `(is_deleted ne true)`;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const getOptionLabel = function (optionValue, options) {
|
|
234
|
+
let option = _.find(options, function (o) {
|
|
235
|
+
return o.value == optionValue;
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
if (option && option.label) {
|
|
239
|
+
return option.label;
|
|
240
|
+
} else {
|
|
241
|
+
return optionValue;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const key2value = async function (fieldValue, fieldConfig, userSession) {
|
|
246
|
+
switch (fieldConfig.type) {
|
|
247
|
+
case "boolean":
|
|
248
|
+
if (fieldValue) {
|
|
249
|
+
return t("form_field_checkbox_yes", {}, userSession.language);
|
|
250
|
+
} else {
|
|
251
|
+
return t("form_field_checkbox_no", {}, userSession.language);
|
|
252
|
+
}
|
|
253
|
+
case "select":
|
|
254
|
+
let options = fieldConfig.options;
|
|
255
|
+
|
|
256
|
+
if (fieldConfig.multiple && _.isArray(fieldValue)) {
|
|
257
|
+
for (let i = 0; i < fieldValue.length; i++) {
|
|
258
|
+
let newValue = getOptionLabel(fieldValue[i], options);
|
|
259
|
+
fieldValue[i] = newValue;
|
|
260
|
+
}
|
|
261
|
+
return fieldValue;
|
|
262
|
+
} else {
|
|
263
|
+
return getOptionLabel(fieldValue, options);
|
|
264
|
+
}
|
|
265
|
+
case "master_detail":
|
|
266
|
+
case "lookup":
|
|
267
|
+
let reference_to = fieldConfig.reference_to;
|
|
268
|
+
let ref_coll: any;
|
|
269
|
+
let id = fieldValue;
|
|
270
|
+
// 判断reference_to是已经指定的对象名,还是通过function计算的对象名
|
|
271
|
+
if (
|
|
272
|
+
_.isFunction(reference_to) ||
|
|
273
|
+
(fieldConfig._reference_to &&
|
|
274
|
+
fieldConfig._reference_to.startsWith("function"))
|
|
275
|
+
) {
|
|
276
|
+
reference_to = fieldValue.o;
|
|
277
|
+
id = fieldConfig.multiple ? fieldValue.ids : fieldValue.ids[0];
|
|
278
|
+
}
|
|
279
|
+
ref_coll = await objectql.getObject(reference_to);
|
|
280
|
+
const nameFieldKey = await ref_coll.getNameFieldKey();
|
|
281
|
+
let reference_to_field = fieldConfig.reference_to_field;
|
|
282
|
+
let filters: any[] = [];
|
|
283
|
+
if (reference_to_field) {
|
|
284
|
+
filters[0] = reference_to_field;
|
|
285
|
+
} else {
|
|
286
|
+
filters[0] = "_id";
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!fieldConfig.multiple) {
|
|
290
|
+
filters[1] = "=";
|
|
291
|
+
filters[2] = id;
|
|
292
|
+
let ref_record = await ref_coll.find({
|
|
293
|
+
filters: filters,
|
|
294
|
+
fields: [filters[0], nameFieldKey],
|
|
295
|
+
});
|
|
296
|
+
if (ref_record && ref_record.length == 1) {
|
|
297
|
+
return ref_record[0][nameFieldKey];
|
|
298
|
+
} else {
|
|
299
|
+
return id;
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
filters[1] = "in";
|
|
303
|
+
filters[2] = id;
|
|
304
|
+
// 如果id不是数组,则返回id
|
|
305
|
+
if (!_.isArray(id)) {
|
|
306
|
+
return id;
|
|
307
|
+
}
|
|
308
|
+
let ref_record = await ref_coll.find({
|
|
309
|
+
filters: filters,
|
|
310
|
+
fields: [filters[0], nameFieldKey],
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
for (let i = 0; i < id.length; i++) {
|
|
314
|
+
let _record = _.find(ref_record, function (r) {
|
|
315
|
+
return r[filters[0]] == id[i];
|
|
316
|
+
});
|
|
317
|
+
if (_record) {
|
|
318
|
+
id[i] = _record[nameFieldKey];
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return id;
|
|
322
|
+
}
|
|
323
|
+
case "date":
|
|
324
|
+
return moment(fieldValue).format("YYYY-MM-DD");
|
|
325
|
+
case "datetime":
|
|
326
|
+
return moment(fieldValue)
|
|
327
|
+
.utcOffset(userSession.utcOffset ?? 8)
|
|
328
|
+
.format("YYYY-MM-DD H:mm");
|
|
329
|
+
case "time":
|
|
330
|
+
return moment(fieldValue).utcOffset(0).format("HH:mm");
|
|
331
|
+
case "summary":
|
|
332
|
+
let summaryObj = await objectql.getObject(fieldConfig.summary_object);
|
|
333
|
+
let summaryField = summaryObj.fields[fieldConfig.summary_field];
|
|
334
|
+
if (summaryField) {
|
|
335
|
+
return await key2value(fieldValue, summaryField, userSession);
|
|
336
|
+
}
|
|
337
|
+
return fieldValue;
|
|
338
|
+
default:
|
|
339
|
+
return fieldValue;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
router.get(
|
|
344
|
+
"/api/record/export/:objectName",
|
|
345
|
+
requireAuthentication,
|
|
346
|
+
async function (req: any, res: any) {
|
|
347
|
+
return await exportRecordData(req, res);
|
|
348
|
+
},
|
|
349
|
+
);
|
|
350
|
+
exports.default = router;
|
|
@@ -3,110 +3,177 @@
|
|
|
3
3
|
* @Date: 2022-06-09 10:19:47
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
5
|
* @LastEditTime: 2025-02-18 11:47:54
|
|
6
|
-
* @Description:
|
|
6
|
+
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
import { getSteedosSchema } from "@steedos/objectql";
|
|
9
|
-
const express = require(
|
|
10
|
-
const router =express.Router();
|
|
11
|
-
const auth = require(
|
|
9
|
+
const express = require("express");
|
|
10
|
+
const router = express.Router();
|
|
11
|
+
const auth = require("@steedos/auth");
|
|
12
|
+
const _ = require("lodash");
|
|
12
13
|
|
|
13
|
-
const callObjectServiceAction = async function(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const callObjectServiceAction = async function (
|
|
15
|
+
actionName,
|
|
16
|
+
userSession,
|
|
17
|
+
data?,
|
|
18
|
+
) {
|
|
19
|
+
const broker = getSteedosSchema().broker;
|
|
20
|
+
return broker.call(actionName, data, { meta: { user: userSession } });
|
|
21
|
+
};
|
|
17
22
|
|
|
18
|
-
const getObjectName = function(objectServiceName){
|
|
19
|
-
|
|
20
|
-
}
|
|
23
|
+
const getObjectName = function (objectServiceName) {
|
|
24
|
+
return objectServiceName.substring(1);
|
|
25
|
+
};
|
|
21
26
|
|
|
22
|
-
router.get(
|
|
27
|
+
router.get(
|
|
28
|
+
"/service/api/:objectServiceName/fields",
|
|
29
|
+
auth.requireAuthentication,
|
|
30
|
+
async function (req, res) {
|
|
23
31
|
const userSession = req.user;
|
|
24
32
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
const { objectServiceName } = req.params;
|
|
34
|
+
const { fields } = req.query;
|
|
35
|
+
const result = await callObjectServiceAction(
|
|
36
|
+
`objectql.getFields`,
|
|
37
|
+
userSession,
|
|
38
|
+
{ objectName: getObjectName(objectServiceName) },
|
|
39
|
+
);
|
|
40
|
+
if (fields) {
|
|
41
|
+
const result2 = {};
|
|
42
|
+
_.each(result, function (item, k) {
|
|
43
|
+
return (result2[k] = _.pick(item, _.split(fields, ",")));
|
|
44
|
+
});
|
|
45
|
+
return res.status(200).send(result2);
|
|
46
|
+
}
|
|
47
|
+
res.status(200).send(result);
|
|
28
48
|
} catch (error) {
|
|
29
|
-
|
|
49
|
+
res.status(500).send(error.message);
|
|
30
50
|
}
|
|
31
|
-
}
|
|
51
|
+
},
|
|
52
|
+
);
|
|
32
53
|
|
|
33
|
-
router.get(
|
|
54
|
+
router.get(
|
|
55
|
+
"/service/api/:objectServiceName/getUserObjectPermission",
|
|
56
|
+
auth.requireAuthentication,
|
|
57
|
+
async function (req, res) {
|
|
34
58
|
const userSession = req.user;
|
|
35
59
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
60
|
+
const { objectServiceName } = req.params;
|
|
61
|
+
const result = await callObjectServiceAction(
|
|
62
|
+
`objectql.getUserObjectPermission`,
|
|
63
|
+
userSession,
|
|
64
|
+
{ objectName: getObjectName(objectServiceName) },
|
|
65
|
+
);
|
|
66
|
+
res.status(200).send(result);
|
|
39
67
|
} catch (error) {
|
|
40
|
-
|
|
68
|
+
res.status(500).send(error.message);
|
|
41
69
|
}
|
|
42
|
-
}
|
|
70
|
+
},
|
|
71
|
+
);
|
|
43
72
|
|
|
44
|
-
router.get(
|
|
73
|
+
router.get(
|
|
74
|
+
"/service/api/:objectServiceName/recordPermissions/:recordId",
|
|
75
|
+
auth.requireAuthentication,
|
|
76
|
+
async function (req, res) {
|
|
45
77
|
const userSession = req.user;
|
|
46
78
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
79
|
+
const { objectServiceName, recordId } = req.params;
|
|
80
|
+
const result = await callObjectServiceAction(
|
|
81
|
+
`objectql.getRecordPermissionsById`,
|
|
82
|
+
userSession,
|
|
83
|
+
{
|
|
84
|
+
objectName: getObjectName(objectServiceName),
|
|
85
|
+
recordId: recordId,
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
res.status(200).send(result);
|
|
53
89
|
} catch (error) {
|
|
54
|
-
|
|
90
|
+
res.status(500).send(error.message);
|
|
55
91
|
}
|
|
56
|
-
}
|
|
92
|
+
},
|
|
93
|
+
);
|
|
57
94
|
|
|
58
|
-
router.get(
|
|
95
|
+
router.get(
|
|
96
|
+
"/service/api/:objectServiceName/uiSchema",
|
|
97
|
+
auth.requireAuthentication,
|
|
98
|
+
async function (req, res) {
|
|
59
99
|
const userSession = req.user;
|
|
60
100
|
try {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
101
|
+
const { objectServiceName } = req.params;
|
|
102
|
+
const objectName = objectServiceName.substring(1);
|
|
103
|
+
// const [ result, hasImportTemplates ] = await Promise.all([
|
|
104
|
+
// callObjectServiceAction(`objectql.getRecordView`, userSession, { objectName }),
|
|
105
|
+
// callObjectServiceAction(`@steedos/data-import.hasImportTemplates`, userSession, {
|
|
106
|
+
// objectName: objectName
|
|
107
|
+
// })
|
|
108
|
+
// ])
|
|
109
|
+
// result.hasImportTemplates = hasImportTemplates //TODO 这段查的有点多
|
|
110
|
+
const [result] = await Promise.all([
|
|
111
|
+
callObjectServiceAction(`objectql.getRecordView`, userSession, {
|
|
112
|
+
objectName,
|
|
113
|
+
}),
|
|
114
|
+
]);
|
|
115
|
+
res.status(200).send(result);
|
|
74
116
|
} catch (error) {
|
|
75
|
-
|
|
117
|
+
res.status(500).send(error.message);
|
|
76
118
|
}
|
|
77
|
-
}
|
|
119
|
+
},
|
|
120
|
+
);
|
|
78
121
|
|
|
79
|
-
router.post(
|
|
122
|
+
router.post(
|
|
123
|
+
"/service/api/:objectServiceName/defUiSchema",
|
|
124
|
+
auth.requireAuthentication,
|
|
125
|
+
async function (req, res) {
|
|
80
126
|
const userSession = req.user;
|
|
81
127
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
128
|
+
const { objectServiceName } = req.params;
|
|
129
|
+
const result = await callObjectServiceAction(
|
|
130
|
+
`objectql.createDefaultRecordView`,
|
|
131
|
+
userSession,
|
|
132
|
+
{ objectName: getObjectName(objectServiceName) },
|
|
133
|
+
);
|
|
134
|
+
res.status(200).send(result);
|
|
85
135
|
} catch (error) {
|
|
86
|
-
|
|
136
|
+
res.status(500).send(error.message);
|
|
87
137
|
}
|
|
88
|
-
}
|
|
138
|
+
},
|
|
139
|
+
);
|
|
89
140
|
|
|
90
|
-
router.get(
|
|
141
|
+
router.get(
|
|
142
|
+
"/service/api/:objectServiceName/uiSchemaTemplate",
|
|
143
|
+
auth.requireAuthentication,
|
|
144
|
+
async function (req, res) {
|
|
91
145
|
const userSession = req.user;
|
|
92
146
|
try {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
147
|
+
const { objectServiceName } = req.params;
|
|
148
|
+
const result = await callObjectServiceAction(
|
|
149
|
+
`objectql.getDefaultRecordView`,
|
|
150
|
+
userSession,
|
|
151
|
+
{ objectName: getObjectName(objectServiceName) },
|
|
152
|
+
);
|
|
153
|
+
res.status(200).send(result);
|
|
96
154
|
} catch (error) {
|
|
97
|
-
|
|
155
|
+
res.status(500).send(error.message);
|
|
98
156
|
}
|
|
99
|
-
}
|
|
157
|
+
},
|
|
158
|
+
);
|
|
100
159
|
|
|
101
|
-
router.get(
|
|
160
|
+
router.get(
|
|
161
|
+
"/service/api/:objectServiceName/relateds",
|
|
162
|
+
auth.requireAuthentication,
|
|
163
|
+
async function (req, res) {
|
|
102
164
|
const userSession = req.user;
|
|
103
165
|
try {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
166
|
+
const { objectServiceName } = req.params;
|
|
167
|
+
const result = await callObjectServiceAction(
|
|
168
|
+
`objectql.getRelateds`,
|
|
169
|
+
userSession,
|
|
170
|
+
{ objectName: getObjectName(objectServiceName) },
|
|
171
|
+
);
|
|
172
|
+
res.status(200).send(result);
|
|
107
173
|
} catch (error) {
|
|
108
|
-
|
|
174
|
+
res.status(500).send(error.message);
|
|
109
175
|
}
|
|
110
|
-
}
|
|
176
|
+
},
|
|
177
|
+
);
|
|
111
178
|
|
|
112
|
-
exports.default = router;
|
|
179
|
+
exports.default = router;
|