yaml-admin-api 0.0.93 → 0.0.95

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml-admin-api",
3
- "version": "0.0.93",
3
+ "version": "0.0.95",
4
4
  "license": "MIT",
5
5
  "description": "YAML Admin API package",
6
6
  "type": "commonjs",
@@ -450,13 +450,20 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
450
450
 
451
451
  var r = await db.collection(collection_name).insertOne(entity);
452
452
  //Custom Create Tail Start
453
- if(options?.listener?.entityCreated)
453
+ if(options?.listener?.entityCreated) {
454
+ let passwordField = yml_entity.fields.find(f => f.type == 'password')
455
+ if(passwordField)
456
+ entity[passwordField.name] = req.body[passwordField.name]
454
457
  await options.listener.entityCreated(db, entity_name, entity)
458
+ }
455
459
  //Custom Create Tail End
456
460
 
457
461
  const generatedId = entityId || r.insertedId
458
462
  entity.id = (key_field.type == 'objectId') ? generatedId?.toString() : generatedId;
459
-
463
+ let passwordField = yml_entity.fields.find(f => f.type == 'password')
464
+ if(passwordField)
465
+ delete entity[passwordField.name]
466
+
460
467
  res.json(entity);
461
468
  }));
462
469
 
@@ -471,7 +478,6 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
471
478
  if (entity[key_field.name] !== undefined)
472
479
  delete entity[key_field.name]
473
480
 
474
-
475
481
  //Custom Create Start
476
482
 
477
483
  //Custom Create End
@@ -496,12 +502,22 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
496
502
  await db.collection(collection_name).updateOne(f, { $set: entity });
497
503
 
498
504
  //Custom Create Tail Start
499
- if(options?.listener?.entityUpdated)
500
- await options.listener.entityUpdated(db, entity_name, entity)
505
+ if(options?.listener?.entityUpdated) {
506
+ let entityWithId = { ...entity }
507
+ entityWithId[key_field.name] = entityId
508
+
509
+ let passwordField = yml_entity.fields.find(f => f.type == 'password')
510
+ if(passwordField && req.body[passwordField.name])
511
+ entityWithId[passwordField.name] = req.body[passwordField.name]
512
+ await options.listener.entityUpdated(db, entity_name, entityWithId)
513
+ }
501
514
  //Custom Create Tail End
502
515
 
503
516
  // Ensure React-Admin receives an `id` in the response
504
517
  entity.id = (key_field.type == 'objectId') ? entityId?.toString() : entityId
518
+ let passwordField = yml_entity.fields.find(f => f.type == 'password')
519
+ if(passwordField)
520
+ delete entity[passwordField.name]
505
521
 
506
522
  res.json(entity);
507
523
  }));