Updating default routes

Hi,

I’m trying to update a default update route in order to call my own server after FA has handled the update

The original code looked like this:

router.put('/users/:recordId', permissionMiddlewareCreator.update(), (request, response, next) => {
  next();
});

This page “explains” how to add logic after the default behaviour:

At some point, you may want to trigger your remote logic after Forest Admin’s logic.

To achieve this, you can manually recreate next() 's behavior by using the snippets of default routes, then append your own logic.

So, using the default snippet found here, I now have this:

// Update a User
router.put('/users/:recordId', permissionMiddlewareCreator.update(), (request, response, next) => {
  const recordUpdater = new RecordUpdater(users);
  recordUpdater.deserialize(request.body)
    .then(recordToUpdate => recordUpdater.update(recordToUpdate, request.params.recordId))
    .then(record => { console.log(record); return record })
    .then(record => recordUpdater.serialize(record))
    .then(recordSerialized => response.send(recordSerialized))
    .catch(next);
});

I wanted to ensure that I still had the default behaviour, but now when I update a users I get this error at the point where the code tries to instantiate a new RecordUpdater:

[forest] :deciduous_tree::deciduous_tree::deciduous_tree: Unexpected error: Cannot read property ‘timezone’ of undefined
{
“stack”: "TypeError: Cannot read property ‘timezone’ of undefined\n at new AbstractRecordService (/Users/Tim/Development/…/forest/node_modules/forest-express/dist/services/exposed/abstract-records-service.js:20:17)\n

I’m using forest-express-sequelize v8.

Are the snippets on the documentation page out of date? How can I solve this?

Thanks,

Tim

Hi @timothyarmes :wave: according to our documentation Default routes - Documentation
there is a little error in your code.

const recordUpdater = new RecordUpdater(users);
// should be
const recordUpdater = new RecordUpdater(users, request.user, request.query);

Let me know if it fix your issue.

Hi,

Thank you, that does fix the issue!

It would be great if you could update the code on the documentation page to reflect this.

EDIT: I understand what happened, my Google search ended up on version 6 of the documentation.

Regards

Tim

Happy to hear your issue is fixed.
Can you give me the search you have execute in order to try to fix the redirection :pray: