From d6d3540b16f829f79da8cb6a39888c61e9de38bf Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 8 Apr 2025 23:36:46 +0200 Subject: [PATCH] Fix history percent calculation --- api/src/controllers/profiles/history.ts | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/api/src/controllers/profiles/history.ts b/api/src/controllers/profiles/history.ts index 77b7a361..441a131f 100644 --- a/api/src/controllers/profiles/history.ts +++ b/api/src/controllers/profiles/history.ts @@ -1,20 +1,9 @@ -import { - and, - count, - eq, - exists, - gt, - isNotNull, - ne, - not, - or, - sql, -} from "drizzle-orm"; +import { and, count, eq, exists, gt, isNotNull, ne, sql } from "drizzle-orm"; import { alias } from "drizzle-orm/pg-core"; import Elysia, { t } from "elysia"; import { auth, getUserInfo } from "~/auth"; import { db } from "~/db"; -import { entries, history, profiles, videos } from "~/db/schema"; +import { entries, history, profiles, shows, videos } from "~/db/schema"; import { watchlist } from "~/db/schema/watchlist"; import { coalesce, values } from "~/db/utils"; import { Entry } from "~/models/entry"; @@ -244,6 +233,11 @@ export const historyH = new Elysia({ tags: ["profiles"] }) ), ); + const showKindQ = db + .select({ k: shows.kind }) + .from(shows) + .where(eq(shows.pk, sql`excluded.show_pk`)); + await db .insert(watchlist) .select( @@ -302,7 +296,11 @@ export const historyH = new Elysia({ tags: ["profiles"] }) else ${watchlist.status} end `, - seenCount: sql`${seenCountQ}`, + seenCount: sql` + case + when ${showKindQ} = 'movie' then excluded.seen_count + else ${seenCountQ} + end`, nextEntry: sql` case when ${watchlist.status} = 'completed' then null