Create elysia schemas for movies

This commit is contained in:
Zoe Roux 2024-11-01 21:46:34 +01:00
parent 4c91462b05
commit 908e06c88f
No known key found for this signature in database
4 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import { t } from "elysia";
export const ExternalId = t.Record(
t.String(),
t.Object({
dataId: t.String(),
link: t.Nullable(t.String({ format: "uri" })),
}),
);
export type ExternalId = typeof ExternalId.static;

10
api/src/models/image.ts Normal file
View File

@ -0,0 +1,10 @@
import { t } from "elysia";
export const Image = t.Object({
source: t.String({ format: "uri" }),
blurhash: t.String(),
low: t.String({ format: "uri" }),
medium: t.String({ format: "uri" }),
high: t.String({ format: "uri" }),
});
export type Image = typeof Image.static;

42
api/src/models/movie.ts Normal file
View File

@ -0,0 +1,42 @@
import { t } from "elysia";
import { Genre, ShowStatus } from "./show";
import { Image } from "./image";
import { ExternalId } from "./external-id";
export const Movie = 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()),
genres: t.Array(Genre),
rating: t.Nullable(t.Number({ minimum: 0, maximum: 100 })),
status: ShowStatus,
airDate: t.Nullable(t.Date()),
originalLanguage: t.Nullable(t.String()),
trailerUrl: t.Nullable(t.String()),
poster: t.Nullable(Image),
thumbnail: t.Nullable(Image),
banner: t.Nullable(Image),
logo: t.Nullable(Image),
// this is a datetime, not just a date.
createdAt: t.Date(),
nextRefresh: t.Date(),
externalId: ExternalId,
});
export type Movie = typeof Movie.static;
// Movie.examples = [{
// slug: "bubble",
// title: "Bubble",
// tagline: "Is she a calamity or a blessing?",
// description: " In an abandoned Tokyo overrun by bubbles and gravitational abnormalities, one gifted young man has a fateful meeting with a mysterious girl. ",
// }]

36
api/src/models/show.ts Normal file
View File

@ -0,0 +1,36 @@
import { t } from "elysia";
export const ShowStatus = t.UnionEnum([
"unknown",
"finished",
"airing",
"planned",
]);
export type ShowStatus = typeof ShowStatus.static;
export const Genre = t.UnionEnum([
"action",
"adventure",
"animation",
"comedy",
"crime",
"documentary",
"drama",
"family",
"fantasy",
"history",
"horror",
"music",
"mystery",
"romance",
"science-fiction",
"thriller",
"war",
"western",
"kids",
"reality",
"politics",
"soap",
"talk",
]);
export type Genre = typeof Genre.static;