mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add watch status type in movies/series
This commit is contained in:
parent
e489d0c445
commit
32cc6e7910
@ -12,6 +12,7 @@ import {
|
|||||||
studios,
|
studios,
|
||||||
videos,
|
videos,
|
||||||
} from "~/db/schema";
|
} from "~/db/schema";
|
||||||
|
import { watchlist } from "~/db/schema/watchlist";
|
||||||
import {
|
import {
|
||||||
coalesce,
|
coalesce,
|
||||||
getColumns,
|
getColumns,
|
||||||
@ -248,6 +249,12 @@ export async function getShows({
|
|||||||
)
|
)
|
||||||
.as("t");
|
.as("t");
|
||||||
|
|
||||||
|
const watchStatusQ = db
|
||||||
|
.select()
|
||||||
|
.from(watchlist)
|
||||||
|
.where(eq(watchlist.profilePk, userId))
|
||||||
|
.as("watchstatus");
|
||||||
|
|
||||||
return await db
|
return await db
|
||||||
.select({
|
.select({
|
||||||
...getColumns(shows),
|
...getColumns(shows),
|
||||||
@ -266,9 +273,12 @@ export async function getShows({
|
|||||||
logo: sql<Image>`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`,
|
logo: sql<Image>`coalesce(nullif(${shows.original}->'logo', 'null'::jsonb), ${transQ.logo})`,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
watchStatus: getColumns(watchStatusQ),
|
||||||
|
|
||||||
...buildRelations(relations, showRelations, { languages, userId }),
|
...buildRelations(relations, showRelations, { languages, userId }),
|
||||||
})
|
})
|
||||||
.from(shows)
|
.from(shows)
|
||||||
|
.leftJoin(watchStatusQ, eq(shows.pk, watchStatusQ.showPk))
|
||||||
[fallbackLanguage ? "innerJoin" : ("leftJoin" as "innerJoin")](
|
[fallbackLanguage ? "innerJoin" : ("leftJoin" as "innerJoin")](
|
||||||
transQ,
|
transQ,
|
||||||
eq(shows.pk, transQ.pk),
|
eq(shows.pk, transQ.pk),
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import {
|
import { check, integer, primaryKey, timestamp } from "drizzle-orm/pg-core";
|
||||||
check,
|
|
||||||
integer,
|
|
||||||
primaryKey,
|
|
||||||
text,
|
|
||||||
timestamp,
|
|
||||||
} from "drizzle-orm/pg-core";
|
|
||||||
import { entries } from "./entries";
|
import { entries } from "./entries";
|
||||||
import { profiles } from "./profiles";
|
import { profiles } from "./profiles";
|
||||||
import { shows } from "./shows";
|
import { shows } from "./shows";
|
||||||
@ -34,7 +28,9 @@ export const watchlist = schema.table(
|
|||||||
nextEntry: integer().references(() => entries.pk, { onDelete: "set null" }),
|
nextEntry: integer().references(() => entries.pk, { onDelete: "set null" }),
|
||||||
|
|
||||||
score: integer(),
|
score: integer(),
|
||||||
notes: text(),
|
|
||||||
|
startedAt: timestamp({ withTimezone: true, mode: "string" }),
|
||||||
|
completedAt: timestamp({ withTimezone: true, mode: "string" }),
|
||||||
|
|
||||||
createdAt: timestamp({ withTimezone: true, mode: "string" })
|
createdAt: timestamp({ withTimezone: true, mode: "string" })
|
||||||
.notNull()
|
.notNull()
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { Original } from "./utils/original";
|
import { Original } from "./utils/original";
|
||||||
import { EmbeddedVideo } from "./video";
|
import { EmbeddedVideo } from "./video";
|
||||||
|
import { WatchStatus } from "./watchlist";
|
||||||
|
|
||||||
export const MovieStatus = t.UnionEnum(["unknown", "finished", "planned"]);
|
export const MovieStatus = t.UnionEnum(["unknown", "finished", "planned"]);
|
||||||
export type MovieStatus = typeof MovieStatus.static;
|
export type MovieStatus = typeof MovieStatus.static;
|
||||||
@ -55,6 +56,7 @@ export const Movie = t.Intersect([
|
|||||||
t.Object({
|
t.Object({
|
||||||
original: Original,
|
original: Original,
|
||||||
isAvailable: t.Boolean(),
|
isAvailable: t.Boolean(),
|
||||||
|
watchStatus: t.Omit(WatchStatus, ["seenCount"]),
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
export type Movie = Prettify<typeof Movie.static>;
|
export type Movie = Prettify<typeof Movie.static>;
|
||||||
|
@ -17,6 +17,7 @@ import {
|
|||||||
TranslationRecord,
|
TranslationRecord,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { Original } from "./utils/original";
|
import { Original } from "./utils/original";
|
||||||
|
import { WatchStatus } from "./watchlist";
|
||||||
|
|
||||||
export const SerieStatus = t.UnionEnum([
|
export const SerieStatus = t.UnionEnum([
|
||||||
"unknown",
|
"unknown",
|
||||||
@ -70,6 +71,7 @@ export const Serie = t.Intersect([
|
|||||||
availableCount: t.Integer({
|
availableCount: t.Integer({
|
||||||
description: "The number of episodes that can be played right away",
|
description: "The number of episodes that can be played right away",
|
||||||
}),
|
}),
|
||||||
|
watchStatus: WatchStatus,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
export type Serie = Prettify<typeof Serie.static>;
|
export type Serie = Prettify<typeof Serie.static>;
|
||||||
|
@ -27,3 +27,22 @@ export const Progress = t.Object({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
export type Progress = typeof Progress.static;
|
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,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user