@steedos/service-objectql 2.7.27-beta.6 → 3.0.0-beta.100

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/package.service.js +36 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-objectql",
3
- "version": "2.7.27-beta.6",
3
+ "version": "3.0.0-beta.100",
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": "4cc6978a51be2b5b8efcad8ec8adba467df6e02a",
16
+ "gitHead": "89c69deb3ceb9d9e97c70ee23694ccecf1b4ce2b",
17
17
  "dependencies": {
18
- "@steedos/objectql": "2.7.27-beta.6"
18
+ "@steedos/objectql": "3.0.0-beta.100"
19
19
  }
20
20
  }
@@ -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-05-11 13:44:56
5
+ * @LastEditTime: 2025-01-16 16:55:42
6
6
  * @Description:
7
7
  */
8
8
  "use strict";
@@ -12,6 +12,8 @@ const { getObject } = objectql;
12
12
 
13
13
  const { ObjectId } = require('mongodb');
14
14
 
15
+ const _ = require('lodash');
16
+
15
17
  /**
16
18
  * @typedef {import('moleculer').Context} Context Moleculer's Context
17
19
  */
@@ -569,8 +571,12 @@ module.exports = {
569
571
  async handler(ctx) {
570
572
  return await this.getPrimarySpaceId()
571
573
  }
574
+ },
575
+ getPrimarySpace: {
576
+ async handler(ctx) {
577
+ return await this.getPrimarySpace()
578
+ }
572
579
  }
573
-
574
580
  },
575
581
 
576
582
  /**
@@ -651,6 +657,34 @@ module.exports = {
651
657
  }
652
658
  this.primarySpaceId = spaceId
653
659
  return this.primarySpaceId
660
+ },
661
+ getPrimarySpace: async function () {
662
+ if(this.primarySpace){
663
+ return this.primarySpace;
664
+ }
665
+ const steedosConfig = objectql.getSteedosConfig();
666
+ let spaceId;
667
+ if (steedosConfig && steedosConfig.tenant && steedosConfig.tenant._id) {
668
+ spaceId = steedosConfig.tenant._id
669
+ }
670
+
671
+ const datasource = objectql.getDataSource('default');
672
+ if (datasource) {
673
+ const adapter = datasource.adapter;
674
+ await adapter.connect()
675
+ const collection = adapter.collection('spaces');
676
+ let space = null;
677
+ if (spaceId) {
678
+ space = await collection.findOne({ _id: spaceId })
679
+ }else{
680
+ space = await collection.findOne()
681
+ }
682
+
683
+ if (space) {
684
+ this.primarySpace = space;
685
+ }
686
+ }
687
+ return this.primarySpace
654
688
  }
655
689
  },
656
690