Test POST /videos

This commit is contained in:
Zoe Roux
2025-04-29 00:49:33 +02:00
parent 1369da1845
commit 39dcfb4418
4 changed files with 94 additions and 38 deletions
+7 -7
View File
@@ -7,11 +7,10 @@ import {
conflictUpdateAllExcept,
jsonbBuildObject,
jsonbObjectAgg,
sqlarr,
values,
} from "~/db/utils";
import { bubbleVideo } from "~/models/examples";
import { Page, isUuid } from "~/models/utils";
import { isUuid } from "~/models/utils";
import { Guesses, SeedVideo, Video } from "~/models/video";
import { comment } from "~/utils";
import { computeVideoSlug } from "./seed/insert/entries";
@@ -138,10 +137,11 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
})
.from(
values(
body.flatMap((x) =>
x.for.map((e) => ({
body.flatMap((x) => {
if (!x.for) return [];
return x.for.map((e) => ({
path: x.path,
needRendering: x.for.length > 1,
needRendering: x.for!.length > 1,
entry: {
...e,
movie:
@@ -157,8 +157,8 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] })
: { slug: e.serie }
: undefined,
},
})),
),
}));
}),
).as("j"),
)
.innerJoin(vidsI, eq(vidsI.path, sql`j.path`))
+4 -1
View File
@@ -103,7 +103,10 @@ export const nullif = <T>(val: SQL<T> | Column, eq: SQL<T>) => {
return sql<T>`nullif(${val}, ${eq})`;
};
export const jsonbObjectAgg = <T>(key: SQLWrapper, value: SQL<T> | SQLWrapper) => {
export const jsonbObjectAgg = <T>(
key: SQLWrapper,
value: SQL<T> | SQLWrapper,
) => {
return sql<
Record<string, T>
>`jsonb_object_agg(${sql.join([key, value], sql.raw(","))})`;
+33 -30
View File
@@ -68,44 +68,47 @@ export const SeedVideo = t.Object({
guess: Guess,
for: t.Array(
t.Union([
t.Object({
slug: t.String({
format: "slug",
examples: ["made-in-abyss-dawn-of-the-deep-soul"],
}),
}),
t.Object({
externalId: t.Optional(t.Union([EpisodeId, ExternalId()])),
}),
t.Object({
movie: t.Union([
t.String({ format: "uuid" }),
t.String({ format: "slug", examples: ["bubble"] }),
]),
}),
t.Intersect([
for: t.Optional(
t.Array(
t.Union([
t.Object({
serie: t.Union([
slug: t.String({
format: "slug",
examples: ["made-in-abyss-dawn-of-the-deep-soul"],
}),
}),
t.Object({
externalId: t.Optional(t.Union([EpisodeId, ExternalId()])),
}),
t.Object({
movie: t.Union([
t.String({ format: "uuid" }),
t.String({ format: "slug", examples: ["made-in-abyss"] }),
t.String({ format: "slug", examples: ["bubble"] }),
]),
}),
t.Union([
t.Intersect([
t.Object({
season: t.Integer({ minimum: 1 }),
episode: t.Integer(),
}),
t.Object({
order: t.Number(),
}),
t.Object({
special: t.Integer(),
serie: t.Union([
t.String({ format: "uuid" }),
t.String({ format: "slug", examples: ["made-in-abyss"] }),
]),
}),
t.Union([
t.Object({
season: t.Integer({ minimum: 1 }),
episode: t.Integer(),
}),
t.Object({
order: t.Number(),
}),
t.Object({
special: t.Integer(),
}),
]),
]),
]),
]),
{ default: [] },
),
),
});
export type SeedVideo = Prettify<typeof SeedVideo.static>;