@steedos/service-objectql 2.6.1-beta.7 → 2.6.2-beta.2
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 +3 -3
- package/package.service.js +55 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-objectql",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2-beta.2",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"description": "steedos package",
|
|
14
14
|
"repository": {},
|
|
15
15
|
"license": "MIT",
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "ddef9fbc34afc7b57c59a31e9ed4f56818dc4c31",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@steedos/objectql": "2.6.
|
|
18
|
+
"@steedos/objectql": "2.6.2-beta.2"
|
|
19
19
|
}
|
|
20
20
|
}
|
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: 孙浩林 sunhaolin@steedos.com
|
|
5
|
-
* @LastEditTime: 2023-
|
|
5
|
+
* @LastEditTime: 2023-11-14 10:43:21
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
"use strict";
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
const objectql = require('@steedos/objectql');
|
|
11
11
|
const { getObject } = objectql;
|
|
12
12
|
|
|
13
|
+
const { ObjectId } = require('mongodb');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @typedef {import('moleculer').Context} Context Moleculer's Context
|
|
@@ -371,7 +372,7 @@ module.exports = {
|
|
|
371
372
|
getRecordPermissionsById: {
|
|
372
373
|
params: {
|
|
373
374
|
objectName: { type: "string" },
|
|
374
|
-
recordId: { type: "
|
|
375
|
+
recordId: { type: "any" },
|
|
375
376
|
},
|
|
376
377
|
async handler(ctx) {
|
|
377
378
|
const userSession = ctx.meta.user;
|
|
@@ -506,6 +507,38 @@ module.exports = {
|
|
|
506
507
|
const { objectName, doc } = ctx.params;
|
|
507
508
|
return await this.encryptFieldValue(objectName, doc);
|
|
508
509
|
}
|
|
510
|
+
},
|
|
511
|
+
makeNewID: {
|
|
512
|
+
async handler(ctx) {
|
|
513
|
+
return new ObjectId().toHexString();
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
createIndex: {
|
|
517
|
+
params: {
|
|
518
|
+
objectName: { type: "string" },
|
|
519
|
+
fieldName: { type: "string" },
|
|
520
|
+
},
|
|
521
|
+
async handler(ctx) {
|
|
522
|
+
const { objectName, fieldName } = ctx.params;
|
|
523
|
+
const obj = getObject(objectName)
|
|
524
|
+
return await obj.createIndex(fieldName);
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
dropIndex: {
|
|
528
|
+
params: {
|
|
529
|
+
objectName: { type: "string" },
|
|
530
|
+
fieldName: { type: "string" },
|
|
531
|
+
},
|
|
532
|
+
async handler(ctx) {
|
|
533
|
+
const { objectName, fieldName } = ctx.params;
|
|
534
|
+
const obj = getObject(objectName)
|
|
535
|
+
return await obj.dropIndex(fieldName);
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
getPrimarySpaceId: {
|
|
539
|
+
async handler(ctx) {
|
|
540
|
+
return await this.getPrimarySpaceId()
|
|
541
|
+
}
|
|
509
542
|
}
|
|
510
543
|
|
|
511
544
|
},
|
|
@@ -564,6 +597,26 @@ module.exports = {
|
|
|
564
597
|
console.error(`[字段级加密] 对象${objectName}中字段加密失败:`, error);
|
|
565
598
|
}
|
|
566
599
|
return doc;
|
|
600
|
+
},
|
|
601
|
+
getPrimarySpaceId: async function () {
|
|
602
|
+
const steedosConfig = objectql.getSteedosConfig();
|
|
603
|
+
let spaceId;
|
|
604
|
+
if (steedosConfig && steedosConfig.tenant && steedosConfig.tenant._id) {
|
|
605
|
+
spaceId = steedosConfig.tenant._id
|
|
606
|
+
}
|
|
607
|
+
if (!spaceId) {
|
|
608
|
+
const datasource = objectql.getDataSource('default');
|
|
609
|
+
if (datasource) {
|
|
610
|
+
const adapter = datasource.adapter;
|
|
611
|
+
await adapter.connect()
|
|
612
|
+
const collection = adapter.collection('spaces');
|
|
613
|
+
const space = await collection.findOne()
|
|
614
|
+
if (space) {
|
|
615
|
+
spaceId = space._id;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return spaceId
|
|
567
620
|
}
|
|
568
621
|
},
|
|
569
622
|
|