@cocreate/crud-server 1.24.2 → 1.24.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 +14 -0
- package/package.json +1 -1
- package/src/index.js +29 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.24.4](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.24.3...v1.24.4) (2023-06-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* check if this.config ([151ab0d](https://github.com/CoCreate-app/CoCreate-crud-server/commit/151ab0d8b912c1c7b0369f596f4ae22e19831587))
|
|
7
|
+
|
|
8
|
+
## [1.24.3](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.24.2...v1.24.3) (2023-06-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* process.env.storage replaced with this.config.storage ([547d9db](https://github.com/CoCreate-app/CoCreate-crud-server/commit/547d9db0a41d0a77b6032245292b32e38b85ace0))
|
|
14
|
+
|
|
1
15
|
## [1.24.2](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.24.1...v1.24.2) (2023-06-15)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -15,9 +15,9 @@ class CoCreateCrudServer {
|
|
|
15
15
|
async init() {
|
|
16
16
|
this.config = await Config({
|
|
17
17
|
'organization_id': { prompt: 'Enter your organization_id: ' },
|
|
18
|
-
'
|
|
18
|
+
'storage': {
|
|
19
19
|
prompt: 'Enter a friendly name for the new storage: ',
|
|
20
|
-
variable:
|
|
20
|
+
variable: 'name'
|
|
21
21
|
},
|
|
22
22
|
'storage.{{name}}.provider': {
|
|
23
23
|
prompt: 'Enter the storage provider, ex mongodb: '
|
|
@@ -126,24 +126,40 @@ class CoCreateCrudServer {
|
|
|
126
126
|
async crud(socket, action, data) {
|
|
127
127
|
return new Promise(async (resolve) => {
|
|
128
128
|
try {
|
|
129
|
-
if (!data.organization_id)
|
|
129
|
+
if (!data.organization_id || !this.config)
|
|
130
130
|
return resolve()
|
|
131
|
+
if (!this.config)
|
|
132
|
+
this.config = await Config({
|
|
133
|
+
'organization_id': { prompt: 'Enter your organization_id: ' },
|
|
134
|
+
'storage': {
|
|
135
|
+
prompt: 'Enter a friendly name for the new storage: ',
|
|
136
|
+
variable: 'name'
|
|
137
|
+
},
|
|
138
|
+
'storage.{{name}}.provider': {
|
|
139
|
+
prompt: 'Enter the storage provider, ex mongodb: '
|
|
140
|
+
},
|
|
141
|
+
'storage.{{name}}.url': {
|
|
142
|
+
prompt: 'Enter the storage providers url: '
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
|
|
131
147
|
|
|
132
148
|
let storage = this.storages.get(data.organization_id)
|
|
133
149
|
if (storage === false)
|
|
134
150
|
return resolve({ storage: false, error: 'A storage or database could not be found' })
|
|
135
151
|
|
|
136
152
|
if (!storage) {
|
|
137
|
-
if (data.organization_id ===
|
|
138
|
-
storage =
|
|
153
|
+
if (data.organization_id === this.config.organization_id) {
|
|
154
|
+
storage = this.config.storage
|
|
139
155
|
if (storage)
|
|
140
|
-
this.storages.set(data.organization_id,
|
|
156
|
+
this.storages.set(data.organization_id, storage)
|
|
141
157
|
} else {
|
|
142
158
|
let organization = await this.readDocument({
|
|
143
|
-
database:
|
|
159
|
+
database: this.config.organization_id,
|
|
144
160
|
collection: 'organizations',
|
|
145
161
|
document: [{ _id: data.organization_id }],
|
|
146
|
-
organization_id:
|
|
162
|
+
organization_id: this.config.organization_id
|
|
147
163
|
})
|
|
148
164
|
if (organization && organization.document && organization.document[0])
|
|
149
165
|
organization = organization.document[0]
|
|
@@ -171,7 +187,7 @@ class CoCreateCrudServer {
|
|
|
171
187
|
if (!data.database)
|
|
172
188
|
data['database'] = data.organization_id
|
|
173
189
|
|
|
174
|
-
if (action === 'updateDocument' && data.organization_id !==
|
|
190
|
+
if (action === 'updateDocument' && data.organization_id !== this.config.organization_id) {
|
|
175
191
|
let syncKeys
|
|
176
192
|
if (data.collection === 'organizations')
|
|
177
193
|
syncKeys = ['name', 'logo', 'databases', 'host', 'apis']
|
|
@@ -180,10 +196,10 @@ class CoCreateCrudServer {
|
|
|
180
196
|
|
|
181
197
|
if (syncKeys && syncKeys.length) {
|
|
182
198
|
let platformUpdate = {
|
|
183
|
-
database:
|
|
199
|
+
database: this.config.organization_id,
|
|
184
200
|
collection: data.collection,
|
|
185
201
|
document: [{}],
|
|
186
|
-
organization_id:
|
|
202
|
+
organization_id: this.config.organization_id
|
|
187
203
|
}
|
|
188
204
|
|
|
189
205
|
let document = data.document[0] || data.document
|
|
@@ -225,10 +241,10 @@ class CoCreateCrudServer {
|
|
|
225
241
|
|
|
226
242
|
delete data.dbUrl
|
|
227
243
|
if (socket) {
|
|
228
|
-
if (data.organization_id ===
|
|
244
|
+
if (data.organization_id === this.config.organization_id && socket.config.organization_id !== data.organization_id) {
|
|
229
245
|
this.wsManager.broadcast({
|
|
230
246
|
config: {
|
|
231
|
-
organization_id:
|
|
247
|
+
organization_id: this.config.organization_id,
|
|
232
248
|
}
|
|
233
249
|
}, action, { ...data });
|
|
234
250
|
data.organization_id = socket.config.organization_id
|