@cocreate/organizations 1.2.4 → 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 +7 -0
- package/package.json +1 -1
- package/src/client.js +1 -30
- package/src/server.js +2 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
## [1.2.4](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.3...v1.2.4) (2022-05-09)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -5,11 +5,6 @@ import action from '@cocreate/actions';
|
|
|
5
5
|
const CoCreateOrganization = {
|
|
6
6
|
init: function() {
|
|
7
7
|
const self = this;
|
|
8
|
-
crud.listen('createOrgNew', function(data) {
|
|
9
|
-
document.dispatchEvent(new CustomEvent('createdOrg', {
|
|
10
|
-
detail: data
|
|
11
|
-
}));
|
|
12
|
-
});
|
|
13
8
|
crud.listen('createOrg', function(data) {
|
|
14
9
|
self.setDocumentId('organizations', data.document_id);
|
|
15
10
|
document.dispatchEvent(new CustomEvent('createdOrg', {
|
|
@@ -17,23 +12,7 @@ const CoCreateOrganization = {
|
|
|
17
12
|
}));
|
|
18
13
|
});
|
|
19
14
|
},
|
|
20
|
-
|
|
21
|
-
createOrgNew: function(btn) {
|
|
22
|
-
let form = btn.closest("form");
|
|
23
|
-
if (!form) return;
|
|
24
|
-
let newOrg_id = form.querySelector("input[collection='organizations'][name='_id']");
|
|
25
|
-
|
|
26
|
-
const room = config.organization_id;
|
|
27
|
-
|
|
28
|
-
crud.send('createOrgNew', {
|
|
29
|
-
apiKey: config.apiKey,
|
|
30
|
-
organization_id: config.organization_id,
|
|
31
|
-
collection: 'organizations',
|
|
32
|
-
newOrg_id: newOrg_id,
|
|
33
|
-
}, room);
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
|
|
15
|
+
|
|
37
16
|
createOrg: function(btn) {
|
|
38
17
|
let form = btn.closest("form");
|
|
39
18
|
if (!form) return;
|
|
@@ -77,14 +56,6 @@ const CoCreateOrganization = {
|
|
|
77
56
|
|
|
78
57
|
};
|
|
79
58
|
|
|
80
|
-
action.init({
|
|
81
|
-
name: "createOrgNew",
|
|
82
|
-
endEvent: "createdOrg",
|
|
83
|
-
callback: (btn, data) => {
|
|
84
|
-
CoCreateOrganization.createOrgNew(btn);
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
|
|
88
59
|
action.init({
|
|
89
60
|
name: "createOrg",
|
|
90
61
|
endEvent: "createdOrg",
|
package/src/server.js
CHANGED
|
@@ -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.insertedId}`, 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,10 +21,12 @@ 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
27
|
const orgId = `${result.insertedId}`
|
|
58
28
|
data.data['_id'] = result.insertedId
|
|
29
|
+
|
|
59
30
|
const anotherCollection = self.dbClient.db(orgId).collection(data['collection']);
|
|
60
31
|
// Create new org db and insert organization
|
|
61
32
|
anotherCollection.insertOne({...data.data, organization_id : orgId});
|