Search code examples
baqend

Baqend onUpdate Handler


Will doing partialupdate() cause code in a data class' onUpdate Handler to run?

I have this setup in the data class:

exports.onUpdate = function(db, obj) {
  DB.log.info(obj.ShiftID);
  db.Shifts.load(obj.ShiftID)
  .then((Shift) => {
    DB.log.info(Shift);
    if (Shift.User == db.User.me) {
      Shift.User = null;
      Shift.status = 0;
      return Shift.update();
    }
  })
};

(yes, role 2 for node has permissions to query and update the Shifts data class)

But I am getting zero logs when I make a partialupdate(). Do I need to do a real update query...load the object, modify the data, update()?

Also it seems that this code causes the partialupdate() to not run at all, but when I delete the handler, it starts working again.


Solution

  • Yes, that is currently an unimplemented feature since a partial update can't execute an onUpdate handler since there is no object which can be passed to the update handler.

    On the other hand, a partial update can't be executed directly since that will result in a security issue (since your onUpdate handler can contain validation code etc.)

    So we currently reject any partial update on a class which has an onUpdate handler because there doesn't exist a way how we can actually validate the partial update against your onUpdate code.

    We have planned that you can define an extra onPartial handler where you can take some extra steps before the partialUpdate is executed. But that handler will only get the partial update and not the object itself.