Feature(s) impacted
override the create action of a collection.
I want to override the create action to call my backend.
Everything works except I get an error message when I call “create”.
But the data is well created and I put console.log in the code and the overrideCreate functions returns (maybe the format is wrong but I think I followed the example in the documentation)
So basically I return an array with a single element that is created. Here is my code
const overrideCreate: CreateOverrideHandler<
Schema,
'my_collection'
> = async context => {
const { data } = context;
if (data.length !== 1) {
throw new UnprocessableError('Cannot create several objects at a time');
}
const objectToCreate = data[0];
const createdObject = await post('/my-collection', {
email: objectToCreate.email,
type: objectToCreate.type,
...
}); // This works
console.log(JSON.stringify(createdObject)); // here I see my object in the logs
return [
{
id: createdObject.id,
createdAt: createdObject.createdAt,
type: createdObject.type,
name: createdObject.name,
email: createdObject.user.email,
},
];
};
The only thing a bit different as usual is that in this collection I have imported fields from the users
Collection (which is a oneToMany). I don’t think it’s the issue but we never know
collection.importField('email', { path: 'user:email', readonly: true });
After all this I get the error "Cannot read properties of undefined (reading 'type')"
comming from an external package (not from my code)
Observed behavior
The data is created but I get an error message
Expected behavior
I don’t get an error message and I’m redirected on the created data page
Context
- Project name: Azybia
- Team name: Azybia
- Environment name: Production
- Agent technology: nodejs
- Agent “@forestadmin/forest-cloud”: “1.9.17” “@forestadmin/agent”: “1.41.1”,
- Database type: postgres
- Recent changes made on your end if any: -