Fix nextEntry calculation when adding to watchlist

This commit is contained in:
Zoe Roux 2025-04-08 23:37:42 +02:00
parent 144e08a99c
commit e1b428e8ce
No known key found for this signature in database

View File

@ -11,9 +11,11 @@ import { db } from "~/db";
import { entries, shows } from "~/db/schema"; import { entries, shows } from "~/db/schema";
import { watchlist } from "~/db/schema/watchlist"; import { watchlist } from "~/db/schema/watchlist";
import { conflictUpdateAllExcept, getColumns } from "~/db/utils"; import { conflictUpdateAllExcept, getColumns } from "~/db/utils";
import { Entry } from "~/models/entry";
import { KError } from "~/models/error"; import { KError } from "~/models/error";
import { bubble, madeInAbyss } from "~/models/examples"; import { bubble, madeInAbyss } from "~/models/examples";
import { Show } from "~/models/show"; import { Movie } from "~/models/movie";
import { Serie } from "~/models/serie";
import { import {
AcceptLanguage, AcceptLanguage,
DbMetadata, DbMetadata,
@ -60,8 +62,7 @@ async function setWatchStatus({
: 0, : 0,
showPk: show.pk, showPk: show.pk,
nextEntry: nextEntry:
show.kind === "movie" && status.status === "watching" || status.status === "rewatching"
(status.status === "watching" || status.status === "rewatching")
? sql`${firstEntryQ}` ? sql`${firstEntryQ}`
: sql`null`, : sql`null`,
lastPlayedAt: status.startedAt, lastPlayedAt: status.startedAt,
@ -172,7 +173,18 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
{ additionalProperties: true }, { additionalProperties: true },
), ),
response: { 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, 422: KError,
}, },
}, },
@ -224,7 +236,18 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
"accept-language": AcceptLanguage({ autoFallback: true }), "accept-language": AcceptLanguage({ autoFallback: true }),
}), }),
response: { 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, 403: KError,
404: { 404: {
...KError, ...KError,