@cocreate/organizations 1.3.1 → 1.5.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 +22 -0
- package/package.json +5 -5
- package/src/client.js +71 -4
- package/src/server.js +31 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
# [1.5.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.4.0...v1.5.0) (2022-05-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* deleteDocument broadcasted after orgDeleted ([be1ecee](https://github.com/CoCreate-app/CoCreate-organizations/commit/be1ecee732ce71a3877dfbb06df9b19c0148eb16))
|
|
7
|
+
* deleteOrgs action to select and delete many organizations ([0abaa20](https://github.com/CoCreate-app/CoCreate-organizations/commit/0abaa2061ac7575c51314f5011aa6031022b6d7f))
|
|
8
|
+
|
|
9
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.3.2...v1.4.0) (2022-05-28)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* deleteOrg will delete db and org from from platformDB ([0fcb1bc](https://github.com/CoCreate-app/CoCreate-organizations/commit/0fcb1bc2ecdbb1948733c240ce7adfaceaa2b5e6))
|
|
15
|
+
|
|
16
|
+
## [1.3.2](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.3.1...v1.3.2) (2022-05-23)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* bump all dependencies ([fdebb81](https://github.com/CoCreate-app/CoCreate-organizations/commit/fdebb813950687c404bfc70e0139f94e2a6c90e5))
|
|
22
|
+
|
|
1
23
|
## [1.3.1](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.3.0...v1.3.1) (2022-05-17)
|
|
2
24
|
|
|
3
25
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/organizations",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/actions": "^1.
|
|
65
|
-
"@cocreate/crud-client": "^1.
|
|
66
|
-
"@cocreate/docs": "^1.
|
|
67
|
-
"@cocreate/elements": "^1.
|
|
64
|
+
"@cocreate/actions": "^1.4.1",
|
|
65
|
+
"@cocreate/crud-client": "^1.6.2",
|
|
66
|
+
"@cocreate/docs": "^1.3.1",
|
|
67
|
+
"@cocreate/elements": "^1.7.3",
|
|
68
68
|
"mongodb": "^4.4.0"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/src/client.js
CHANGED
|
@@ -30,14 +30,11 @@ const CoCreateOrganization = {
|
|
|
30
30
|
}
|
|
31
31
|
data[name] = value;
|
|
32
32
|
});
|
|
33
|
-
const room = config.organization_id;
|
|
34
33
|
|
|
35
34
|
crud.send('createOrg', {
|
|
36
|
-
apiKey: config.apiKey,
|
|
37
|
-
organization_id: config.organization_id,
|
|
38
35
|
collection: 'organizations',
|
|
39
36
|
data: data
|
|
40
|
-
}
|
|
37
|
+
});
|
|
41
38
|
},
|
|
42
39
|
|
|
43
40
|
setDocumentId: function(collection, id) {
|
|
@@ -53,9 +50,63 @@ const CoCreateOrganization = {
|
|
|
53
50
|
});
|
|
54
51
|
}
|
|
55
52
|
},
|
|
53
|
+
|
|
54
|
+
deleteOrg: async function(btn) {
|
|
55
|
+
const { collection, document_id } = crud.getAttr(btn);
|
|
56
|
+
const organization_id = document_id;
|
|
57
|
+
|
|
58
|
+
if(crud.checkAttrValue(collection) && crud.checkAttrValue(document_id)) {
|
|
59
|
+
|
|
60
|
+
crud.send('deleteOrg', {
|
|
61
|
+
collection,
|
|
62
|
+
document_id,
|
|
63
|
+
data: {
|
|
64
|
+
organization_id,
|
|
65
|
+
},
|
|
66
|
+
'metadata': 'deleteOrg-action'
|
|
67
|
+
}).then(response => {
|
|
68
|
+
|
|
69
|
+
// ToDo: replace with custom event
|
|
70
|
+
document.dispatchEvent(new CustomEvent('deletedOrg', {
|
|
71
|
+
detail: {}
|
|
72
|
+
}));
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
deleteOrgs: async function(btn) {
|
|
78
|
+
const collection = btn.getAttribute('collection');
|
|
79
|
+
if(crud.checkAttrValue(collection)) {
|
|
80
|
+
const dataTemplateid = btn.getAttribute('template_id');
|
|
81
|
+
if(!dataTemplateid) return;
|
|
82
|
+
|
|
83
|
+
const selectedEls = document.querySelectorAll(`.selected[templateid="${dataTemplateid}"]`);
|
|
84
|
+
|
|
85
|
+
selectedEls.forEach((el) => {
|
|
86
|
+
const document_id = el.getAttribute('document_id');
|
|
87
|
+
const organization_id = document_id;
|
|
88
|
+
|
|
89
|
+
if(crud.checkAttrValue(document_id)) {
|
|
90
|
+
crud.send('deleteOrg', {
|
|
91
|
+
collection,
|
|
92
|
+
document_id,
|
|
93
|
+
data: {
|
|
94
|
+
organization_id,
|
|
95
|
+
},
|
|
96
|
+
'metadata': 'deleteOrgs-action'
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
document.dispatchEvent(new CustomEvent('deletedOrgs', {
|
|
102
|
+
detail: {}
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
56
106
|
|
|
57
107
|
};
|
|
58
108
|
|
|
109
|
+
|
|
59
110
|
action.init({
|
|
60
111
|
name: "createOrg",
|
|
61
112
|
endEvent: "createdOrg",
|
|
@@ -64,6 +115,22 @@ action.init({
|
|
|
64
115
|
},
|
|
65
116
|
});
|
|
66
117
|
|
|
118
|
+
action.init({
|
|
119
|
+
name: "deleteOrg",
|
|
120
|
+
endEvent: "deletedOrg",
|
|
121
|
+
callback: (btn, data) => {
|
|
122
|
+
CoCreateOrganization.deleteOrg(btn);
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
action.init({
|
|
127
|
+
name: "deleteOrgs",
|
|
128
|
+
endEvent: "deletedOrgs",
|
|
129
|
+
callback: (btn, data) => {
|
|
130
|
+
CoCreateOrganization.deleteOrgs(btn);
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
67
134
|
CoCreateOrganization.init();
|
|
68
135
|
|
|
69
136
|
export default CoCreateOrganization;
|
package/src/server.js
CHANGED
|
@@ -9,8 +9,12 @@ class CoCreateOrganization {
|
|
|
9
9
|
|
|
10
10
|
init() {
|
|
11
11
|
if (this.wsManager) {
|
|
12
|
-
this.wsManager.on('createOrg',
|
|
13
|
-
|
|
12
|
+
this.wsManager.on('createOrg', (socket, data, socketInfo) =>
|
|
13
|
+
this.createOrg(socket, data, socketInfo)
|
|
14
|
+
);
|
|
15
|
+
this.wsManager.on('deleteOrg', (socket, data, socketInfo) =>
|
|
16
|
+
this.deleteOrg(socket, data, socketInfo)
|
|
17
|
+
);
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
|
|
@@ -52,8 +56,32 @@ class CoCreateOrganization {
|
|
|
52
56
|
async deleteOrg(socket, data, socketInfo) {
|
|
53
57
|
const self = this;
|
|
54
58
|
if(!data.data) return;
|
|
59
|
+
const organization_id = data.data.organization_id
|
|
60
|
+
if(!organization_id || organization_id == process.env.organization_id) return;
|
|
61
|
+
if(data.organization_id != process.env.organization_id) return;
|
|
55
62
|
try{
|
|
56
|
-
|
|
63
|
+
const db = this.dbClient.db(organization_id);
|
|
64
|
+
db.dropDatabase().then(response => {
|
|
65
|
+
if (response === true){
|
|
66
|
+
process.emit('deleteOrg', organization_id)
|
|
67
|
+
|
|
68
|
+
// delete org from platformDB
|
|
69
|
+
const platformDB = self.dbClient.db(process.env.organization_id).collection(data['collection']);
|
|
70
|
+
const query = {
|
|
71
|
+
"_id": new ObjectId(organization_id)
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
platformDB.deleteOne(query, function(error, result) {
|
|
75
|
+
if (!error) {
|
|
76
|
+
let response = { ...data }
|
|
77
|
+
self.wsManager.send(socket, 'deleteOrg', response, socketInfo);
|
|
78
|
+
self.wsManager.broadcast(socket, response.namespace || response['organization_id'], response.room, 'deleteDocument', response, socketInfo);
|
|
79
|
+
} else {
|
|
80
|
+
self.wsManager.send(socket, 'ServerError', error, socketInfo);
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
})
|
|
57
85
|
}catch(error){
|
|
58
86
|
console.log('deleteOrg error', error);
|
|
59
87
|
}
|