Hello.
I’m trying to attach a property to a model when an instance of that model is requested from the database. I’ve set up two event handlers, afterFind() and afterFindById(), in order to cover models requested individually or in bulk.
I run a calculation based on properties within the model and then attach a “status” parameter. This works great for the beforeFindById handler:
Backendless.ServerCode.Persistence.afterFindById('Person', (req, res) => {
let person = res.result;
return appendStatus(person);
});
However, when I move this over to afterFind, it doesn’t work.
Backendless.ServerCode.Persistence.afterFind('Person', (req, res) => {
return {
wtf: true
};
});
I can see in my console that this event is handled by CodeRunner…
21:08:28.850 - [*snip*] [INVOKE EVENT HANDLER] persistence.afterFind (Person)
…but I still get the standard response from Backendless.
{
"offset": 0,
"data": [...],
"nextPage": "https://api.backendless.com/v1/data/Person?pageSize=10&offset=10",
"totalObjects": 16
}
I’ve also tried returning the data in the same format as it comes back in the response:
{
"data": [
<Person with status added>
<Person with status added>
...
]
}
But this also doesn’t seem to work, I still get the standard response (and a notification that my handler was called in the CodeRunner console).
If anyone has experienced this, I’d be appreciative to hear how you solved it.
Also, to the devs: the documentation on this seems to be broken. See “Find” section on this page:
https://backendless.com/documentation/business-logic/js/bl_data_service_handler.htm
I can’t seem to find documentation on quirks like this, nor robust examples to follow that would indicate how problems like this are solved. The JS-Examples repository (https://github.com/Backendless/JS-Examples) seems to be all client-based. JS-Code-Runner repository (https://github.com/Backendless/JS-Code-Runner/blob/master/examples/handlers/) shows some examples for creation of objects, but not for finding objects. Perhaps I am missing some area of the docs that would better cover issues like this?