Cleanup default watchlist sort

This commit is contained in:
Zoe Roux 2025-04-07 18:17:59 +02:00
parent 880a85ff8d
commit df7d109c34
No known key found for this signature in database
2 changed files with 29 additions and 6 deletions

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"],

View File

@ -67,6 +67,21 @@ describe("Set & get watch status", () => {
});
});
it("Can filter watchlist", async () => {
let [resp, body] = await getWatchlist("me", {
filter: "watchStatus eq rewatching",
});
expectStatus(resp, body).toBe(200);
expect(body.items).toBeArrayOfSize(1);
expect(body.items[0].slug).toBe(bubble.slug);
[resp, body] = await getWatchlist("me", {
filter: "watchStatus eq completed",
});
expectStatus(resp, body).toBe(200);
expect(body.items).toBeArrayOfSize(0);
});
it("Return watchstatus in /shows", async () => {
const [resp, body] = await getShows({});
expectStatus(resp, body).toBe(200);