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:
  if (!request.params.recordId) return next();
  const user = await UserObject.findById(request.params.recordId);
  await thirdparty.updateUser(user);

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);
    .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))

Let me know if that helps!