Skip to content

Commit

Permalink
Merge pull request #752 from podverse/develop
Browse files Browse the repository at this point in the history
Release v4.16.18
  • Loading branch information
mitchdowney committed Apr 27, 2024
2 parents 9456938 + bab3753 commit 4314494
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "podverse-api",
"version": "4.16.17",
"version": "4.16.18",
"description": "Data API, database migration scripts, and backend services for all Podverse models.",
"contributors": [
"Mitch Downey"
Expand Down
30 changes: 12 additions & 18 deletions src/lib/utility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,50 +151,45 @@ export const addOrderByToQuery = (qb, type, sort, sortDateKey, allowRandom, isFr
} else if (sort === 'live-item-start-desc') {
qb.orderBy(`liveItem.start`, descKey)
} else if (sort === 'top-past-day') {
qb.leftJoin(
qb.innerJoin(
ormStatsType,
`stats_${type}`,
`${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`,
{ timeframe: 'daily' }
)

qb.addOrderBy(`stats_${type}.play_count`, descKey)
qb.orderBy(`stats_${type}.play_count`, descKey)
} else if (sort === 'top-past-week') {
qb.leftJoin(
qb.innerJoin(
ormStatsType,
`stats_${type}`,
`${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`,
{ timeframe: 'weekly' }
)

qb.addOrderBy(`stats_${type}.play_count`, descKey)
qb.orderBy(`stats_${type}.play_count`, descKey)
} else if (sort === 'top-past-month') {
qb.leftJoin(
qb.innerJoin(
ormStatsType,
`stats_${type}`,
`${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`,
{ timeframe: 'monthly' }
)

qb.addOrderBy(`stats_${type}.play_count`, descKey)
qb.orderBy(`stats_${type}.play_count`, descKey)
} else if (sort === 'top-past-year') {
qb.leftJoin(
qb.innerJoin(
ormStatsType,
`stats_${type}`,
`${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`,
{ timeframe: 'yearly' }
)

qb.addOrderBy(`stats_${type}.play_count`, descKey)
qb.orderBy(`stats_${type}.play_count`, descKey)
} else if (sort === 'top-all-time') {
qb.leftJoin(
qb.innerJoin(
ormStatsType,
`stats_${type}`,
`${type}.id = stats_${type}.${statsParentId}_id AND stats_${type}.timeframe = :timeframe`,
{ timeframe: 'all_time' }
)

qb.addOrderBy(`stats_${type}.play_count`, descKey)
qb.orderBy(`stats_${type}.play_count`, descKey)
} else if (sort === 'most-recent') {
qb.orderBy(`${type}.${sortDateKey}`, descKey)
} else if (sort === 'oldest') {
Expand All @@ -210,14 +205,13 @@ export const addOrderByToQuery = (qb, type, sort, sortDateKey, allowRandom, isFr
} else if (sort === 'episode-number-asc') {
qb.orderBy(`${type}.itunesEpisode`, ascKey)
} else {
qb.leftJoin(
qb.innerJoin(
ormStatsType,
`stats_${type}`,
`${type}.id = stats_${type}.${type}_id AND stats_${type}.timeframe = :timeframe`,
{ timeframe: 'weekly' }
)

qb.addOrderBy(`stats_${type}.play_count`, descKey)
qb.orderBy(`stats_${type}.play_count`, descKey)
}

return qb
Expand Down

0 comments on commit 4314494

Please sign in to comment.