mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Fix type issues on get /movies
This commit is contained in:
parent
eea0f688a0
commit
43ae26679a
@ -7,7 +7,7 @@ import { db } from "../db";
|
||||
import { shows, showTranslations } from "../db/schema/shows";
|
||||
import { getColumns } from "../db/schema/utils";
|
||||
import { bubble } from "../models/examples";
|
||||
import { Movie, MovieTranslation } from "../models/movie";
|
||||
import { Movie, type MovieStatus, MovieTranslation } from "../models/movie";
|
||||
|
||||
// drizzle is bugged and doesn't allow js arrays to be used in raw sql.
|
||||
export function sqlarr(array: unknown[]) {
|
||||
@ -41,7 +41,52 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
movie: Movie,
|
||||
"movie-translation": MovieTranslation,
|
||||
})
|
||||
.guard({
|
||||
.get(
|
||||
"/:id",
|
||||
async ({
|
||||
params: { id },
|
||||
headers: { "accept-language": languages },
|
||||
error,
|
||||
set,
|
||||
}) => {
|
||||
const langs = processLanguages(languages);
|
||||
const [transQ, transCol] = getTranslationQuery(langs);
|
||||
|
||||
const idFilter = isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id);
|
||||
|
||||
const [ret] = await db
|
||||
.select({
|
||||
...moviesCol,
|
||||
status: sql<MovieStatus>`${moviesCol.status}`,
|
||||
airDate: startAir,
|
||||
translation: transCol,
|
||||
})
|
||||
.from(shows)
|
||||
.leftJoin(transQ, eq(shows.pk, transQ.pk))
|
||||
.where(and(eq(shows.kind, "movie"), idFilter))
|
||||
.limit(1);
|
||||
|
||||
if (!ret) {
|
||||
return error(404, {
|
||||
status: 404,
|
||||
message: "Movie not found",
|
||||
details: undefined,
|
||||
});
|
||||
}
|
||||
if (!ret.translation) {
|
||||
return error(422, {
|
||||
status: 422,
|
||||
message: "Accept-Language header could not be satisfied.",
|
||||
details: undefined,
|
||||
});
|
||||
}
|
||||
set.headers["content-language"] = ret.translation.language;
|
||||
return { ...ret, ...ret.translation };
|
||||
},
|
||||
{
|
||||
detail: {
|
||||
description: "Get a movie by id or slug",
|
||||
},
|
||||
params: t.Object({
|
||||
id: t.String({
|
||||
description: "The id or slug of the movie to retrieve",
|
||||
@ -74,51 +119,5 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
`,
|
||||
},
|
||||
},
|
||||
})
|
||||
.get(
|
||||
"/:id",
|
||||
async ({
|
||||
params: { id },
|
||||
headers: { "accept-language": languages },
|
||||
error,
|
||||
set,
|
||||
}) => {
|
||||
const langs = processLanguages(languages);
|
||||
const [transQ, transCol] = getTranslationQuery(langs);
|
||||
|
||||
const idFilter = isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id);
|
||||
|
||||
const [ret] = await db
|
||||
.select({
|
||||
...moviesCol,
|
||||
...transCol,
|
||||
airDate: startAir,
|
||||
})
|
||||
.from(shows)
|
||||
.leftJoin(transQ, eq(shows.pk, transQ.pk))
|
||||
.where(and(eq(shows.kind, "movie"), idFilter))
|
||||
.limit(1);
|
||||
|
||||
if (!ret) {
|
||||
return error(404, {
|
||||
status: 404,
|
||||
message: "Movie not found",
|
||||
details: undefined,
|
||||
});
|
||||
}
|
||||
if (!ret.language) {
|
||||
return error(422, {
|
||||
status: 422,
|
||||
message: "Accept-Language header could not be satisfied.",
|
||||
details: undefined,
|
||||
});
|
||||
}
|
||||
set.headers["content-language"] = ret.language;
|
||||
return ret;
|
||||
},
|
||||
{
|
||||
detail: {
|
||||
description: "Get a movie by id or slug",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { t } from "elysia";
|
||||
import { ExternalId, Genre, Image, Language, SeedImage } from "./utils";
|
||||
import { SeedVideo } from "./video";
|
||||
import { bubble, registerExamples } from "./examples";
|
||||
import { bubbleImages } from "./examples/bubble";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user