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] 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