Define collection type

This commit is contained in:
Zoe Roux 2025-03-02 00:19:32 +01:00
parent 43465834c3
commit 01183df4e9
No known key found for this signature in database
4 changed files with 83 additions and 2 deletions

View File

@ -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: {

View File

@ -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<typeof Collection.static>;
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<typeof SeedCollection.static>;

View File

@ -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<typeof SeedMovie.static>;

View File

@ -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<typeof Serie.static>;
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;