Hi Team,
I want to perform the action on database update or create should be done by third party API not with forestadmin.
below is the code here I commented the next() to stop automated operation perform by forestadmin. but after save it keeps loading.
axios({
url: 'http://localhost:8000/api/v1/settings',
method: 'post',
data: data,
})
.then(async (result) => {
// console.log(result);
await RecordUpdaterM.serialize(result.data)
response.send("sucess");
})
.catch((error) => {
console.log('error:', error);
});
// next();
Thanks,
Sourabh
Hi @sourabht,
Thanks for your message.
Could you tell me what route kind you’re trying to replace?
Did you try to send the result in the response?
Like:
.then(async (result) => {
response.send(await RecordUpdaterM.serialize(result.data));
})
Thanks!
Yes i tried the same but not resolved.
Is it a POST route that you are overriding?
Are you not using the RecordCreator serializer as specified in the documentation?
const { RecordCreator } = require('forest-express-mongoose');
const recordCreator = new RecordCreator(users);
...
.then(async (result) => {
response.send(await recordCreator.serialize(result.data));
Hi @anon34731316 ,
I have successfully integrated the API call using the override route.
but after getting a successful response it redirects me to the details page and there it showed me the old records. Once I will reload the list page then i can get the latest data on click on particular record. this issue coming on add and update both. below are the screen shot.
old record:
After refresh page new record:
Below are the code snippt.
router.post('/media', permissionMiddlewareCreator.create(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#create-a-record
const recordCreator = new RecordCreator(media);
const data = request.body.data.attributes;
axios({
url: 'http://localhost:8000/media',
method: 'post',
data: data,
})
.then(async (result) => {
response.send(await recordCreator.serialize(result.data));
})
.catch((error) => {
console.log('error:', error);
});
// next();
});
Thanks,
Sourabh
Hi @sourabht have you take a look on the response payload on your browser console?
In case of update record ForestAdmin need the full new record to update it.
I got the above response on update record. also i get the issue when i update this and went to the listing and again click on the particular row then getting below the page.
and i reload on same page then updated data i am able to see.
Thank you.
Sourabh
To be more explicite! You must return the updated record in your payload. Not { sucess: true }
.
1 Like
I got the solution below is the code.
response.send(await recordCreator.serialize(result.data.data));