Closed ThanhSonITNIC closed 7 months ago
Hello @ThanhSonITNIC,
Can you give me an example to reproduce this to cover this in a Unit test please ?
PostResource
- id
- title
StarResource
- id
- rate
- approved
Get total approved rate [POST] api/posts/search
{
"search": {
"aggregates": [
{
"relation": "stars",
"type": "sum",
"field": "rate",
"filters": [
{"field": "approved", "value": true}
]
}
]
}
}
It's throw an error 422 The search.aggregates.0.filters.0.field field is not valid
because no field approved
in validation list.
After debug, I see Aggregate validation fields is [id, title]
, but it should be [id, rate, approved]
I'm gonna investigate this in detail 😄
Thanks for the feedback, I did adapt your fix to the package. It's fixed and covered by a new test
Description
In PerformSearch at line 255, $resource is a relation resource https://github.com/Lomkit/laravel-rest-api/blob/460a3d231208c3ca42092d9b2bfe9b8272f8e1c2/src/Query/Traits/PerformSearch.php#L222-L231
But when validate in aggregatesRules it not a relation resource for filters validation https://github.com/Lomkit/laravel-rest-api/blob/460a3d231208c3ca42092d9b2bfe9b8272f8e1c2/src/Rules/SearchRules.php#L301-L304
So Aggregates filters not work correctly