Add a custom filter to the request query


#1

I want to be able to control what filters the user can use?
For example, I have a Users table and a Codes table. I don’t want the user to use the filter provided by dreamfactory and filter the way he wants. Instead, I want to restrict the queries that he can make.

For example, let us assume that I want to retrieve all the codes belonging to userID=1.
Now I can do this using:
?filter=userID%3D=1 (userID=1 as a filter). Instead, I want the user to use a URL like this:
?userID=1 and I will take care of passing the filter to the API.

To do that, I added this server-side script in the db.Codes.get.pre_process where it does the following:

userID = event.request.query.userID;
event.request.query.filter = "userID="+userID;

Now if I print out the “event.request.query.filter” here in the script, it shows the correct string, but it is not working! The API returns all the records as if no filter was added.

Can you please help?


#2

To affect the filter you need to change event.request.body.filter. I will log this as an issue. Even if by design it is confusing.

event.request.body.filter = “userID=”+userID;