@live-change/user-service 0.9.197 → 0.9.199
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/contactOrUserItem.js +26 -4
- package/contactOrUserProperty.js +14 -4
- package/package.json +4 -4
- package/sessionOrUserItem.js +34 -12
- package/sessionOrUserProperty.js +18 -5
- package/userItem.js +26 -4
- package/userProperty.js +12 -3
package/contactOrUserItem.js
CHANGED
|
@@ -115,8 +115,11 @@ definition.processor(function(service, app) {
|
|
|
115
115
|
}
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
+
if (!model.ownerCrud) model.ownerCrud = {}
|
|
119
|
+
|
|
118
120
|
if(config.ownerReadAccess) {
|
|
119
121
|
const viewName = 'my' + pluralize(modelName)
|
|
122
|
+
model.ownerCrud.range ??= viewName
|
|
120
123
|
service.views[viewName] = new ViewDefinition({
|
|
121
124
|
name: viewName,
|
|
122
125
|
access(params, context) {
|
|
@@ -154,6 +157,7 @@ definition.processor(function(service, app) {
|
|
|
154
157
|
name: actionName,
|
|
155
158
|
access: (params, context) => context.client.user
|
|
156
159
|
&& (config.ownerCreateAccess || config.ownerWriteAccess)(params,context),
|
|
160
|
+
skipValidation: true,
|
|
157
161
|
properties: {
|
|
158
162
|
...originalModelProperties,
|
|
159
163
|
[modelPropertyName]: {
|
|
@@ -171,15 +175,28 @@ definition.processor(function(service, app) {
|
|
|
171
175
|
ownerType: 'user_User',
|
|
172
176
|
owner: client.user,
|
|
173
177
|
}
|
|
178
|
+
let newObject = {}
|
|
179
|
+
for(const propertyName of writeableProperties) {
|
|
180
|
+
if(properties.hasOwnProperty(propertyName)) {
|
|
181
|
+
newObject[propertyName] = properties[propertyName]
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const data = App.utils.mergeDeep({},
|
|
185
|
+
App.computeDefaults(model, properties, { client, service }), newObject)
|
|
186
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
187
|
+
{ source: action, action, service, app, client })
|
|
174
188
|
emit({
|
|
175
189
|
type: eventName,
|
|
176
190
|
[modelPropertyName]: id,
|
|
177
191
|
identifiers,
|
|
178
|
-
data
|
|
192
|
+
data
|
|
179
193
|
})
|
|
180
194
|
return id
|
|
181
195
|
}
|
|
182
196
|
})
|
|
197
|
+
model.ownerCrud.create ??= actionName
|
|
198
|
+
const action = service.actions[actionName]
|
|
199
|
+
const validators = App.validation.getValidators(action, service, action)
|
|
183
200
|
}
|
|
184
201
|
if(config.ownerUpdateAccess || config.ownerWriteAccess) {
|
|
185
202
|
const eventName = modelName + 'Updated'
|
|
@@ -210,8 +227,6 @@ definition.processor(function(service, app) {
|
|
|
210
227
|
updateObject[propertyName] = properties[propertyName]
|
|
211
228
|
}
|
|
212
229
|
}
|
|
213
|
-
const merged = App.utils.mergeDeep({}, entity, updateObject)
|
|
214
|
-
await App.validation.validate(merged, validators, { source: action, action, service, app, client })
|
|
215
230
|
const identifiers = client.user ? {
|
|
216
231
|
ownerType: 'user_User',
|
|
217
232
|
owner: client.user,
|
|
@@ -219,14 +234,20 @@ definition.processor(function(service, app) {
|
|
|
219
234
|
ownerType: 'session_Session',
|
|
220
235
|
owner: client.session,
|
|
221
236
|
}
|
|
237
|
+
const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
238
|
+
const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
|
|
239
|
+
const merged = App.utils.mergeDeep({}, entity, data)
|
|
240
|
+
await App.validation.validate({ ...identifiers, ...merged, [modelPropertyName]: entity.id }, validators,
|
|
241
|
+
{ source: action, action, service, app, client })
|
|
222
242
|
emit({
|
|
223
243
|
type: eventName,
|
|
224
244
|
[modelPropertyName]: entity.id,
|
|
225
245
|
identifiers,
|
|
226
|
-
data
|
|
246
|
+
data
|
|
227
247
|
})
|
|
228
248
|
}
|
|
229
249
|
})
|
|
250
|
+
model.ownerCrud.update ??= actionName
|
|
230
251
|
const action = service.actions[actionName]
|
|
231
252
|
const validators = App.validation.getValidators(action, service, action)
|
|
232
253
|
}
|
|
@@ -265,6 +286,7 @@ definition.processor(function(service, app) {
|
|
|
265
286
|
})
|
|
266
287
|
}
|
|
267
288
|
})
|
|
289
|
+
model.ownerCrud.delete ??= actionName
|
|
268
290
|
}
|
|
269
291
|
}
|
|
270
292
|
}
|
package/contactOrUserProperty.js
CHANGED
|
@@ -142,8 +142,11 @@ definition.processor(function(service, app) {
|
|
|
142
142
|
}
|
|
143
143
|
})
|
|
144
144
|
|
|
145
|
+
if (!model.ownerCrud) model.ownerCrud = {}
|
|
146
|
+
|
|
145
147
|
if(config.ownerReadAccess) { // single item view
|
|
146
148
|
const viewName = 'my' + modelName
|
|
149
|
+
model.ownerCrud.read ??= viewName
|
|
147
150
|
const identifiers = createIdentifiersProperties(extendedWith)
|
|
148
151
|
service.views[viewName] = new ViewDefinition({
|
|
149
152
|
name: viewName,
|
|
@@ -241,7 +244,6 @@ definition.processor(function(service, app) {
|
|
|
241
244
|
}
|
|
242
245
|
const data = App.utils.mergeDeep({},
|
|
243
246
|
App.computeDefaults(model, properties, { client, service } ), newObject)
|
|
244
|
-
await App.validation.validate(data, validators, { source: action, action, service, app, client })
|
|
245
247
|
const identifiers = {
|
|
246
248
|
contactOrUserType: 'user_User',
|
|
247
249
|
contactOrUser: client.user,
|
|
@@ -250,6 +252,8 @@ definition.processor(function(service, app) {
|
|
|
250
252
|
identifiers[key+'Type'] = properties[key+'Type']
|
|
251
253
|
identifiers[key]=properties[key]
|
|
252
254
|
}
|
|
255
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
256
|
+
{ source: action, action, service, app, client })
|
|
253
257
|
emit({
|
|
254
258
|
type: eventName,
|
|
255
259
|
identifiers,
|
|
@@ -257,6 +261,7 @@ definition.processor(function(service, app) {
|
|
|
257
261
|
})
|
|
258
262
|
}
|
|
259
263
|
})
|
|
264
|
+
model.ownerCrud.create ??= actionName
|
|
260
265
|
const action = service.actions[actionName]
|
|
261
266
|
const validators = App.validation.getValidators(action, service, action)
|
|
262
267
|
}
|
|
@@ -288,8 +293,6 @@ definition.processor(function(service, app) {
|
|
|
288
293
|
updateObject[propertyName] = properties[propertyName]
|
|
289
294
|
}
|
|
290
295
|
}
|
|
291
|
-
const merged = App.utils.mergeDeep({}, entity, updateObject)
|
|
292
|
-
await App.validation.validate(merged, validators, { source: action, action, service, app, client })
|
|
293
296
|
const identifiers = {
|
|
294
297
|
contactOrUserType: 'user_User',
|
|
295
298
|
contactOrUser: client.user,
|
|
@@ -298,13 +301,19 @@ definition.processor(function(service, app) {
|
|
|
298
301
|
identifiers[key+'Type'] = properties[key+'Type']
|
|
299
302
|
identifiers[key]=properties[key]
|
|
300
303
|
}
|
|
304
|
+
const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
305
|
+
const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
|
|
306
|
+
const merged = App.utils.mergeDeep({}, entity, data)
|
|
307
|
+
await App.validation.validate({ ...identifiers, ...merged }, validators,
|
|
308
|
+
{ source: action, action, service, app, client })
|
|
301
309
|
emit({
|
|
302
310
|
type: eventName,
|
|
303
311
|
identifiers,
|
|
304
|
-
data
|
|
312
|
+
data
|
|
305
313
|
})
|
|
306
314
|
}
|
|
307
315
|
})
|
|
316
|
+
model.ownerCrud.update ??= actionName
|
|
308
317
|
const action = service.actions[actionName]
|
|
309
318
|
const validators = App.validation.getValidators(action, service, action)
|
|
310
319
|
}
|
|
@@ -342,6 +351,7 @@ definition.processor(function(service, app) {
|
|
|
342
351
|
})
|
|
343
352
|
}
|
|
344
353
|
})
|
|
354
|
+
model.ownerCrud.reset ??= actionName
|
|
345
355
|
}
|
|
346
356
|
|
|
347
357
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/user-service",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.199",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.9.
|
|
26
|
-
"@live-change/relations-plugin": "^0.9.
|
|
25
|
+
"@live-change/framework": "^0.9.199",
|
|
26
|
+
"@live-change/relations-plugin": "^0.9.199",
|
|
27
27
|
"pluralize": "^8.0.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "1900043a10cf9ad49b9cc33a539fb973706de962"
|
|
30
30
|
}
|
package/sessionOrUserItem.js
CHANGED
|
@@ -37,6 +37,8 @@ definition.processor(function(service, app) {
|
|
|
37
37
|
sessionOrUserTypes: ['session_Session', 'user_User']
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
if (!model.ownerCrud) model.ownerCrud = {}
|
|
41
|
+
|
|
40
42
|
service.trigger({
|
|
41
43
|
name: 'signedIn',
|
|
42
44
|
properties: {
|
|
@@ -147,6 +149,7 @@ definition.processor(function(service, app) {
|
|
|
147
149
|
|
|
148
150
|
if(config.ownerReadAccess) {
|
|
149
151
|
const viewName = 'my' + pluralize(modelName)
|
|
152
|
+
model.ownerCrud.range ??= viewName
|
|
150
153
|
service.views[viewName] = new ViewDefinition({
|
|
151
154
|
name: viewName,
|
|
152
155
|
access(params, context) {
|
|
@@ -179,6 +182,7 @@ definition.processor(function(service, app) {
|
|
|
179
182
|
|
|
180
183
|
if(config.ownerReadAccess) {
|
|
181
184
|
const viewName = 'my' + modelName
|
|
185
|
+
model.ownerCrud.read ??= viewName
|
|
182
186
|
const propertyName = modelName[0].toLowerCase() + modelName.slice(1)
|
|
183
187
|
service.views[viewName] = new ViewDefinition({
|
|
184
188
|
name: viewName,
|
|
@@ -210,6 +214,7 @@ definition.processor(function(service, app) {
|
|
|
210
214
|
const actionName = 'createMy' + modelName
|
|
211
215
|
service.actions[actionName] = new ActionDefinition({
|
|
212
216
|
name: actionName,
|
|
217
|
+
skipValidation: true,
|
|
213
218
|
access: config.ownerCreateAccess || config.ownerWriteAccess,
|
|
214
219
|
properties: {
|
|
215
220
|
...originalModelProperties,
|
|
@@ -225,21 +230,34 @@ definition.processor(function(service, app) {
|
|
|
225
230
|
const entity = await modelRuntime().get(id)
|
|
226
231
|
if(entity) throw app.logicError("exists")
|
|
227
232
|
const identifiers = client.user ? {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
233
|
+
sessionOrUserType: 'user_User',
|
|
234
|
+
sessionOrUser: client.user,
|
|
235
|
+
} : {
|
|
236
|
+
sessionOrUserType: 'session_Session',
|
|
237
|
+
sessionOrUser: client.session,
|
|
238
|
+
}
|
|
239
|
+
let newObject = {}
|
|
240
|
+
for(const propertyName of writeableProperties) {
|
|
241
|
+
if(properties.hasOwnProperty(propertyName)) {
|
|
242
|
+
newObject[propertyName] = properties[propertyName]
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const data = App.utils.mergeDeep({},
|
|
246
|
+
App.computeDefaults(model, properties, { client, service }), newObject)
|
|
247
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
248
|
+
{ source: action, action, service, app, client })
|
|
234
249
|
emit({
|
|
235
250
|
type: eventName,
|
|
236
251
|
[modelPropertyName]: id,
|
|
237
252
|
identifiers,
|
|
238
|
-
data
|
|
253
|
+
data
|
|
239
254
|
})
|
|
240
255
|
return id
|
|
241
256
|
}
|
|
242
257
|
})
|
|
258
|
+
model.ownerCrud.create ??= actionName
|
|
259
|
+
const action = service.actions[actionName]
|
|
260
|
+
const validators = App.validation.getValidators(action, service, action)
|
|
243
261
|
}
|
|
244
262
|
if(config.ownerUpdateAccess || config.ownerWriteAccess) {
|
|
245
263
|
const eventName = modelName + 'Updated'
|
|
@@ -272,10 +290,6 @@ definition.processor(function(service, app) {
|
|
|
272
290
|
updateObject[propertyName] = properties[propertyName]
|
|
273
291
|
}
|
|
274
292
|
}
|
|
275
|
-
const merged = App.utils.mergeDeep({ [modelPropertyName]: properties[modelPropertyName] },
|
|
276
|
-
entity, updateObject)
|
|
277
|
-
|
|
278
|
-
await App.validation.validate(merged, validators, { source: action, action, service, app, client })
|
|
279
293
|
const identifiers = client.user ? {
|
|
280
294
|
sessionOrUserType: 'user_User',
|
|
281
295
|
sessionOrUser: client.user,
|
|
@@ -283,14 +297,21 @@ definition.processor(function(service, app) {
|
|
|
283
297
|
sessionOrUserType: 'session_Session',
|
|
284
298
|
sessionOrUser: client.session,
|
|
285
299
|
}
|
|
300
|
+
const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
301
|
+
const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
|
|
302
|
+
const merged = App.utils.mergeDeep({ [modelPropertyName]: properties[modelPropertyName] },
|
|
303
|
+
entity, data)
|
|
304
|
+
await App.validation.validate({ ...identifiers, ...merged, [modelPropertyName]: entity.id }, validators,
|
|
305
|
+
{ source: action, action, service, app, client })
|
|
286
306
|
emit({
|
|
287
307
|
type: eventName,
|
|
288
308
|
[modelPropertyName]: entity.id,
|
|
289
309
|
identifiers,
|
|
290
|
-
data
|
|
310
|
+
data
|
|
291
311
|
})
|
|
292
312
|
}
|
|
293
313
|
})
|
|
314
|
+
model.ownerCrud.update ??= actionName
|
|
294
315
|
const action = service.actions[actionName]
|
|
295
316
|
const validators = App.validation.getValidators(action, service, action)
|
|
296
317
|
}
|
|
@@ -331,6 +352,7 @@ definition.processor(function(service, app) {
|
|
|
331
352
|
})
|
|
332
353
|
}
|
|
333
354
|
})
|
|
355
|
+
model.ownerCrud.delete ??= actionName
|
|
334
356
|
}
|
|
335
357
|
}
|
|
336
358
|
}
|
package/sessionOrUserProperty.js
CHANGED
|
@@ -157,10 +157,13 @@ definition.processor(function(service, app) {
|
|
|
157
157
|
})
|
|
158
158
|
*/
|
|
159
159
|
|
|
160
|
+
if (!model.ownerCrud) model.ownerCrud = {}
|
|
161
|
+
|
|
160
162
|
const extendedIdentifiersProperties = createIdentifiersProperties(extendedWith)
|
|
161
163
|
|
|
162
164
|
if(config.ownerReadAccess) { // single item view
|
|
163
165
|
const viewName = 'my' + modelName
|
|
166
|
+
model.ownerCrud.read ??= viewName
|
|
164
167
|
service.views[viewName] = new ViewDefinition({
|
|
165
168
|
name: viewName,
|
|
166
169
|
properties: {
|
|
@@ -187,6 +190,7 @@ definition.processor(function(service, app) {
|
|
|
187
190
|
const indexName = 'by' + (['SessionOrUser', ...combination])
|
|
188
191
|
.map(prop => prop[0].toUpperCase() + prop.slice(1))
|
|
189
192
|
const viewName = 'my' + propsUpperCase.join('And') + pluralize(modelName)
|
|
193
|
+
model.ownerCrud.range ??= viewName
|
|
190
194
|
const identifiers = createIdentifiersProperties(combination)
|
|
191
195
|
service.views[viewName] = new ViewDefinition({
|
|
192
196
|
name: viewName,
|
|
@@ -275,6 +279,7 @@ definition.processor(function(service, app) {
|
|
|
275
279
|
})
|
|
276
280
|
}
|
|
277
281
|
})
|
|
282
|
+
model.ownerCrud.create ??= actionName
|
|
278
283
|
const action = service.actions[actionName]
|
|
279
284
|
const validators = App.validation.getValidators(action, service, action)
|
|
280
285
|
}
|
|
@@ -304,8 +309,6 @@ definition.processor(function(service, app) {
|
|
|
304
309
|
updateObject[propertyName] = properties[propertyName]
|
|
305
310
|
}
|
|
306
311
|
}
|
|
307
|
-
const merged = App.utils.mergeDeep({}, entity, updateObject)
|
|
308
|
-
await App.validation.validate(merged, validators, { source: action, action, service, app, client })
|
|
309
312
|
const identifiers = client.user ? {
|
|
310
313
|
sessionOrUserType: 'user_User',
|
|
311
314
|
sessionOrUser: client.user,
|
|
@@ -317,13 +320,19 @@ definition.processor(function(service, app) {
|
|
|
317
320
|
identifiers[key+'Type'] = properties[key+'Type']
|
|
318
321
|
identifiers[key]=properties[key]
|
|
319
322
|
}
|
|
323
|
+
const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
324
|
+
const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
|
|
325
|
+
const merged = App.utils.mergeDeep({}, entity, data)
|
|
326
|
+
await App.validation.validate({ ...identifiers, ...merged }, validators,
|
|
327
|
+
{ source: action, action, service, app, client })
|
|
320
328
|
emit({
|
|
321
329
|
type: eventName,
|
|
322
330
|
identifiers,
|
|
323
|
-
data
|
|
331
|
+
data
|
|
324
332
|
})
|
|
325
333
|
}
|
|
326
334
|
})
|
|
335
|
+
model.ownerCrud.update ??= actionName
|
|
327
336
|
const action = service.actions[actionName]
|
|
328
337
|
const validators = App.validation.getValidators(action, service, action)
|
|
329
338
|
}
|
|
@@ -376,18 +385,21 @@ definition.processor(function(service, app) {
|
|
|
376
385
|
data
|
|
377
386
|
})
|
|
378
387
|
} else {
|
|
379
|
-
const
|
|
388
|
+
const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
389
|
+
const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
|
|
390
|
+
const merged = App.utils.mergeDeep({}, entity, data)
|
|
380
391
|
//console.log('V', { ...identifiers, ...merged}, validators)
|
|
381
392
|
await App.validation.validate({ ...identifiers, ...merged}, validators,
|
|
382
393
|
{ source: action, action, service, app, client })
|
|
383
394
|
emit({
|
|
384
395
|
type: updatedEventName,
|
|
385
396
|
identifiers,
|
|
386
|
-
data
|
|
397
|
+
data
|
|
387
398
|
})
|
|
388
399
|
}
|
|
389
400
|
}
|
|
390
401
|
})
|
|
402
|
+
model.ownerCrud.createOrUpdate ??= actionName
|
|
391
403
|
const action = service.actions[actionName]
|
|
392
404
|
const validators = App.validation.getValidators(action, service, action)
|
|
393
405
|
}
|
|
@@ -426,6 +438,7 @@ definition.processor(function(service, app) {
|
|
|
426
438
|
})
|
|
427
439
|
}
|
|
428
440
|
})
|
|
441
|
+
model.ownerCrud.reset ??= actionName
|
|
429
442
|
}
|
|
430
443
|
|
|
431
444
|
}
|
package/userItem.js
CHANGED
|
@@ -30,10 +30,13 @@ definition.processor(function(service, app) {
|
|
|
30
30
|
...config
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
if (!model.ownerCrud) model.ownerCrud = {}
|
|
34
|
+
|
|
33
35
|
/// TODO: delete on userDeleted trigger
|
|
34
36
|
|
|
35
37
|
if(config.userReadAccess) {
|
|
36
38
|
const viewName = 'myUser' + pluralize(modelName)
|
|
39
|
+
model.ownerCrud.range ??= viewName
|
|
37
40
|
service.views[viewName] = new ViewDefinition({
|
|
38
41
|
name: viewName,
|
|
39
42
|
access(params, context) {
|
|
@@ -66,6 +69,7 @@ definition.processor(function(service, app) {
|
|
|
66
69
|
|
|
67
70
|
if(config.userReadAccess) {
|
|
68
71
|
const viewName = 'myUser' + modelName
|
|
72
|
+
model.ownerCrud.read ??= viewName
|
|
69
73
|
service.views[viewName] = new ViewDefinition({
|
|
70
74
|
name: viewName,
|
|
71
75
|
async access(params, context) {
|
|
@@ -88,6 +92,7 @@ definition.processor(function(service, app) {
|
|
|
88
92
|
const actionName = 'createMyUser' + modelName
|
|
89
93
|
service.actions[actionName] = new ActionDefinition({
|
|
90
94
|
name: actionName,
|
|
95
|
+
skipValidation: true,
|
|
91
96
|
access: config.userCreateAccess || config.userWriteAccess,
|
|
92
97
|
properties: {
|
|
93
98
|
...originalModelProperties,
|
|
@@ -102,17 +107,30 @@ definition.processor(function(service, app) {
|
|
|
102
107
|
const id = properties[modelPropertyName] || app.generateUid()
|
|
103
108
|
const entity = await modelRuntime().get(id)
|
|
104
109
|
if(entity) throw app.logicError("exists")
|
|
110
|
+
let newObject = {}
|
|
111
|
+
for(const propertyName of writeableProperties) {
|
|
112
|
+
if(properties.hasOwnProperty(propertyName)) {
|
|
113
|
+
newObject[propertyName] = properties[propertyName]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const data = App.utils.mergeDeep({},
|
|
117
|
+
App.computeDefaults(model, properties, { client, service }), newObject)
|
|
118
|
+
await App.validation.validate(data, validators,
|
|
119
|
+
{ source: action, action, service, app, client })
|
|
105
120
|
emit({
|
|
106
121
|
type: eventName,
|
|
107
122
|
[modelPropertyName]: id,
|
|
108
123
|
identifiers: {
|
|
109
124
|
user: client.user,
|
|
110
125
|
},
|
|
111
|
-
data
|
|
126
|
+
data
|
|
112
127
|
})
|
|
113
128
|
return id
|
|
114
129
|
}
|
|
115
130
|
})
|
|
131
|
+
model.ownerCrud.create ??= actionName
|
|
132
|
+
const action = service.actions[actionName]
|
|
133
|
+
const validators = App.validation.getValidators(action, service, action)
|
|
116
134
|
}
|
|
117
135
|
if(config.userUpdateAccess || config.userWriteAccess) {
|
|
118
136
|
const eventName = modelName + 'Updated'
|
|
@@ -140,18 +158,21 @@ definition.processor(function(service, app) {
|
|
|
140
158
|
updateObject[propertyName] = properties[propertyName]
|
|
141
159
|
}
|
|
142
160
|
}
|
|
143
|
-
const
|
|
144
|
-
|
|
161
|
+
const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
162
|
+
const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
|
|
163
|
+
const merged = App.utils.mergeDeep({}, entity, data)
|
|
164
|
+
await App.validation.validate({ ...merged, [modelPropertyName]: entity.id }, validators, { source: action, action, service, app, client })
|
|
145
165
|
emit({
|
|
146
166
|
type: eventName,
|
|
147
167
|
[modelPropertyName]: entity.id,
|
|
148
168
|
identifiers: {
|
|
149
169
|
user: client.user,
|
|
150
170
|
},
|
|
151
|
-
data
|
|
171
|
+
data
|
|
152
172
|
})
|
|
153
173
|
}
|
|
154
174
|
})
|
|
175
|
+
model.ownerCrud.update ??= actionName
|
|
155
176
|
const action = service.actions[actionName]
|
|
156
177
|
const validators = App.validation.getValidators(action, service, action)
|
|
157
178
|
}
|
|
@@ -182,6 +203,7 @@ definition.processor(function(service, app) {
|
|
|
182
203
|
})
|
|
183
204
|
}
|
|
184
205
|
})
|
|
206
|
+
model.ownerCrud.delete ??= actionName
|
|
185
207
|
}
|
|
186
208
|
}
|
|
187
209
|
}
|
package/userProperty.js
CHANGED
|
@@ -30,10 +30,13 @@ definition.processor(function(service, app) {
|
|
|
30
30
|
...config
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
if (!model.ownerCrud) model.ownerCrud = {}
|
|
34
|
+
|
|
33
35
|
/// TODO: delete on userDeleted trigger
|
|
34
36
|
|
|
35
37
|
if(config.userReadAccess) {
|
|
36
38
|
const viewName = 'myUser' + modelName
|
|
39
|
+
model.ownerCrud.read ??= viewName
|
|
37
40
|
service.views[viewName] = new ViewDefinition({
|
|
38
41
|
name: viewName,
|
|
39
42
|
access(params, context) {
|
|
@@ -95,6 +98,7 @@ definition.processor(function(service, app) {
|
|
|
95
98
|
})
|
|
96
99
|
}
|
|
97
100
|
})
|
|
101
|
+
model.ownerCrud.create ??= actionName
|
|
98
102
|
const action = service.actions[actionName]
|
|
99
103
|
const validators = App.validation.getValidators(action, service, action)
|
|
100
104
|
}
|
|
@@ -120,17 +124,21 @@ definition.processor(function(service, app) {
|
|
|
120
124
|
updateObject[propertyName] = properties[propertyName]
|
|
121
125
|
}
|
|
122
126
|
}
|
|
123
|
-
const
|
|
124
|
-
|
|
127
|
+
const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
128
|
+
const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
|
|
129
|
+
const merged = App.utils.mergeDeep({}, entity, data)
|
|
130
|
+
await App.validation.validate({ user: client.user, ...merged }, validators,
|
|
131
|
+
{ source: action, action, service, app, client })
|
|
125
132
|
emit({
|
|
126
133
|
type: eventName,
|
|
127
134
|
identifiers: {
|
|
128
135
|
user: client.user
|
|
129
136
|
},
|
|
130
|
-
data
|
|
137
|
+
data
|
|
131
138
|
})
|
|
132
139
|
}
|
|
133
140
|
})
|
|
141
|
+
model.ownerCrud.update ??= actionName
|
|
134
142
|
const action = service.actions[actionName]
|
|
135
143
|
const validators = App.validation.getValidators(action, service, action)
|
|
136
144
|
}
|
|
@@ -154,6 +162,7 @@ definition.processor(function(service, app) {
|
|
|
154
162
|
})
|
|
155
163
|
}
|
|
156
164
|
})
|
|
165
|
+
model.ownerCrud.reset ??= actionName
|
|
157
166
|
}
|
|
158
167
|
|
|
159
168
|
}
|