@cocreate/organizations 1.3.0 → 1.4.0

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,24 @@
1
+ # [1.4.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.3.2...v1.4.0) (2022-05-28)
2
+
3
+
4
+ ### Features
5
+
6
+ * deleteOrg will delete db and org from from platformDB ([0fcb1bc](https://github.com/CoCreate-app/CoCreate-organizations/commit/0fcb1bc2ecdbb1948733c240ce7adfaceaa2b5e6))
7
+
8
+ ## [1.3.2](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.3.1...v1.3.2) (2022-05-23)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bump all dependencies ([fdebb81](https://github.com/CoCreate-app/CoCreate-organizations/commit/fdebb813950687c404bfc70e0139f94e2a6c90e5))
14
+
15
+ ## [1.3.1](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.3.0...v1.3.1) (2022-05-17)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * get orgId from socketInfo ([77348c3](https://github.com/CoCreate-app/CoCreate-organizations/commit/77348c30afa285c152754545b549464a7202eb94))
21
+
1
22
  # [1.3.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.5...v1.3.0) (2022-05-14)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
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",
@@ -61,10 +61,10 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/actions": "^1.3.33",
65
- "@cocreate/crud-client": "^1.4.47",
66
- "@cocreate/docs": "^1.2.69",
67
- "@cocreate/elements": "^1.6.11",
64
+ "@cocreate/actions": "^1.4.1",
65
+ "@cocreate/crud-client": "^1.6.2",
66
+ "@cocreate/docs": "^1.3.1",
67
+ "@cocreate/elements": "^1.7.3",
68
68
  "mongodb": "^4.4.0"
69
69
  }
70
70
  }
package/src/server.js CHANGED
@@ -9,12 +9,12 @@ class CoCreateOrganization {
9
9
 
10
10
  init() {
11
11
  if (this.wsManager) {
12
- this.wsManager.on('createOrg', (socket, data, socketInfo) => this.createOrg(socket, data));
13
- this.wsManager.on('deleteOrg', (socket, data, socketInfo) => this.deleteOrg(socket, data));
12
+ this.wsManager.on('createOrg', (socket, data, socketInfo) => this.createOrg(socket, data, socketInfo));
13
+ this.wsManager.on('deleteOrg', (socket, data, socketInfo) => this.deleteOrg(socket, data, socketInfo));
14
14
  }
15
15
  }
16
16
 
17
- async createOrg(socket, data) {
17
+ async createOrg(socket, data, socketInfo) {
18
18
  const self = this;
19
19
  if(!data.data) return;
20
20
 
@@ -33,7 +33,7 @@ class CoCreateOrganization {
33
33
 
34
34
  const response = { ...data, document_id: orgId }
35
35
 
36
- self.wsManager.send(socket, 'createOrg', response );
36
+ self.wsManager.send(socket, 'createOrg', response, socketInfo);
37
37
  self.wsManager.broadcast(socket, data.namespace || data['organization_id'] , data.room, 'createDocument', response);
38
38
 
39
39
  // add new org to platformDB
@@ -49,11 +49,36 @@ class CoCreateOrganization {
49
49
  }
50
50
 
51
51
 
52
- async deleteOrg(socket, data) {
52
+ async deleteOrg(socket, data, socketInfo) {
53
53
  const self = this;
54
54
  if(!data.data) return;
55
+ const organization_id = data.data.organization_id
56
+ if(!organization_id || organization_id == process.env.organization_id) return;
57
+
55
58
  try{
56
- // ToDo: Delete DB and delete org and user from masterDB
59
+ const db = this.dbClient.db(organization_id);
60
+ db.dropDatabase().then(response => {
61
+ if (response === true){
62
+ console.log('deleteOrg response', response)
63
+ }
64
+
65
+ // delete org from platformDB
66
+ // if (organization_id != process.env.organization_id) {
67
+ const platformDB = self.dbClient.db(process.env.organization_id).collection(data['collection']);
68
+ const query = {
69
+ "_id": new ObjectId(organization_id)
70
+ };
71
+
72
+ platformDB.deleteOne(query, function(error, result) {
73
+ if (!error) {
74
+ let response = { ...data }
75
+ self.broadcast(socket, 'deleteDocument', response, socketInfo)
76
+ } else {
77
+ self.wsManager.send(socket, 'ServerError', error, socketInfo);
78
+ }
79
+ })
80
+ // }
81
+ })
57
82
  }catch(error){
58
83
  console.log('deleteOrg error', error);
59
84
  }