Add watch status type in movies/series

This commit is contained in:
Zoe Roux 2025-03-11 17:16:56 +01:00
parent e489d0c445
commit 32cc6e7910
No known key found for this signature in database
5 changed files with 37 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import {
studios,
videos,
} from "~/db/schema";
import { watchlist } from "~/db/schema/watchlist";
import {
coalesce,
getColumns,
@ -248,6 +249,12 @@ export async function getShows({
)
.as("t");
const watchStatusQ = db
.select()
.from(watchlist)
.where(eq(watchlist.profilePk, userId))
.as("watchstatus");
return await db
.select({
...getColumns(shows),
@ -266,9 +273,12 @@ export async function getShows({
logo: sql<Image>`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`,
}),
watchStatus: getColumns(watchStatusQ),
...buildRelations(relations, showRelations, { languages, userId }),
})
.from(shows)
.leftJoin(watchStatusQ, eq(shows.pk, watchStatusQ.showPk))
[fallbackLanguage ? "innerJoin" : ("leftJoin" as "innerJoin")](
transQ,
eq(shows.pk, transQ.pk),

View File

@ -1,11 +1,5 @@
import { sql } from "drizzle-orm";
import {
check,
integer,
primaryKey,
text,
timestamp,
} from "drizzle-orm/pg-core";
import { check, integer, primaryKey, timestamp } from "drizzle-orm/pg-core";
import { entries } from "./entries";
import { profiles } from "./profiles";
import { shows } from "./shows";
@ -34,7 +28,9 @@ export const watchlist = schema.table(
nextEntry: integer().references(() => entries.pk, { onDelete: "set null" }),
score: integer(),
notes: text(),
startedAt: timestamp({ withTimezone: true, mode: "string" }),
completedAt: timestamp({ withTimezone: true, mode: "string" }),
createdAt: timestamp({ withTimezone: true, mode: "string" })
.notNull()

View File

@ -16,6 +16,7 @@ import {
} from "./utils";
import { Original } from "./utils/original";
import { EmbeddedVideo } from "./video";
import { WatchStatus } from "./watchlist";
export const MovieStatus = t.UnionEnum(["unknown", "finished", "planned"]);
export type MovieStatus = typeof MovieStatus.static;
@ -55,6 +56,7 @@ export const Movie = t.Intersect([
t.Object({
original: Original,
isAvailable: t.Boolean(),
watchStatus: t.Omit(WatchStatus, ["seenCount"]),
}),
]);
export type Movie = Prettify<typeof Movie.static>;

View File

@ -17,6 +17,7 @@ import {
TranslationRecord,
} from "./utils";
import { Original } from "./utils/original";
import { WatchStatus } from "./watchlist";
export const SerieStatus = t.UnionEnum([
"unknown",
@ -70,6 +71,7 @@ export const Serie = t.Intersect([
availableCount: t.Integer({
description: "The number of episodes that can be played right away",
}),
watchStatus: WatchStatus,
}),
]);
export type Serie = Prettify<typeof Serie.static>;

View File

@ -27,3 +27,22 @@ export const Progress = t.Object({
),
});
export type Progress = typeof Progress.static;
export const WatchlistStatus = t.UnionEnum([
"completed",
"watching",
"rewatching",
"dropped",
"planned",
]);
export const WatchStatus = t.Object({
status: WatchlistStatus,
score: t.Nullable(t.Integer({ minimum: 0, maximum: 100 })),
startedAt: t.Nullable(t.String({ format: "date-time" })),
completedAt: t.Nullable(t.String({ format: "date-time" })),
seenCount: t.Integer({
description: "The number of episodes you watched in this serie.",
minimum: 0,
}),
});