diff --git a/backend/ResQueue/ResQueue/Endpoints/QueueEndpoints.cs b/backend/ResQueue/ResQueue/Endpoints/QueueEndpoints.cs index 7bc9464..19521f6 100644 --- a/backend/ResQueue/ResQueue/Endpoints/QueueEndpoints.cs +++ b/backend/ResQueue/ResQueue/Endpoints/QueueEndpoints.cs @@ -71,7 +71,7 @@ public static void MapQueueEndpoints(this IEndpointRouteBuilder routes) search = search.Trim(); sortField = new[] { - "name", "synced", "messages" + "inbox", "name", "messages" }.Contains(sortField) ? sortField : null; @@ -113,8 +113,15 @@ public static void MapQueueEndpoints(this IEndpointRouteBuilder routes) if (sortField is not null && sortOrder is not null) { var secondarySort = sortOrder == 1 - ? Builders.Sort.Ascending($"RawData.{sortField}") - : Builders.Sort.Descending($"RawData.{sortField}"); + ? Builders.Sort.Ascending(x => x.RawData[sortField]) + : Builders.Sort.Descending(x => x.RawData[sortField]); + + if (sortField.Equals("inbox", StringComparison.CurrentCultureIgnoreCase)) + { + secondarySort = sortOrder == 1 + ? Builders.Sort.Ascending(x => x.TotalMessages) + : Builders.Sort.Descending(x => x.TotalMessages); + } sort = Builders.Sort.Combine(sort, secondarySort); }