nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.04k stars 533 forks source link

Filter with OR operator #758

Open hardikdgsa opened 2 years ago

hardikdgsa commented 2 years ago

We have used this API for listing and filtering operations. it is working well. Now we want to have a filter with OR conditions, but as mentioned in the doc it does not work combined.

current URL is like this:- users?page=1&limit=10&sort[0]=createdAt,DESC&filter=id||in||462e640f-97ae-4b9e-9f8a-2f1f6f625d69&or[0]=user.firstName||$contL||Maira&or[1]=user.lastName||$contL||Maria&or[2]=user.email||$contL||Maria&or[3]=user.phone||$contL||Maria

In the above URL, it is not taking the filter in the result. The desired condition is: id=11 AND (firstName= ABC or Lastname = ABC or email= ABC). However, It is showing all the records matching the OR condition. If we don't add or condition, the filter is working fine. Do we have any option like we can use multiple OR condition with Filter?

fricred commented 2 years ago

Hey men! i gout you XD use search

s: {"$and":[{"id":{"$in":"462e640f-97ae-4b9e-9f8a-2f1f6f625d69"}},{"$or":[{"user.firstName":{"$cont":"Maira"}},{"user.lastName":{"$cont":"Maria"}},{"user.email":{"$cont":"Maria"}},{"user.phone":{"$cont":"Maria"}}]}]}