mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-23 12:19:38 +00:00
Update book progress sort queries to use NULLS LAST
This commit is contained in:
parent
c98763fc48
commit
a7534af258
1 changed files with 3 additions and 11 deletions
|
|
@ -289,19 +289,11 @@ module.exports = {
|
||||||
const nullDir = sortDesc ? 'DESC NULLS FIRST' : 'ASC NULLS LAST'
|
const nullDir = sortDesc ? 'DESC NULLS FIRST' : 'ASC NULLS LAST'
|
||||||
return [[Sequelize.literal(`CAST(\`series.bookSeries.sequence\` AS FLOAT) ${nullDir}`)]]
|
return [[Sequelize.literal(`CAST(\`series.bookSeries.sequence\` AS FLOAT) ${nullDir}`)]]
|
||||||
} else if (sortBy === 'progress') {
|
} else if (sortBy === 'progress') {
|
||||||
return [[Sequelize.literal('mediaProgresses.updatedAt'), dir]]
|
return [[Sequelize.literal(`mediaProgresses.updatedAt ${dir} NULLS LAST`)]]
|
||||||
} else if (sortBy === 'startedDate') {
|
} else if (sortBy === 'startedDate') {
|
||||||
// Sort started books first (not null), then unstarted (nulls last), then by createdAt desc
|
return [[Sequelize.literal(`mediaProgresses.createdAt ${dir} NULLS LAST`)]]
|
||||||
return [
|
|
||||||
[Sequelize.literal('(CASE WHEN mediaProgresses.createdAt IS NULL THEN 1 ELSE 0 END)'), 'ASC'],
|
|
||||||
['mediaProgresses', 'createdAt', dir]
|
|
||||||
]
|
|
||||||
} else if (sortBy === 'finishedDate') {
|
} else if (sortBy === 'finishedDate') {
|
||||||
// Sort finished books first (not null), then unfinished (nulls last), then by finishedAt desc
|
return [[Sequelize.literal(`mediaProgresses.finishedAt ${dir} NULLS LAST`)]]
|
||||||
return [
|
|
||||||
[Sequelize.literal('(CASE WHEN mediaProgresses.finishedAt IS NULL THEN 1 ELSE 0 END)'), 'ASC'],
|
|
||||||
['mediaProgresses', 'finishedAt', dir]
|
|
||||||
]
|
|
||||||
} else if (sortBy === 'random') {
|
} else if (sortBy === 'random') {
|
||||||
return [Database.sequelize.random()]
|
return [Database.sequelize.random()]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue