mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Use select with named fields for movies
This commit is contained in:
parent
6327e911ad
commit
6d13f0610b
@ -2,10 +2,17 @@ import { Elysia, t } from "elysia";
|
|||||||
import { Movie } from "../models/movie";
|
import { Movie } from "../models/movie";
|
||||||
import { db } from "../db";
|
import { db } from "../db";
|
||||||
import { shows, showTranslations } from "../db/schema/shows";
|
import { shows, showTranslations } from "../db/schema/shows";
|
||||||
import { eq, and, sql, or, inArray } from "drizzle-orm";
|
import { eq, and, sql, or, inArray, getTableColumns } from "drizzle-orm";
|
||||||
|
|
||||||
|
const { pk: _, kind, startAir, endAir, ...moviesCol } = getTableColumns(shows);
|
||||||
|
const { pk, language, ...translationsCol } = getTableColumns(showTranslations);
|
||||||
|
|
||||||
const findMovie = db
|
const findMovie = db
|
||||||
.select()
|
.select({
|
||||||
|
...moviesCol,
|
||||||
|
airDate: startAir,
|
||||||
|
...translationsCol,
|
||||||
|
})
|
||||||
.from(shows)
|
.from(shows)
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
db
|
db
|
||||||
@ -50,9 +57,5 @@ export const movies = new Elysia({ prefix: "/movies" })
|
|||||||
.get("/:id", async ({ params: { id }, error }) => {
|
.get("/:id", async ({ params: { id }, error }) => {
|
||||||
const ret = await findMovie.execute({ id });
|
const ret = await findMovie.execute({ id });
|
||||||
if (ret.length !== 1) return error(404, {});
|
if (ret.length !== 1) return error(404, {});
|
||||||
return {
|
return ret[0];
|
||||||
...ret[0].shows,
|
|
||||||
...ret[0].t,
|
|
||||||
airDate: ret[0].shows.startAir,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user