mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add 200/201 handling on post /movies + doc
This commit is contained in:
parent
5d24dcafd5
commit
24035c15bf
@ -11,12 +11,24 @@ export const seed = new Elysia()
|
||||
})
|
||||
.post(
|
||||
"/movies",
|
||||
async ({ body }) => {
|
||||
return await seedMovie(body);
|
||||
async ({ body, error }) => {
|
||||
const { status, ...ret } = await seedMovie(body);
|
||||
return error(status === "created" ? 201 : 200, ret);
|
||||
},
|
||||
{
|
||||
body: "seed-movie",
|
||||
response: { 200: "seed-movie-response", 400: "error" },
|
||||
tags: ["movies"],
|
||||
response: {
|
||||
200: {
|
||||
...SeedMovieResponse,
|
||||
description: "Existing movie edited/updated.",
|
||||
},
|
||||
201: { ...SeedMovieResponse, description: "Created a new movie." },
|
||||
400: "error",
|
||||
},
|
||||
detail: {
|
||||
tags: ["movies"],
|
||||
description:
|
||||
"Create a movie & all related metadata. Can also link videos.",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
@ -11,7 +11,6 @@ import {
|
||||
} from "~/db/schema";
|
||||
import { conflictUpdateAllExcept } from "~/db/schema/utils";
|
||||
import type { SeedMovie } from "~/models/movie";
|
||||
import { Resource } from "~/models/utils";
|
||||
import { processOptImage } from "./images";
|
||||
import { guessNextRefresh } from "./refresh";
|
||||
|
||||
@ -19,17 +18,18 @@ type Show = typeof shows.$inferInsert;
|
||||
type ShowTrans = typeof showTranslations.$inferInsert;
|
||||
type Entry = typeof entries.$inferInsert;
|
||||
|
||||
export const SeedMovieResponse = t.Intersect([
|
||||
Resource,
|
||||
t.Object({
|
||||
videos: t.Array(t.Object({ slug: t.String({ format: "slug" }) })),
|
||||
}),
|
||||
]);
|
||||
export const SeedMovieResponse = t.Object({
|
||||
id: t.String({ format: "uuid" }),
|
||||
slug: t.String({ format: "slug", examples: ["bubble"] }),
|
||||
videos: t.Array(
|
||||
t.Object({ slug: t.String({ format: "slug", examples: ["bubble-v2"] }) }),
|
||||
),
|
||||
});
|
||||
export type SeedMovieResponse = typeof SeedMovieResponse.static;
|
||||
|
||||
export const seedMovie = async (
|
||||
seed: SeedMovie,
|
||||
): Promise<SeedMovieResponse> => {
|
||||
): Promise<SeedMovieResponse & { status: "created" | "updated" }> => {
|
||||
const { translations, videos: vids, ...bMovie } = seed;
|
||||
|
||||
const ret = await db.transaction(async (tx) => {
|
||||
@ -139,6 +139,7 @@ export const seedMovie = async (
|
||||
}
|
||||
|
||||
return {
|
||||
status: ret.updated ? "updated" : "created",
|
||||
id: ret.id,
|
||||
slug: ret.slug,
|
||||
videos: retVideos,
|
||||
|
@ -73,7 +73,6 @@ const app = new Elysia()
|
||||
},
|
||||
}),
|
||||
)
|
||||
.get("/", () => "Hello Elysia")
|
||||
.model({ image: Image })
|
||||
.use(movies)
|
||||
.use(series)
|
||||
|
Loading…
x
Reference in New Issue
Block a user