@cocreate/organizations 1.2.2 → 1.2.5
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/CHANGELOG.md +22 -0
- package/CoCreate.config.js +1 -1
- package/demo/CoCreate-createUser.html +1 -1
- package/demo/index.html +1 -1
- package/demo/industries/industries.html +1 -1
- package/demo/industries/industry-datatable.html +1 -1
- package/demo/industries/industry-documents-datatable.1.html +1 -1
- package/package.json +1 -1
- package/src/client.js +3 -35
- package/src/server.js +13 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [1.2.5](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.4...v1.2.5) (2022-05-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* remove dead code ([b8b78fb](https://github.com/CoCreate-app/CoCreate-organizations/commit/b8b78fba6b8d0ab661d29d96a03a2dca5a1b9d38))
|
|
7
|
+
|
|
8
|
+
## [1.2.4](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.3...v1.2.4) (2022-05-09)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* insert returns insertedId instead of [0]._id ([3a604ed](https://github.com/CoCreate-app/CoCreate-organizations/commit/3a604ed3759f3d607243b29b9ee568bb459ab40f))
|
|
14
|
+
|
|
15
|
+
## [1.2.3](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.2...v1.2.3) (2022-05-06)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* replace ObjectID with ObjectId due to mongodb depreciation ([675f499](https://github.com/CoCreate-app/CoCreate-organizations/commit/675f49949d338e735e5d6df8a1be01b9b5f71751))
|
|
21
|
+
* update config organization_Id to organization_id ([be77abe](https://github.com/CoCreate-app/CoCreate-organizations/commit/be77abe662b7839f3f97ad1dcc54835d85dc67c1))
|
|
22
|
+
|
|
1
23
|
## [1.2.2](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.1...v1.2.2) (2022-03-21)
|
|
2
24
|
|
|
3
25
|
|
package/CoCreate.config.js
CHANGED
package/demo/index.html
CHANGED
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -3,14 +3,8 @@ import crud from '@cocreate/crud-client';
|
|
|
3
3
|
import action from '@cocreate/actions';
|
|
4
4
|
|
|
5
5
|
const CoCreateOrganization = {
|
|
6
|
-
// masterDB: '5ae0cfac6fb8c4e656fdaf92', // '5ae0cfac6fb8c4e656fdaf92' /** masterDB **/,
|
|
7
6
|
init: function() {
|
|
8
7
|
const self = this;
|
|
9
|
-
crud.listen('createOrgNew', function(data) {
|
|
10
|
-
document.dispatchEvent(new CustomEvent('createdOrg', {
|
|
11
|
-
detail: data
|
|
12
|
-
}));
|
|
13
|
-
});
|
|
14
8
|
crud.listen('createOrg', function(data) {
|
|
15
9
|
self.setDocumentId('organizations', data.document_id);
|
|
16
10
|
document.dispatchEvent(new CustomEvent('createdOrg', {
|
|
@@ -18,23 +12,7 @@ const CoCreateOrganization = {
|
|
|
18
12
|
}));
|
|
19
13
|
});
|
|
20
14
|
},
|
|
21
|
-
|
|
22
|
-
createOrgNew: function(btn) {
|
|
23
|
-
let form = btn.closest("form");
|
|
24
|
-
if (!form) return;
|
|
25
|
-
let newOrg_id = form.querySelector("input[collection='organizations'][name='_id']");
|
|
26
|
-
|
|
27
|
-
const room = config.organization_Id;
|
|
28
|
-
|
|
29
|
-
crud.send('createOrgNew', {
|
|
30
|
-
apiKey: config.apiKey,
|
|
31
|
-
organization_id: config.organization_Id,
|
|
32
|
-
collection: 'organizations',
|
|
33
|
-
newOrg_id: newOrg_id,
|
|
34
|
-
}, room);
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
|
|
15
|
+
|
|
38
16
|
createOrg: function(btn) {
|
|
39
17
|
let form = btn.closest("form");
|
|
40
18
|
if (!form) return;
|
|
@@ -52,13 +30,11 @@ const CoCreateOrganization = {
|
|
|
52
30
|
}
|
|
53
31
|
data[name] = value;
|
|
54
32
|
});
|
|
55
|
-
const room = config.
|
|
33
|
+
const room = config.organization_id;
|
|
56
34
|
|
|
57
35
|
crud.send('createOrg', {
|
|
58
36
|
apiKey: config.apiKey,
|
|
59
|
-
organization_id: config.
|
|
60
|
-
// orgDb: newOrg,
|
|
61
|
-
mdb: '5ae0cfac6fb8c4e656fdaf92',
|
|
37
|
+
organization_id: config.organization_id,
|
|
62
38
|
collection: 'organizations',
|
|
63
39
|
data: data
|
|
64
40
|
}, room);
|
|
@@ -80,14 +56,6 @@ const CoCreateOrganization = {
|
|
|
80
56
|
|
|
81
57
|
};
|
|
82
58
|
|
|
83
|
-
action.init({
|
|
84
|
-
name: "createOrgNew",
|
|
85
|
-
endEvent: "createdOrg",
|
|
86
|
-
callback: (btn, data) => {
|
|
87
|
-
CoCreateOrganization.createOrgNew(btn);
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
|
|
91
59
|
action.init({
|
|
92
60
|
name: "createOrg",
|
|
93
61
|
endEvent: "createdOrg",
|
package/src/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {ObjectId} = require("mongodb");
|
|
2
2
|
|
|
3
3
|
class CoCreateOrganization {
|
|
4
4
|
constructor(wsManager, dbClient) {
|
|
@@ -9,42 +9,11 @@ class CoCreateOrganization {
|
|
|
9
9
|
|
|
10
10
|
init() {
|
|
11
11
|
if (this.wsManager) {
|
|
12
|
-
this.wsManager.on('createOrgNew', (socket, data, socketInfo) => this.createOrgNew(socket, data));
|
|
13
12
|
this.wsManager.on('createOrg', (socket, data, socketInfo) => this.createOrg(socket, data));
|
|
14
13
|
this.wsManager.on('deleteOrg', (socket, data, socketInfo) => this.deleteOrg(socket, data));
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
async createOrgNew(socket, data) {
|
|
19
|
-
const self = this;
|
|
20
|
-
if(!data) return;
|
|
21
|
-
const newOrg_id = data.newOrg_id;
|
|
22
|
-
if (newOrg_id != data.organization_id) {
|
|
23
|
-
try{
|
|
24
|
-
const db = this.dbClient.db(req_data['organization_id']);
|
|
25
|
-
const collection = db.collection(req_data["collection"]);
|
|
26
|
-
const query = {
|
|
27
|
-
"_id": new ObjectID(newOrg_id)
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
collection.find(query).toArray(function(error, result) {
|
|
31
|
-
if(!error && result){
|
|
32
|
-
const newOrgDb = self.dbClient.db(newOrg_id).collection(data['collection']);
|
|
33
|
-
// Create new user in config db users collection
|
|
34
|
-
newOrgDb.insertOne({...result.ops[0], organization_id : newOrg_id}, function(error, result) {
|
|
35
|
-
if(!error && result){
|
|
36
|
-
const response = { ...data, document_id: result.ops[0]._id, data: result.ops[0]}
|
|
37
|
-
self.wsManager.send(socket, 'createOrgNew', response, data['organization_id']);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}catch(error){
|
|
43
|
-
console.log('createDocument error', error);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
17
|
async createOrg(socket, data) {
|
|
49
18
|
const self = this;
|
|
50
19
|
if(!data.data) return;
|
|
@@ -52,22 +21,27 @@ class CoCreateOrganization {
|
|
|
52
21
|
try{
|
|
53
22
|
const collection = this.dbClient.db(data.organization_id).collection(data.collection);
|
|
54
23
|
// create new org in config db organization collection
|
|
24
|
+
// ToDo: if data.data._id create org in platformDB
|
|
55
25
|
collection.insertOne({ ...data.data, organization_id: data.organization_id }, function(error, result) {
|
|
56
26
|
if(!error && result){
|
|
57
|
-
const orgId = result.
|
|
27
|
+
const orgId = `${result.insertedId}`
|
|
28
|
+
data.data['_id'] = result.insertedId
|
|
29
|
+
|
|
58
30
|
const anotherCollection = self.dbClient.db(orgId).collection(data['collection']);
|
|
59
31
|
// Create new org db and insert organization
|
|
60
|
-
anotherCollection.insertOne({...
|
|
32
|
+
anotherCollection.insertOne({...data.data, organization_id : orgId});
|
|
61
33
|
|
|
62
|
-
const response = { ...data, document_id:
|
|
34
|
+
const response = { ...data, document_id: orgId }
|
|
63
35
|
|
|
64
36
|
self.wsManager.send(socket, 'createOrg', response );
|
|
65
37
|
self.wsManager.broadcast(socket, data.namespace || data['organization_id'] , data.room, 'createDocument', response);
|
|
66
|
-
}
|
|
67
|
-
// add new org to masterDb
|
|
68
|
-
const masterOrgDb = self.dbClient.db(data.mdb).collection(data['collection']);
|
|
69
|
-
masterOrgDb.insertOne({...result.ops[0], organization_id : data['mdb']});
|
|
70
38
|
|
|
39
|
+
// add new org to platformDB
|
|
40
|
+
if (data.organization_id != process.env.organization_id) {
|
|
41
|
+
const platformDB = self.dbClient.db(process.env.organization_id).collection(data['collection']);
|
|
42
|
+
platformDB.insertOne({...data.data, organization_id: process.env.organization_id});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
71
45
|
});
|
|
72
46
|
}catch(error){
|
|
73
47
|
console.log('createDocument error', error);
|