@cocreate/organizations 1.2.3 → 1.2.4

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,10 @@
1
+ ## [1.2.4](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.3...v1.2.4) (2022-05-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * insert returns insertedId instead of [0]._id ([3a604ed](https://github.com/CoCreate-app/CoCreate-organizations/commit/3a604ed3759f3d607243b29b9ee568bb459ab40f))
7
+
1
8
  ## [1.2.3](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.2.2...v1.2.3) (2022-05-06)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
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
@@ -56,8 +56,6 @@ const CoCreateOrganization = {
56
56
  crud.send('createOrg', {
57
57
  apiKey: config.apiKey,
58
58
  organization_id: config.organization_id,
59
- // orgDb: newOrg,
60
- mdb: '5ae0cfac6fb8c4e656fdaf92',
61
59
  collection: 'organizations',
62
60
  data: data
63
61
  }, room);
package/src/server.js CHANGED
@@ -33,7 +33,7 @@ class CoCreateOrganization {
33
33
  // Create new user in config db users collection
34
34
  newOrgDb.insertOne({...result.ops[0], organization_id : newOrg_id}, function(error, result) {
35
35
  if(!error && result){
36
- const response = { ...data, document_id: result.ops[0]._id, data: result.ops[0]}
36
+ const response = { ...data, document_id: `${result.insertedId}`, data: result.ops[0]}
37
37
  self.wsManager.send(socket, 'createOrgNew', response, data['organization_id']);
38
38
  }
39
39
  });
@@ -54,20 +54,23 @@ class CoCreateOrganization {
54
54
  // create new org in config db organization collection
55
55
  collection.insertOne({ ...data.data, organization_id: data.organization_id }, function(error, result) {
56
56
  if(!error && result){
57
- const orgId = result.ops[0]._id + "";
57
+ const orgId = `${result.insertedId}`
58
+ data.data['_id'] = result.insertedId
58
59
  const anotherCollection = self.dbClient.db(orgId).collection(data['collection']);
59
60
  // Create new org db and insert organization
60
- anotherCollection.insertOne({...result.ops[0], organization_id : orgId});
61
+ anotherCollection.insertOne({...data.data, organization_id : orgId});
61
62
 
62
- const response = { ...data, document_id: result.ops[0]._id, data: result.ops[0] }
63
+ const response = { ...data, document_id: orgId }
63
64
 
64
65
  self.wsManager.send(socket, 'createOrg', response );
65
66
  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
67
 
68
+ // add new org to platformDB
69
+ if (data.organization_id != process.env.organization_id) {
70
+ const platformDB = self.dbClient.db(process.env.organization_id).collection(data['collection']);
71
+ platformDB.insertOne({...data.data, organization_id: process.env.organization_id});
72
+ }
73
+ }
71
74
  });
72
75
  }catch(error){
73
76
  console.log('createDocument error', error);