From b9c022f614352cc7d9b8ab64fcd35ca01c9d2cc0 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 25 Jan 2025 16:38:32 +0100 Subject: [PATCH] Add seed entry types --- api/src/models/entry/episode.ts | 16 +++++++++++--- api/src/models/entry/extra.ts | 2 +- api/src/models/entry/index.ts | 12 +++++++++- api/src/models/entry/movie-entry.ts | 32 ++++++++++++++++++++++----- api/src/models/entry/special.ts | 16 +++++++++++--- api/src/models/entry/unknown-entry.ts | 2 +- 6 files changed, 65 insertions(+), 15 deletions(-) diff --git a/api/src/models/entry/episode.ts b/api/src/models/entry/episode.ts index bd8dea2a..602a2816 100644 --- a/api/src/models/entry/episode.ts +++ b/api/src/models/entry/episode.ts @@ -1,7 +1,6 @@ import { t } from "elysia"; -import { EpisodeId } from "../utils/external-id"; -import { Resource } from "../utils/resource"; import { BaseEntry, EntryTranslation } from "./base-entry"; +import { EpisodeId, SeedImage, TranslationRecord, Resource } from "../utils"; export const BaseEpisode = t.Intersect([ BaseEntry, @@ -14,5 +13,16 @@ export const BaseEpisode = t.Intersect([ }), ]); -export const Episode = t.Intersect([Resource, BaseEpisode, EntryTranslation]); +export const Episode = t.Intersect([Resource(), BaseEpisode, EntryTranslation]); export type Episode = typeof Episode.static; + +export const SeedEpisode = t.Intersect([ + BaseEpisode, + t.Omit(BaseEntry, ["thumbnail", "createdAt", "nextRefresh"]), + t.Object({ + thumbnail: t.Nullable(SeedImage), + translations: TranslationRecord(EntryTranslation), + videos: t.Optional(t.Array(t.String({ format: "uuid" }))), + }), +]); +export type SeedEpisode = typeof SeedEpisode.static; diff --git a/api/src/models/entry/extra.ts b/api/src/models/entry/extra.ts index b6196de4..a0667413 100644 --- a/api/src/models/entry/extra.ts +++ b/api/src/models/entry/extra.ts @@ -31,5 +31,5 @@ export const BaseExtra = t.Intersect( }, ); -export const Extra = t.Intersect([Resource, BaseExtra, EntryTranslation]); +export const Extra = t.Intersect([Resource(), BaseExtra, EntryTranslation]); export type Extra = typeof Extra.static; diff --git a/api/src/models/entry/index.ts b/api/src/models/entry/index.ts index 1df97a0b..72b5bb43 100644 --- a/api/src/models/entry/index.ts +++ b/api/src/models/entry/index.ts @@ -1,9 +1,19 @@ import { t } from "elysia"; -import { Episode, MovieEntry, Special } from "../entry"; +import { + Episode, + SeedEpisode, + MovieEntry, + SeedMovieEntry, + Special, + SeedSpecial, +} from "../entry"; export const Entry = t.Union([Episode, MovieEntry, Special]); export type Entry = typeof Entry.static; +export const SeedEntry = t.Union([SeedEpisode, SeedMovieEntry, SeedSpecial]); +export type SeedEntry = typeof Entry.static; + export * from "./episode"; export * from "./movie-entry"; export * from "./special"; diff --git a/api/src/models/entry/movie-entry.ts b/api/src/models/entry/movie-entry.ts index 205c88ef..643928e1 100644 --- a/api/src/models/entry/movie-entry.ts +++ b/api/src/models/entry/movie-entry.ts @@ -1,13 +1,17 @@ import { t } from "elysia"; import { comment } from "../../utils"; -import { ExternalId } from "../utils/external-id"; -import { Image } from "../utils/image"; -import { Resource } from "../utils/resource"; import { BaseEntry, EntryTranslation } from "./base-entry"; +import { + Resource, + Image, + SeedImage, + ExternalId, + TranslationRecord, +} from "../utils"; export const BaseMovieEntry = t.Intersect( [ - t.Omit(BaseEntry, ["thumbnail"]), + BaseEntry, t.Object({ kind: t.Literal("movie"), order: t.Number({ @@ -29,13 +33,29 @@ export const MovieEntryTranslation = t.Intersect([ EntryTranslation, t.Object({ tagline: t.Nullable(t.String()), - thumbnail: t.Nullable(Image), + poster: t.Nullable(Image), }), ]); export const MovieEntry = t.Intersect([ - Resource, + Resource(), BaseMovieEntry, MovieEntryTranslation, ]); export type MovieEntry = typeof MovieEntry.static; + +export const SeedMovieEntry = t.Intersect([ + BaseMovieEntry, + t.Omit(BaseEntry, ["thumbnail", "createdAt", "nextRefresh"]), + t.Object({ + thumbnail: t.Nullable(SeedImage), + translations: TranslationRecord( + t.Intersect([ + t.Omit(MovieEntryTranslation, ["poster"]), + t.Object({ poster: t.Nullable(SeedImage) }), + ]), + ), + videos: t.Optional(t.Array(t.String({ format: "uuid" }))), + }), +]); +export type SeedMovieEntry = typeof SeedMovieEntry.static; diff --git a/api/src/models/entry/special.ts b/api/src/models/entry/special.ts index bb1898d2..d7527f41 100644 --- a/api/src/models/entry/special.ts +++ b/api/src/models/entry/special.ts @@ -1,8 +1,7 @@ import { t } from "elysia"; import { comment } from "../../utils"; -import { EpisodeId } from "../utils/external-id"; -import { Resource } from "../utils/resource"; import { BaseEntry, EntryTranslation } from "./base-entry"; +import { EpisodeId, Resource, SeedImage, TranslationRecord } from "../utils"; export const BaseSpecial = t.Intersect( [ @@ -25,5 +24,16 @@ export const BaseSpecial = t.Intersect( }, ); -export const Special = t.Intersect([Resource, BaseSpecial, EntryTranslation]); +export const Special = t.Intersect([Resource(), BaseSpecial, EntryTranslation]); export type Special = typeof Special.static; + +export const SeedSpecial = t.Intersect([ + BaseSpecial, + t.Omit(BaseEntry, ["thumbnail", "createdAt", "nextRefresh"]), + t.Object({ + thumbnail: t.Nullable(SeedImage), + translations: TranslationRecord(EntryTranslation), + videos: t.Optional(t.Array(t.String({ format: "uuid" }))), + }), +]); +export type SeedSpecial = typeof SeedSpecial.static; diff --git a/api/src/models/entry/unknown-entry.ts b/api/src/models/entry/unknown-entry.ts index e60d224d..383fd15b 100644 --- a/api/src/models/entry/unknown-entry.ts +++ b/api/src/models/entry/unknown-entry.ts @@ -23,7 +23,7 @@ export const UnknownEntryTranslation = t.Omit(EntryTranslation, [ ]); export const UnknownEntry = t.Intersect([ - Resource, + Resource(), BaseUnknownEntry, UnknownEntryTranslation, ]);