@cocreate/organizations 1.5.8 → 1.6.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 +29 -6
- package/src/server.js +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# [1.6.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.5.8...v1.6.0) (2022-09-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* broadcast params reduced to socket, message, data ([f90ea9c](https://github.com/CoCreate-app/CoCreate-organizations/commit/f90ea9cf92e9e5a03c66bf40d2525699102d11a7))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* config is accessible from socket.config ([c64dacf](https://github.com/CoCreate-app/CoCreate-organizations/commit/c64dacf3ef279c61e682c099c8801ff18567fc30))
|
|
12
|
+
* create new org while offline ([dc4223c](https://github.com/CoCreate-app/CoCreate-organizations/commit/dc4223c2e60c9ede79c040508bdc635b26f69fe6))
|
|
13
|
+
|
|
1
14
|
## [1.5.8](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.5.7...v1.5.8) (2022-09-01)
|
|
2
15
|
|
|
3
16
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import crud from '@cocreate/crud-client';
|
|
2
2
|
// import input from '@cocreate/elements'
|
|
3
3
|
import action from '@cocreate/actions';
|
|
4
|
+
import uuid from '@cocreate/uuid';
|
|
4
5
|
|
|
5
6
|
const CoCreateOrganization = {
|
|
6
7
|
init: function() {
|
|
@@ -19,7 +20,7 @@ const CoCreateOrganization = {
|
|
|
19
20
|
|
|
20
21
|
let elements = form.querySelectorAll("[collection='organizations'][name]");
|
|
21
22
|
|
|
22
|
-
let data = {};
|
|
23
|
+
let data = {data: {}};
|
|
23
24
|
//. get form data
|
|
24
25
|
elements.forEach(el => {
|
|
25
26
|
let name = el.getAttribute('name');
|
|
@@ -28,13 +29,33 @@ const CoCreateOrganization = {
|
|
|
28
29
|
if (el.getAttribute('data-type') == 'array') {
|
|
29
30
|
value = [value];
|
|
30
31
|
}
|
|
31
|
-
data[name] = value;
|
|
32
|
+
data.data[name] = value;
|
|
32
33
|
});
|
|
33
34
|
|
|
34
|
-
crud.
|
|
35
|
-
|
|
36
|
-
data
|
|
37
|
-
|
|
35
|
+
const socket = crud.socket.getSocket()
|
|
36
|
+
if (!socket || !socket.connected || window && !window.navigator.onLine) {
|
|
37
|
+
data.collection = 'organizations'
|
|
38
|
+
data.data['_id'] = ObjectId()
|
|
39
|
+
data.data['name'] = 'untitled'
|
|
40
|
+
window.localStorage.setItem('apiKey', uuid(32));
|
|
41
|
+
window.localStorage.setItem('organization_id', data['_id']);
|
|
42
|
+
crud.createDocument(data).then((response) => {
|
|
43
|
+
data.database = data.data['_id']
|
|
44
|
+
data.organization_id = data.data['_id']
|
|
45
|
+
crud.createDocument(data).then((response) => {
|
|
46
|
+
|
|
47
|
+
document.dispatchEvent(new CustomEvent('createOrg', {
|
|
48
|
+
detail: response
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
} else {
|
|
54
|
+
crud.send('createOrg', {
|
|
55
|
+
collection: 'organizations',
|
|
56
|
+
data: data
|
|
57
|
+
});
|
|
58
|
+
}
|
|
38
59
|
},
|
|
39
60
|
|
|
40
61
|
setDocumentId: function(collection, id) {
|
|
@@ -106,6 +127,8 @@ const CoCreateOrganization = {
|
|
|
106
127
|
|
|
107
128
|
};
|
|
108
129
|
|
|
130
|
+
const ObjectId = (rnd = r16 => Math.floor(r16).toString(16)) =>
|
|
131
|
+
rnd(Date.now()/1000) + ' '.repeat(16).replace(/./g, () => rnd(Math.random()*16));
|
|
109
132
|
|
|
110
133
|
action.init({
|
|
111
134
|
name: "createOrg",
|
package/src/server.js
CHANGED
|
@@ -9,16 +9,16 @@ class CoCreateOrganization {
|
|
|
9
9
|
|
|
10
10
|
init() {
|
|
11
11
|
if (this.wsManager) {
|
|
12
|
-
this.wsManager.on('createOrg', (socket, data
|
|
13
|
-
this.createOrg(socket, data
|
|
12
|
+
this.wsManager.on('createOrg', (socket, data) =>
|
|
13
|
+
this.createOrg(socket, data)
|
|
14
14
|
);
|
|
15
|
-
this.wsManager.on('deleteOrg', (socket, data
|
|
16
|
-
this.deleteOrg(socket, data
|
|
15
|
+
this.wsManager.on('deleteOrg', (socket, data) =>
|
|
16
|
+
this.deleteOrg(socket, data)
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
async createOrg(socket, data
|
|
21
|
+
async createOrg(socket, data) {
|
|
22
22
|
const self = this;
|
|
23
23
|
if(!data.data) return;
|
|
24
24
|
|
|
@@ -37,8 +37,8 @@ class CoCreateOrganization {
|
|
|
37
37
|
|
|
38
38
|
const response = { ...data, document_id: orgId }
|
|
39
39
|
|
|
40
|
-
self.wsManager.send(socket, 'createOrg', response
|
|
41
|
-
self.wsManager.broadcast(socket,
|
|
40
|
+
self.wsManager.send(socket, 'createOrg', response);
|
|
41
|
+
self.wsManager.broadcast(socket, 'createDocument', response);
|
|
42
42
|
|
|
43
43
|
// add new org to platformDB
|
|
44
44
|
if (data.organization_id != process.env.organization_id) {
|
|
@@ -53,7 +53,7 @@ class CoCreateOrganization {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
async deleteOrg(socket, data
|
|
56
|
+
async deleteOrg(socket, data) {
|
|
57
57
|
const self = this;
|
|
58
58
|
if(!data.data) return;
|
|
59
59
|
const organization_id = data.data.organization_id
|
|
@@ -74,10 +74,10 @@ class CoCreateOrganization {
|
|
|
74
74
|
platformDB.deleteOne(query, function(error, result) {
|
|
75
75
|
if (!error) {
|
|
76
76
|
let response = { ...data }
|
|
77
|
-
self.wsManager.send(socket, 'deleteOrg', response
|
|
78
|
-
self.wsManager.broadcast(socket,
|
|
77
|
+
self.wsManager.send(socket, 'deleteOrg', response);
|
|
78
|
+
self.wsManager.broadcast(socket, 'deleteDocument', response);
|
|
79
79
|
} else {
|
|
80
|
-
self.wsManager.send(socket, 'ServerError', error
|
|
80
|
+
self.wsManager.send(socket, 'ServerError', error);
|
|
81
81
|
}
|
|
82
82
|
})
|
|
83
83
|
}
|