diff --git a/api/src/controllers/movies.ts b/api/src/controllers/movies.ts index 83f209ac..86eb0b52 100644 --- a/api/src/controllers/movies.ts +++ b/api/src/controllers/movies.ts @@ -1,5 +1,6 @@ import { type SQL, and, eq, exists, sql } from "drizzle-orm"; import { Elysia, t } from "elysia"; +import { db } from "~/db"; import { entries, entryVideoJoin, showTranslations, shows } from "~/db/schema"; import { getColumns, sqlarr } from "~/db/utils"; import { KError } from "~/models/error"; @@ -25,7 +26,6 @@ import { sortToSql, } from "~/models/utils"; import { desc } from "~/models/utils/descriptions"; -import { db } from "../db"; const movieFilters: FilterDef = { genres: { diff --git a/api/src/models/collections.ts b/api/src/models/collections.ts new file mode 100644 index 00000000..ffa94233 --- /dev/null +++ b/api/src/models/collections.ts @@ -0,0 +1,76 @@ +import { t } from "elysia"; +import type { Prettify } from "elysia/dist/types"; +import { + ExternalId, + Genre, + Image, + Resource, + SeedImage, + TranslationRecord, +} from "./utils"; + +const BaseCollection = t.Object({ + genres: t.Array(Genre), + rating: t.Nullable(t.Integer({ minimum: 0, maximum: 100 })), + startAir: t.Nullable( + t.String({ + format: "date", + descrpition: "Date of the first item of the collection", + }), + ), + endAir: t.Nullable( + t.String({ + format: "date", + descrpition: "Date of the last item of the collection", + }), + ), + + createdAt: t.String({ format: "date-time" }), + nextRefresh: t.String({ format: "date-time" }), + + externalId: ExternalId, +}); + +export const CollectionTranslation = t.Object({ + name: t.String(), + description: t.Nullable(t.String()), + tagline: t.Nullable(t.String()), + aliases: t.Array(t.String()), + tags: t.Array(t.String()), + + poster: t.Nullable(Image), + thumbnail: t.Nullable(Image), + banner: t.Nullable(Image), + logo: t.Nullable(Image), +}); + +export const Collection = t.Intersect([ + Resource(), + CollectionTranslation, + BaseCollection, +]); +export type Collection = Prettify; + +export const SeedCollection = t.Intersect([ + t.Omit(BaseCollection, ["createdAt", "nextRefresh"]), + t.Object({ + slug: t.String({ format: "slug" }), + translations: TranslationRecord( + t.Intersect([ + t.Omit(CollectionTranslation, [ + "poster", + "thumbnail", + "banner", + "logo", + ]), + t.Object({ + poster: t.Nullable(SeedImage), + thumbnail: t.Nullable(SeedImage), + banner: t.Nullable(SeedImage), + logo: t.Nullable(SeedImage), + }), + ]), + ), + }), +]); +export type SeedCollection = Prettify; diff --git a/api/src/models/movie.ts b/api/src/models/movie.ts index a6630fb7..452d6071 100644 --- a/api/src/models/movie.ts +++ b/api/src/models/movie.ts @@ -12,6 +12,7 @@ import { TranslationRecord, } from "./utils"; import { Video } from "./video"; +import { SeedCollection } from "./collections"; export const MovieStatus = t.UnionEnum(["unknown", "finished", "planned"]); export type MovieStatus = typeof MovieStatus.static; @@ -85,6 +86,7 @@ export const SeedMovie = t.Intersect([ ]), ), videos: t.Optional(t.Array(t.String({ format: "uuid" }))), + collection: t.Optional(SeedCollection), }), ]); export type SeedMovie = Prettify; diff --git a/api/src/models/serie.ts b/api/src/models/serie.ts index 7344a9c3..5a408d9b 100644 --- a/api/src/models/serie.ts +++ b/api/src/models/serie.ts @@ -7,6 +7,8 @@ import { Genre } from "./utils/genres"; import { Image, SeedImage } from "./utils/image"; import { Language, TranslationRecord } from "./utils/language"; import { Resource } from "./utils/resource"; +import { Prettify } from "~/utils"; +import { SeedCollection } from "./collections"; export const SerieStatus = t.UnionEnum([ "unknown", @@ -57,7 +59,7 @@ export const SerieTranslation = t.Object({ export type SerieTranslation = typeof SerieTranslation.static; export const Serie = t.Intersect([Resource(), SerieTranslation, BaseSerie]); -export type Serie = typeof Serie.static; +export type Serie = Prettify; export const SeedSerie = t.Intersect([ t.Omit(BaseSerie, ["createdAt", "nextRefresh"]), @@ -77,6 +79,7 @@ export const SeedSerie = t.Intersect([ seasons: t.Array(SeedSeason), entries: t.Array(SeedEntry), extras: t.Optional(t.Array(SeedExtra)), + collection: t.Optional(SeedCollection), }), ]); export type SeedSerie = typeof SeedSerie.static;