Admin Tools: Fix sorting

This commit is contained in:
yu-i-i
2026-01-30 00:23:02 +01:00
parent 91e97dbdf2
commit ada07fb779
4 changed files with 38 additions and 30 deletions

View File

@@ -111,16 +111,23 @@ function _applyFilters(projects, filters) {
function _sortAndPaginate(projects, sort, page) {
if (
(sort.by && !['lastUpdated', 'title', 'deletedAt'].includes(sort.by)) ||
(sort.by && !['lastUpdated', 'title', 'deletedAt', 'owner'].includes(sort.by)) ||
(sort.order && !['asc', 'desc'].includes(sort.order))
) {
throw new OError('Invalid sorting criteria', { sort })
}
const sortedProjects = _.orderBy(
projects,
[sort.by || 'lastUpdated'],
[sort.order || 'desc']
)
// sorting by owner is not implemented, it is mot needed
const sortedProjects =
sort.by === 'title'
? [...projects].sort((a, b) =>
(a.name ?? '\uffff').localeCompare(b.name ?? '\uffff')
)
: _.orderBy(
projects,
[sort.by || 'lastUpdated'],
[sort.order || 'desc']
)
return sortedProjects
}