diff options
author | Chocobozzz <me@florianbigard.com> | 2020-12-01 15:08:59 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-12-01 15:08:59 +0100 |
commit | 49cff3a4c950b22ae13f345dc4eab803d96a236e (patch) | |
tree | cd918676792834b6cfaee70c582249496320ddd1 /server/models/utils.ts | |
parent | 15feebd97ab5291f81b2a8cdcb16a8e4f4c5aa69 (diff) | |
download | PeerTube-49cff3a4c950b22ae13f345dc4eab803d96a236e.tar.gz PeerTube-49cff3a4c950b22ae13f345dc4eab803d96a236e.tar.zst PeerTube-49cff3a4c950b22ae13f345dc4eab803d96a236e.zip |
Keep displayName as valid playlist sort
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r-- | server/models/utils.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts index 6e5522346..a06d57831 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { literal, Op, OrderItem } from 'sequelize' | ||
1 | import { Model, Sequelize } from 'sequelize-typescript' | 2 | import { Model, Sequelize } from 'sequelize-typescript' |
2 | import validator from 'validator' | ||
3 | import { Col } from 'sequelize/types/lib/utils' | 3 | import { Col } from 'sequelize/types/lib/utils' |
4 | import { literal, OrderItem, Op } from 'sequelize' | 4 | import validator from 'validator' |
5 | 5 | ||
6 | type SortType = { sortModel: string, sortValue: string } | 6 | type SortType = { sortModel: string, sortValue: string } |
7 | 7 | ||
@@ -22,6 +22,16 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt | |||
22 | return [ [ finalField, direction ], lastSort ] | 22 | return [ [ finalField, direction ], lastSort ] |
23 | } | 23 | } |
24 | 24 | ||
25 | function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { | ||
26 | const { direction, field } = buildDirectionAndField(value) | ||
27 | |||
28 | if (field.toLowerCase() === 'name') { | ||
29 | return [ [ 'displayName', direction ], lastSort ] | ||
30 | } | ||
31 | |||
32 | return getSort(value, lastSort) | ||
33 | } | ||
34 | |||
25 | function getCommentSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { | 35 | function getCommentSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { |
26 | const { direction, field } = buildDirectionAndField(value) | 36 | const { direction, field } = buildDirectionAndField(value) |
27 | 37 | ||
@@ -227,6 +237,7 @@ export { | |||
227 | buildBlockedAccountSQL, | 237 | buildBlockedAccountSQL, |
228 | buildBlockedAccountSQLOptimized, | 238 | buildBlockedAccountSQLOptimized, |
229 | buildLocalActorIdsIn, | 239 | buildLocalActorIdsIn, |
240 | getPlaylistSort, | ||
230 | SortType, | 241 | SortType, |
231 | buildLocalAccountIdsIn, | 242 | buildLocalAccountIdsIn, |
232 | getSort, | 243 | getSort, |