diff --git a/api/src/models/examples/made-in-abyss.ts b/api/src/models/examples/made-in-abyss.ts index b9c92490..81e97ec7 100644 --- a/api/src/models/examples/made-in-abyss.ts +++ b/api/src/models/examples/made-in-abyss.ts @@ -1,15 +1,6 @@ -import type { Entry, Extra } from "../entry"; -import type { Season } from "../season"; -import type { Serie } from "../serie"; -import type { Video } from "../video"; +import type { SeedSerie } from "../seed"; -type CompleteSerie = Serie & { - seasons: Season[]; - entries: (Entry & { videos: Video[] })[]; - extras: (Extra & { video: Video })[]; -}; - -export const madeInAbyss: CompleteSerie = { +export const madeInAbyss: SeedSerie = { id: "04bcf2ac-3c09-42f6-8357-b003798f9562", slug: "made-in-abyss", name: "Made in Abyss", diff --git a/api/src/models/season.ts b/api/src/models/season.ts index 2b09c565..212ccb09 100644 --- a/api/src/models/season.ts +++ b/api/src/models/season.ts @@ -1,27 +1,36 @@ import { t } from "elysia"; import { Image } from "./utils/image"; import { SeasonId } from "./utils/external-id"; -import { madeInAbyss, registerExamples } from "./examples"; +import { Resource } from "./utils/resource"; +import { Language } from "./utils/language"; -export const Season = t.Object({ - id: t.String({ format: "uuid" }), - slug: t.String(), +export const BaseSeason = t.Object({ seasonNumber: t.Number({ minimum: 1 }), - name: t.Nullable(t.String()), - description: t.Nullable(t.String()), - startAir: t.Nullable(t.String({ format: "date" })), endAir: t.Nullable(t.String({ format: "date" })), - poster: t.Nullable(Image), - thumbnail: t.Nullable(Image), - banner: t.Nullable(Image), - createdAt: t.String({ format: "date-time" }), nextRefresh: t.String({ format: "date-time" }), externalId: SeasonId, }); + +export const SeasonTranslation = t.Object({ + name: t.Nullable(t.String()), + description: t.Nullable(t.String()), + + poster: t.Nullable(Image), + thumbnail: t.Nullable(Image), + banner: t.Nullable(Image), +}); +export type SeasonTranslation = typeof SeasonTranslation.static; + +export const Season = t.Intersect([Resource, BaseSeason, SeasonTranslation]); export type Season = typeof Season.static; -registerExamples(Season, ...madeInAbyss.seasons); +export const SeedSeason = t.Intersect([ + BaseSeason, + t.Object({ + translations: t.Record(Language(), SeasonTranslation, { minPropreties: 1 }), + }), +]); diff --git a/api/src/models/serie.ts b/api/src/models/serie.ts index a417dbb1..a5dbe3b7 100644 --- a/api/src/models/serie.ts +++ b/api/src/models/serie.ts @@ -2,8 +2,10 @@ import { t } from "elysia"; import { Genre } from "./utils/genres"; import { Image } from "./utils/image"; import { ExternalId } from "./utils/external-id"; -import { madeInAbyss , registerExamples } from "./examples"; -import { comment } from "../utils"; +import { madeInAbyss, registerExamples } from "./examples"; +import { Resource } from "./utils/resource"; +import { Language } from "./utils/language"; +import { SeedSeason } from "./season"; export const SerieStatus = t.UnionEnum([ "unknown", @@ -13,15 +15,7 @@ export const SerieStatus = t.UnionEnum([ ]); export type SerieStatus = typeof SerieStatus.static; -export const Serie = t.Object({ - id: t.String({ format: "uuid" }), - slug: t.String(), - name: t.String(), - description: t.Nullable(t.String()), - tagline: t.Nullable(t.String()), - aliases: t.Array(t.String()), - tags: t.Array(t.String()), - +export const BaseSerie = t.Object({ genres: t.Array(Genre), rating: t.Nullable(t.Number({ minimum: 0, maximum: 100 })), status: SerieStatus, @@ -35,27 +29,42 @@ export const Serie = t.Object({ startAir: t.Nullable(t.String({ format: "date" })), endAir: t.Nullable(t.String({ format: "date" })), originalLanguage: t.Nullable( - t.String({ - description: comment` - The language code this movie was made in. - This is a BCP 47 language code (the IETF Best Current Practices on Tags for Identifying Languages). - BCP 47 is also known as RFC 5646. It subsumes ISO 639 and is backward compatible with it. - `, + Language({ + description: "The language code this serie was made in.", }), ), - poster: t.Nullable(Image), - thumbnail: t.Nullable(Image), - banner: t.Nullable(Image), - logo: t.Nullable(Image), - trailerUrl: t.Nullable(t.String()), - createdAt: t.String({ format: "date-time" }), nextRefresh: t.String({ format: "date-time" }), externalId: ExternalId, }); +export const SerieTranslation = 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), + trailerUrl: t.Nullable(t.String()), +}); +export type SerieTranslation = typeof SerieTranslation.static; + +export const Serie = t.Intersect([Resource, BaseSerie, SerieTranslation]); export type Serie = typeof Serie.static; -registerExamples(Serie, madeInAbyss); +export const SeedSerie = t.Intersect([ + BaseSerie, + t.Object({ + translations: t.Record(Language(), SerieTranslation, { minProperties: 1 }), + seasons: t.Array(SeedSeason), + // entries: t.Array(SeedEntry), + // extras: t.Optional(t.Array(SeedExtra)), + }), +]); +export type SeedSerie = typeof SeedSerie.static;