@cocreate/organizations 1.13.4 → 1.14.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 +13 -0
- package/package.json +1 -1
- package/src/client.js +50 -42
- package/src/server.js +58 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# [1.14.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.13.4...v1.14.0) (2023-05-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* websocket event listener for organizational creation ([bdbec1f](https://github.com/CoCreate-app/CoCreate-organizations/commit/bdbec1f4cf3e536607765561b4a74159d1d1c353))
|
|
7
|
+
* createOrganization method to correctly save data to the serverDB ([c0f574f](https://github.com/CoCreate-app/CoCreate-organizations/commit/c0f574f662c777e1b663cc35bec5a0de8438a33f))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* Create or add an exisitng organization using createOrganization() function. ([311efee](https://github.com/CoCreate-app/CoCreate-organizations/commit/311efee025bcdb4323466e38f211f746faf252bb))
|
|
13
|
+
|
|
1
14
|
## [1.13.4](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.13.3...v1.13.4) (2023-05-12)
|
|
2
15
|
|
|
3
16
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -4,51 +4,59 @@ import action from '@cocreate/actions';
|
|
|
4
4
|
import form from '@cocreate/form';
|
|
5
5
|
|
|
6
6
|
const CoCreateOrganization = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
7
|
+
|
|
8
|
+
createOrganization: async function (btn) {
|
|
9
|
+
let formEl = btn.closest("form");
|
|
10
|
+
if (!formEl) return;
|
|
11
|
+
|
|
12
|
+
let organization = form.getData(formEl, 'organizations')
|
|
13
|
+
let user = form.getData(formEl, 'users')
|
|
14
|
+
|
|
15
|
+
if (!organization || !organization.document)
|
|
16
|
+
return
|
|
17
|
+
if (!user || !user.document)
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
if (!organization.document._id && !user.document._id) {
|
|
21
|
+
let documents = await indexeddb.generateDB(organization, user)
|
|
22
|
+
if (!documents)
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
form.setDocumentId(formEl, organization)
|
|
27
|
+
form.setDocumentId(formEl, user)
|
|
28
|
+
|
|
29
|
+
organization = organization.document[0]
|
|
30
|
+
user = user.document[0]
|
|
31
|
+
|
|
32
|
+
let organization_id = organization._id
|
|
33
|
+
let key = organization.key
|
|
34
|
+
|
|
35
|
+
if (crud.socket.organization !== true) {
|
|
36
|
+
crud.socket.organization = true
|
|
37
|
+
crud.socket.create({ organization_id, key })
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let response = await crud.socket.send('createOrganization', {
|
|
41
|
+
organization,
|
|
42
|
+
user,
|
|
43
|
+
broadcastBrowser: false,
|
|
44
|
+
organization_id,
|
|
45
|
+
key
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
document.dispatchEvent(new CustomEvent('createdOrganization', {
|
|
49
|
+
detail: response
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
44
52
|
};
|
|
45
53
|
|
|
46
54
|
action.init({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
name: "createOrganization",
|
|
56
|
+
endEvent: "createdOrganization",
|
|
57
|
+
callback: (btn) => {
|
|
58
|
+
CoCreateOrganization.createOrganization(btn);
|
|
59
|
+
}
|
|
52
60
|
});
|
|
53
61
|
|
|
54
62
|
export default CoCreateOrganization;
|
package/src/server.js
CHANGED
|
@@ -1,38 +1,62 @@
|
|
|
1
1
|
class CoCreateOrganization {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
constructor(crud) {
|
|
3
|
+
this.wsManager = crud.wsManager
|
|
4
|
+
this.crud = crud
|
|
5
|
+
this.platformSocket = {
|
|
6
|
+
config: {
|
|
7
|
+
organization_id: process.env.organization_id,
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
this.init()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
init() {
|
|
14
|
+
if (this.wsManager) {
|
|
15
|
+
this.wsManager.on('createOrganization', (socket, data) =>
|
|
16
|
+
this.createOrganization(socket, data)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async createOrganization(socket, data) {
|
|
22
|
+
try {
|
|
23
|
+
if (!data.organization || !data.organization._id) return
|
|
24
|
+
if (!data.user || !data.user._id || !data.user.email || !data.user.password) return
|
|
25
|
+
|
|
26
|
+
const organization = {
|
|
27
|
+
_id: data.organization._id,
|
|
28
|
+
name: data.organization.name || 'untitled',
|
|
29
|
+
hosts: data.organization.hosts || [],
|
|
30
|
+
owner: data.user._id
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const user = {
|
|
34
|
+
_id: data.user._id,
|
|
35
|
+
name: data.user.name || 'Admin',
|
|
36
|
+
email: data.user.email,
|
|
37
|
+
password: data.user.password,
|
|
38
|
+
currentOrg: data.organization._id,
|
|
39
|
+
connectedOrgs: [data.organization._id]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const Data = {}
|
|
43
|
+
Data.database = process.env.organization_id
|
|
44
|
+
Data.organization_id = process.env.organization_id
|
|
45
|
+
|
|
46
|
+
if (organization) {
|
|
47
|
+
const response = await this.crud.createDocument({ ...Data, collection: 'organizations', document: organization })
|
|
48
|
+
this.wsManager.broadcast(this.platformSocket, 'createDocument', response);
|
|
49
|
+
}
|
|
50
|
+
if (user) {
|
|
51
|
+
const response = await this.crud.createDocument({ ...Data, collection: 'users', document: user })
|
|
52
|
+
this.wsManager.broadcast(this.platformSocket, 'createDocument', response);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.wsManager.send(socket, 'createOrganization', data);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.log('createDocument error', error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
36
60
|
}
|
|
37
61
|
|
|
38
62
|
module.exports = CoCreateOrganization;
|