How to do an action AFTER a PUT update on a document?

Hi there,

When I update one document (a user for instance), I need to update also this user to a third party service.
In this regard, I wrote something like that

// Update a User
router.put('/user/:recordId', permissionMiddlewareCreator.update(), async (request, response, next) => {
  // Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#update-a-record
  if (!request.params.recordId) return next();
  const user = await UserObject.findById(request.params.recordId);
  await thirdparty.updateUser(user);
  next();
});

but the user here is the one BEFORE the update, and I need the one AFTER, how can I do ?

I tried to look for an answer in the previous topics, but couldn’t find any…

thanks !

Hey (again :slight_smile: ) @arnaudambro,

We have some documentation explaining the exact code triggered when doing an update (And all the other routes as well) here.

  const recordUpdater = new RecordUpdater(companies);
  recordUpdater.deserialize(request.body)
    .then(recordToUpdate => recordUpdater.update(recordToUpdate, request.params.recordId))
    // The next promise receives as parameter the updated record 
    // You should be able to use `thirdparty.updateUser(record)` here
    .then(record => recordUpdater.serialize(record))
    .then(recordSerialized => response.send(recordSerialized))
    .catch(next);

Let me know if that helps!