@steedos/service-rest 3.0.0-beta.12 → 3.0.0-beta.122
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 -5
- package/package.service.js +45 -15
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-rest",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.122",
|
|
4
4
|
"main": "package.service.js",
|
|
5
|
-
"private": false,
|
|
6
5
|
"publishConfig": {
|
|
7
6
|
"access": "public"
|
|
8
7
|
},
|
|
@@ -16,9 +15,9 @@
|
|
|
16
15
|
"repository": {},
|
|
17
16
|
"license": "MIT",
|
|
18
17
|
"dependencies": {
|
|
19
|
-
"@steedos/objectql": "3.0.0-beta.
|
|
20
|
-
"@steedos/service-object-mixin": "3.0.0-beta.
|
|
18
|
+
"@steedos/objectql": "3.0.0-beta.122",
|
|
19
|
+
"@steedos/service-object-mixin": "3.0.0-beta.122",
|
|
21
20
|
"lodash": "^4.17.21"
|
|
22
21
|
},
|
|
23
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "81de9b7d36bd701962cab6b3d11cfa0213cf7e59"
|
|
24
23
|
}
|
package/package.service.js
CHANGED
|
@@ -13,7 +13,7 @@ const {
|
|
|
13
13
|
} = require('./consts')
|
|
14
14
|
const { translateRecords } = require('./translate');
|
|
15
15
|
const _ = require('lodash')
|
|
16
|
-
const { getObject } = require('@steedos/objectql');
|
|
16
|
+
const { getObject, getObjectConfig } = require('@steedos/objectql');
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @typedef {import('moleculer').Context} Context Moleculer's Context
|
|
@@ -534,7 +534,6 @@ module.exports = {
|
|
|
534
534
|
const userSession = ctx.meta.user;
|
|
535
535
|
const query = {}
|
|
536
536
|
if (fields) {
|
|
537
|
-
console.log(`fields:`, fields)
|
|
538
537
|
query.fields = JSON.parse(fields)
|
|
539
538
|
}
|
|
540
539
|
const doc = await this.findOne(objectName, id, query, userSession)
|
|
@@ -767,19 +766,6 @@ module.exports = {
|
|
|
767
766
|
const { objectName, functionApiName } = ctx.params;
|
|
768
767
|
const object = getObject(objectName)
|
|
769
768
|
|
|
770
|
-
// 启用API(is_rest === true) 的函数才在这里执行
|
|
771
|
-
// 从缓存获取
|
|
772
|
-
// eslint-disable-next-line no-undef
|
|
773
|
-
const fDocs = await broker.call(`${METADATA_CACHER_SERVICE_NAME}.find`, {metadataName: 'object_functions', filters: [
|
|
774
|
-
["objectApiName", "=", objectName],
|
|
775
|
-
["_name", "=", functionApiName],
|
|
776
|
-
["is_rest", "=", true]
|
|
777
|
-
]});
|
|
778
|
-
|
|
779
|
-
if (!fDocs || fDocs.length == 0) {
|
|
780
|
-
throw new Error(`function need to enable api access.`);
|
|
781
|
-
}
|
|
782
|
-
|
|
783
769
|
const result = await object.runFunction(functionApiName, ctx.params, userSession);
|
|
784
770
|
return {
|
|
785
771
|
"status": REQUEST_SUCCESS_STATUS,
|
|
@@ -788,6 +774,50 @@ module.exports = {
|
|
|
788
774
|
}
|
|
789
775
|
}
|
|
790
776
|
},
|
|
777
|
+
names: {
|
|
778
|
+
rest: {
|
|
779
|
+
method: "POST",
|
|
780
|
+
path: "/:objectName/names"
|
|
781
|
+
},
|
|
782
|
+
params: {
|
|
783
|
+
objectName: { type: "string" },
|
|
784
|
+
idKey: { type: "string" },
|
|
785
|
+
ids: { type: 'array', items: "string"}
|
|
786
|
+
},
|
|
787
|
+
async handler(ctx) {
|
|
788
|
+
const params = ctx.params
|
|
789
|
+
const { objectName, ids, idKey = '_id' } = params
|
|
790
|
+
|
|
791
|
+
if(ids.length > 500){
|
|
792
|
+
return {
|
|
793
|
+
"status": 1,
|
|
794
|
+
"msg": "Exceeded maximum ID limit",
|
|
795
|
+
"data": {}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
const obj = await getObject(objectName);
|
|
800
|
+
|
|
801
|
+
const records = await obj.directFind({
|
|
802
|
+
filters: [idKey, 'in', ids],
|
|
803
|
+
fields: [idKey, obj.NAME_FIELD_KEY || 'name']
|
|
804
|
+
})
|
|
805
|
+
|
|
806
|
+
return {
|
|
807
|
+
"status": REQUEST_SUCCESS_STATUS,
|
|
808
|
+
"msg": "",
|
|
809
|
+
"data": {
|
|
810
|
+
"options": _.map(records, (item)=>{
|
|
811
|
+
return {
|
|
812
|
+
label: item[obj.NAME_FIELD_KEY || 'name'],
|
|
813
|
+
value: item[idKey]
|
|
814
|
+
}
|
|
815
|
+
}),
|
|
816
|
+
"total": records.length
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
791
821
|
},
|
|
792
822
|
|
|
793
823
|
/**
|