Cleanup default watchlist sort

This commit is contained in:
Zoe Roux
2025-04-07 18:17:59 +02:00
parent 880a85ff8d
commit df7d109c34
2 changed files with 29 additions and 6 deletions
+14 -6
View File
@@ -1,6 +1,12 @@
import { type SQL, and, eq, isNotNull, isNull, sql } from "drizzle-orm";
import { and, eq, isNotNull, isNull, sql } from "drizzle-orm";
import Elysia, { t } from "elysia";
import { auth, getUserInfo } from "~/auth";
import {
getShows,
showFilters,
showSort,
watchStatusQ,
} from "~/controllers/shows/logic";
import { db } from "~/db";
import { profiles, shows } from "~/db/schema";
import { watchlist } from "~/db/schema/watchlist";
@@ -19,7 +25,6 @@ import {
} from "~/models/utils";
import { desc } from "~/models/utils/descriptions";
import { MovieWatchStatus, SerieWatchStatus } from "~/models/watchlist";
import { getShows, showFilters, showSort, watchStatusQ } from "./shows/logic";
async function setWatchStatus({
show,
@@ -72,7 +77,7 @@ async function setWatchStatus({
})
.returning({
...getColumns(watchlist),
percent: sql`${watchlist.seenCount}`.as("percent"),
percent: sql<number>`${watchlist.seenCount}`.as("percent"),
});
return ret;
}
@@ -82,7 +87,10 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
.guard(
{
query: t.Object({
sort: showSort,
sort: {
...showSort,
default: ["watchStatus", ...showSort.default],
},
filter: t.Optional(Filter({ def: showFilters })),
query: t.Optional(t.String({ description: desc.query })),
limit: t.Integer({
@@ -233,7 +241,7 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
}),
body: SerieWatchStatus,
response: {
200: t.Union([SerieWatchStatus, DbMetadata]),
200: t.Intersect([SerieWatchStatus, DbMetadata]),
404: KError,
},
permissions: ["core.read"],
@@ -280,7 +288,7 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
}),
body: t.Omit(MovieWatchStatus, ["percent"]),
response: {
200: t.Union([MovieWatchStatus, DbMetadata]),
200: t.Intersect([MovieWatchStatus, DbMetadata]),
404: KError,
},
permissions: ["core.read"],