0

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.

Varun Sukheja
  • 6,170
  • 5
  • 51
  • 93
  • use operation hooks. observe('before save') check if the payload contains status then update statusId – mehari Dec 22 '17 at 11:23

1 Answers1

2

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(); });

Rahul Singh
  • 19,030
  • 11
  • 64
  • 86