@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 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
 
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
2
  "config": {
3
3
  "apiKey": "2061acef-0451-4545-f754-60cf8160",
4
- "organization_Id": "5ff747727005da1c272740ab",
4
+ "organization_id": "5ff747727005da1c272740ab",
5
5
  "host": "general.cocreate.app"
6
6
  },
7
7
 
@@ -48,7 +48,7 @@
48
48
  <script>
49
49
  var config = {
50
50
  apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
51
- organization_Id: '5de0387b12e200ea63204d6c'
51
+ organization_id: '5de0387b12e200ea63204d6c'
52
52
  }
53
53
  </script>
54
54
 
package/demo/index.html CHANGED
@@ -98,7 +98,7 @@
98
98
  <script>
99
99
  var config = {
100
100
  apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
101
- organization_Id: '5de0387b12e200ea63204d6c',
101
+ organization_id: '5de0387b12e200ea63204d6c',
102
102
  host: 'ws.cocreate.app'
103
103
  }
104
104
  </script>
@@ -75,7 +75,7 @@
75
75
  var config = {
76
76
  apiKey: '2061acef-0451-4545-f754-60cf8160',
77
77
  securityKey: '073daff2-5142-4402-cf59-48e205ef',
78
- organization_Id: '5ff747727005da1c272740ab'
78
+ organization_id: '5ff747727005da1c272740ab'
79
79
  }
80
80
  </script>
81
81
 
@@ -112,7 +112,7 @@
112
112
  <script>
113
113
  var config = {
114
114
  apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
115
- organization_Id: '5de0387b12e200ea63204d6c'
115
+ organization_id: '5de0387b12e200ea63204d6c'
116
116
  }
117
117
  </script>
118
118
 
@@ -117,7 +117,7 @@
117
117
  <script>
118
118
  var config = {
119
119
  apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
120
- organization_Id: '5de0387b12e200ea63204d6c'
120
+ organization_id: '5de0387b12e200ea63204d6c'
121
121
  }
122
122
  </script>
123
123
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.2.2",
3
+ "version": "1.2.5",
4
4
  "description": "A simple organizations component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "organizations",
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.organization_Id;
33
+ const room = config.organization_id;
56
34
 
57
35
  crud.send('createOrg', {
58
36
  apiKey: config.apiKey,
59
- organization_id: config.organization_Id,
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 {ObjectID} = require("mongodb");
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.ops[0]._id + "";
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({...result.ops[0], organization_id : orgId});
32
+ anotherCollection.insertOne({...data.data, organization_id : orgId});
61
33
 
62
- const response = { ...data, document_id: result.ops[0]._id, data: result.ops[0] }
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);