Description
The GET /v1/holders?sort_order=desc endpoint always returns results in ascending order regardless of the sort_order query parameter value.
Root Cause
In components/crm/internal/adapters/mongodb/holder/holder_query.mongodb.go, the FindAll method hardcodes the sort direction:
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(bson.D{{Key: "_id", Value: 1}})
The sort is always _id: 1 (ascending). The query.SortOrder value is recorded in span attributes for tracing but is never applied to the MongoDB query options.
Expected Behavior
sort_order=asc → results sorted by _id: 1 (ascending)
sort_order=desc → results sorted by _id: -1 (descending)
Suggested Fix
sortDirection := 1
if strings.EqualFold(query.SortOrder, "desc") {
sortDirection = -1
}
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(bson.D{{Key: "_id", Value: sortDirection}})