@cocreate/organizations 1.2.4 → 1.3.1

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.3.1](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.3.0...v1.3.1) (2022-05-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * get orgId from socketInfo ([77348c3](https://github.com/CoCreate-app/CoCreate-organizations/commit/77348c30afa285c152754545b549464a7202eb94))
7
+
8
+ # [1.3.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.5...v1.3.0) (2022-05-14)
9
+
10
+
11
+ ### Features
12
+
13
+ * function readDocumentList has been renamed to readDocuments ([9c62367](https://github.com/CoCreate-app/CoCreate-organizations/commit/9c623672b44a9548ab784bbfff9ebef63ac6e805))
14
+
15
+ ## [1.2.5](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.4...v1.2.5) (2022-05-13)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * remove dead code ([b8b78fb](https://github.com/CoCreate-app/CoCreate-organizations/commit/b8b78fba6b8d0ab661d29d96a03a2dca5a1b9d38))
21
+
1
22
  ## [1.2.4](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.3...v1.2.4) (2022-05-09)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.2.4",
3
+ "version": "1.3.1",
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
@@ -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,60 +9,31 @@ 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
- this.wsManager.on('createOrg', (socket, data, socketInfo) => this.createOrg(socket, data));
14
- 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));
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
- async createOrg(socket, data) {
17
+ async createOrg(socket, data, socketInfo) {
49
18
  const self = this;
50
19
  if(!data.data) return;
51
20
 
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});
62
33
 
63
34
  const response = { ...data, document_id: orgId }
64
35
 
65
- self.wsManager.send(socket, 'createOrg', response );
36
+ self.wsManager.send(socket, 'createOrg', response, socketInfo);
66
37
  self.wsManager.broadcast(socket, data.namespace || data['organization_id'] , data.room, 'createDocument', response);
67
38
 
68
39
  // add new org to platformDB
@@ -78,7 +49,7 @@ class CoCreateOrganization {
78
49
  }
79
50
 
80
51
 
81
- async deleteOrg(socket, data) {
52
+ async deleteOrg(socket, data, socketInfo) {
82
53
  const self = this;
83
54
  if(!data.data) return;
84
55
  try{