0
votes

I have a model with properties: status and statusId where statuses can be:

StatusId & Status are described below:

  1. open

  2. processing

  3. close

  4. reject

  5. failure

What I want is if I insert or update the status of my model then statusId should automatically update accordingly.

1
use operation hooks. observe('before save') check if the payload contains status then update statusId - Mehari Mamo

1 Answers

2
votes

You can use two things to implement this scenario

  • Making use of Remote hooks for that model using Observe

<model>.observe('before save', function (ctx, next) { // check the ctx and add the necessary validations }

  • Making use of Middle ware functions if you want this functionality to be like a cross cutting concern for the whole of your app

app.remotes().before('**', (ctx, next) => { // do stuff with ctx.args.options next(); });