From e1b428e8ceb28972b2d04e41b0457e55145ac6dc Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 8 Apr 2025 23:37:42 +0200 Subject: [PATCH] Fix `nextEntry` calculation when adding to watchlist --- api/src/controllers/profiles/watchlist.ts | 33 +++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/api/src/controllers/profiles/watchlist.ts b/api/src/controllers/profiles/watchlist.ts index 8107eaf9..3e6df843 100644 --- a/api/src/controllers/profiles/watchlist.ts +++ b/api/src/controllers/profiles/watchlist.ts @@ -11,9 +11,11 @@ import { db } from "~/db"; import { entries, shows } from "~/db/schema"; import { watchlist } from "~/db/schema/watchlist"; import { conflictUpdateAllExcept, getColumns } from "~/db/utils"; +import { Entry } from "~/models/entry"; import { KError } from "~/models/error"; import { bubble, madeInAbyss } from "~/models/examples"; -import { Show } from "~/models/show"; +import { Movie } from "~/models/movie"; +import { Serie } from "~/models/serie"; import { AcceptLanguage, DbMetadata, @@ -60,8 +62,7 @@ async function setWatchStatus({ : 0, showPk: show.pk, nextEntry: - show.kind === "movie" && - (status.status === "watching" || status.status === "rewatching") + status.status === "watching" || status.status === "rewatching" ? sql`${firstEntryQ}` : sql`null`, lastPlayedAt: status.startedAt, @@ -172,7 +173,18 @@ export const watchlistH = new Elysia({ tags: ["profiles"] }) { additionalProperties: true }, ), response: { - 200: Page(Show), + 200: Page( + t.Union([ + t.Intersect([Movie, t.Object({ kind: t.Literal("movie") })]), + t.Intersect([ + Serie, + t.Object({ + kind: t.Literal("serie"), + nextEntry: t.Optional(t.Nullable(Entry)), + }), + ]), + ]), + ), 422: KError, }, }, @@ -224,7 +236,18 @@ export const watchlistH = new Elysia({ tags: ["profiles"] }) "accept-language": AcceptLanguage({ autoFallback: true }), }), response: { - 200: Page(Show), + 200: Page( + t.Union([ + t.Intersect([Movie, t.Object({ kind: t.Literal("movie") })]), + t.Intersect([ + Serie, + t.Object({ + kind: t.Literal("serie"), + nextEntry: t.Optional(t.Nullable(Entry)), + }), + ]), + ]), + ), 403: KError, 404: { ...KError,