@live-change/user-service 0.8.82 → 0.8.84

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.
@@ -213,9 +213,11 @@ definition.processor(function(service, app) {
213
213
  if(config.ownerSetAccess || config.ownerWriteAccess) {
214
214
  const eventName = eventPrefix + modelName + 'Set'
215
215
  const actionName = 'setMy' + modelName
216
+ const identifiers = createIdentifiersProperties(extendedWith)
216
217
  service.actions[actionName] = new ActionDefinition({
217
218
  name: actionName,
218
219
  properties: {
220
+ ...identifiers,
219
221
  ...originalModelProperties
220
222
  },
221
223
  access: (params, context) => context.client.user
@@ -224,6 +226,11 @@ definition.processor(function(service, app) {
224
226
  queuedBy: (command) => command.client.user ? 'u:'+command.client.user : 's:'+command.client.session,
225
227
  waitForEvents: true,
226
228
  async execute(properties, {client, service}, emit) {
229
+ const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
230
+ for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension])
231
+ const id = owner.map(p => JSON.stringify(p)).join(':')
232
+ const entity = await modelRuntime().get(id)
233
+ if(entity) throw 'alerady_exists'
227
234
  let newObject = {}
228
235
  for(const propertyName of writeableProperties) {
229
236
  if(properties.hasOwnProperty(propertyName)) {
@@ -234,8 +241,12 @@ definition.processor(function(service, app) {
234
241
  App.computeDefaults(model, properties, { client, service } ), newObject)
235
242
  await App.validation.validate(data, validators, { source: action, action, service, app, client })
236
243
  const identifiers = {
237
- ownerType: 'user_User',
238
- owner: client.user,
244
+ contactOrUserType: 'user_User',
245
+ contactOrUser: client.user,
246
+ }
247
+ for(const key of extendedWith) {
248
+ identifiers[key+'Type'] = properties[key+'Type']
249
+ identifiers[key]=properties[key]
239
250
  }
240
251
  emit({
241
252
  type: eventName,
@@ -251,9 +262,11 @@ definition.processor(function(service, app) {
251
262
  if(config.ownerUpdateAccess || config.ownerWriteAccess) {
252
263
  const eventName = eventPrefix + modelName + 'Updated'
253
264
  const actionName = 'updateMy' + modelName
265
+ const identifiers = createIdentifiersProperties(extendedWith)
254
266
  service.actions[actionName] = new ActionDefinition({
255
267
  name: actionName,
256
268
  properties: {
269
+ ...identifiers,
257
270
  ...originalModelProperties
258
271
  },
259
272
  access: (params, context) => context.client.user
@@ -263,6 +276,7 @@ definition.processor(function(service, app) {
263
276
  waitForEvents: true,
264
277
  async execute(properties, { client, service }, emit) {
265
278
  const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
279
+ for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension])
266
280
  const id = owner.map(p => JSON.stringify(p)).join(':')
267
281
  const entity = await modelRuntime().get(id)
268
282
  if(!entity) throw 'not_found'
@@ -275,8 +289,12 @@ definition.processor(function(service, app) {
275
289
  const merged = App.utils.mergeDeep({}, entity, updateObject)
276
290
  await App.validation.validate(merged, validators, { source: action, action, service, app, client })
277
291
  const identifiers = {
278
- ownerType: 'user_User',
279
- owner: client.user,
292
+ contactOrUserType: 'user_User',
293
+ contactOrUser: client.user,
294
+ }
295
+ for(const key of extendedWith) {
296
+ identifiers[key+'Type'] = properties[key+'Type']
297
+ identifiers[key]=properties[key]
280
298
  }
281
299
  emit({
282
300
  type: eventName,
@@ -292,20 +310,29 @@ definition.processor(function(service, app) {
292
310
  if(config.ownerResetAccess || config.ownerWriteAccess) {
293
311
  const eventName = eventPrefix + modelName + 'Reset'
294
312
  const actionName = 'resetMy' + modelName
313
+ const identifiers = createIdentifiersProperties(extendedWith)
295
314
  service.actions[actionName] = new ActionDefinition({
296
315
  name: actionName,
316
+ properties: {
317
+ ...identifiers,
318
+ },
297
319
  access: (params, context) => context.client.user
298
320
  && (config.ownerResetAccess || config.ownerWriteAccess)(params, context),
299
321
  queuedBy: (command) => command.client.user ? 'u:'+command.client.user : 's:'+command.client.session,
300
322
  waitForEvents: true,
301
323
  async execute(properties, {client, service}, emit) {
302
324
  const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
325
+ for(const extension of extendedWith) owner.push(properties[extension+'Type'], properties[extension])
303
326
  const id = owner.map(p => JSON.stringify(p)).join(':')
304
327
  const entity = await modelRuntime().get(id)
305
328
  if (!entity) throw 'not_found'
306
329
  const identifiers = {
307
- ownerType: 'user_User',
308
- owner: client.user,
330
+ contactOrUserType: 'user_User',
331
+ contactOrUser: client.user,
332
+ }
333
+ for(const key of extendedWith) {
334
+ identifiers[key+'Type'] = properties[key+'Type']
335
+ identifiers[key]=properties[key]
309
336
  }
310
337
  emit({
311
338
  type: eventName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/user-service",
3
- "version": "0.8.82",
3
+ "version": "0.8.84",
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.8.82",
26
- "@live-change/relations-plugin": "^0.8.82",
25
+ "@live-change/framework": "^0.8.84",
26
+ "@live-change/relations-plugin": "^0.8.84",
27
27
  "pluralize": "^8.0.0"
28
28
  },
29
- "gitHead": "72f303118f6bb5e324c5d77473b456fc10f7ed04"
29
+ "gitHead": "53f9ddc7529c28f12cb77c4a2758b553461e46b6"
30
30
  }