@cocreate/organizations 1.2.3 → 1.3.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.3.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.5...v1.3.0) (2022-05-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * function readDocumentList has been renamed to readDocuments ([9c62367](https://github.com/CoCreate-app/CoCreate-organizations/commit/9c623672b44a9548ab784bbfff9ebef63ac6e805))
7
+
8
+ ## [1.2.5](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.4...v1.2.5) (2022-05-13)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove dead code ([b8b78fb](https://github.com/CoCreate-app/CoCreate-organizations/commit/b8b78fba6b8d0ab661d29d96a03a2dca5a1b9d38))
14
+
15
+ ## [1.2.4](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.3...v1.2.4) (2022-05-09)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * insert returns insertedId instead of [0]._id ([3a604ed](https://github.com/CoCreate-app/CoCreate-organizations/commit/3a604ed3759f3d607243b29b9ee568bb459ab40f))
21
+
1
22
  ## [1.2.3](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.2...v1.2.3) (2022-05-06)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.2.3",
3
+ "version": "1.3.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",
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;
@@ -56,8 +35,6 @@ const CoCreateOrganization = {
56
35
  crud.send('createOrg', {
57
36
  apiKey: config.apiKey,
58
37
  organization_id: config.organization_id,
59
- // orgDb: newOrg,
60
- mdb: '5ae0cfac6fb8c4e656fdaf92',
61
38
  collection: 'organizations',
62
39
  data: data
63
40
  }, room);
@@ -79,14 +56,6 @@ const CoCreateOrganization = {
79
56
 
80
57
  };
81
58
 
82
- action.init({
83
- name: "createOrgNew",
84
- endEvent: "createdOrg",
85
- callback: (btn, data) => {
86
- CoCreateOrganization.createOrgNew(btn);
87
- },
88
- });
89
-
90
59
  action.init({
91
60
  name: "createOrg",
92
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.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);