mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Fix season get
This commit is contained in:
parent
b5460682c9
commit
5483e34c5e
@ -38,21 +38,27 @@ export const seasonsH = new Elysia({ tags: ["series"] })
|
|||||||
query: { limit, after, query, sort, filter },
|
query: { limit, after, query, sort, filter },
|
||||||
headers: { "accept-language": languages },
|
headers: { "accept-language": languages },
|
||||||
request: { url },
|
request: { url },
|
||||||
|
error,
|
||||||
}) => {
|
}) => {
|
||||||
const langs = processLanguages(languages);
|
const langs = processLanguages(languages);
|
||||||
|
|
||||||
const show = db.$with("serie").as(
|
const [serie] = await db
|
||||||
db
|
.select({ pk: shows.pk })
|
||||||
.select({ pk: shows.pk })
|
.from(shows)
|
||||||
.from(shows)
|
.where(
|
||||||
.where(
|
and(
|
||||||
and(
|
eq(shows.kind, "serie"),
|
||||||
eq(shows.kind, "serie"),
|
isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id),
|
||||||
isUuid(id) ? eq(shows.id, id) : eq(shows.slug, id),
|
),
|
||||||
),
|
)
|
||||||
)
|
.limit(1);
|
||||||
.limit(1),
|
|
||||||
);
|
if (!serie) {
|
||||||
|
return error(404, {
|
||||||
|
status: 404,
|
||||||
|
message: `No serie with the id or slug: '${id}'.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const transQ = db
|
const transQ = db
|
||||||
.selectDistinctOn([seasonTranslations.pk])
|
.selectDistinctOn([seasonTranslations.pk])
|
||||||
@ -65,7 +71,6 @@ export const seasonsH = new Elysia({ tags: ["series"] })
|
|||||||
const { pk, ...transCol } = getColumns(transQ);
|
const { pk, ...transCol } = getColumns(transQ);
|
||||||
|
|
||||||
const items = await db
|
const items = await db
|
||||||
.with(show)
|
|
||||||
.select({
|
.select({
|
||||||
...getColumns(seasons),
|
...getColumns(seasons),
|
||||||
...transCol,
|
...transCol,
|
||||||
@ -74,7 +79,7 @@ export const seasonsH = new Elysia({ tags: ["series"] })
|
|||||||
.innerJoin(transQ, eq(seasons.pk, transQ.pk))
|
.innerJoin(transQ, eq(seasons.pk, transQ.pk))
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(seasons.showPk, show.pk),
|
eq(seasons.showPk, serie.pk),
|
||||||
filter,
|
filter,
|
||||||
query ? sql`${transQ.name} %> ${query}::text` : undefined,
|
query ? sql`${transQ.name} %> ${query}::text` : undefined,
|
||||||
keysetPaginate({ table: seasons, after, sort }),
|
keysetPaginate({ table: seasons, after, sort }),
|
||||||
@ -92,10 +97,10 @@ export const seasonsH = new Elysia({ tags: ["series"] })
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
detail: { description: "Get seasons of a serie" },
|
detail: { description: "Get seasons of a serie" },
|
||||||
path: t.Object({
|
params: t.Object({
|
||||||
id: t.String({
|
id: t.String({
|
||||||
description: "The id or slug of the serie.",
|
description: "The id or slug of the serie.",
|
||||||
examples: [madeInAbyss.slug],
|
example: madeInAbyss.slug,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
query: t.Object({
|
query: t.Object({
|
||||||
@ -117,6 +122,10 @@ export const seasonsH = new Elysia({ tags: ["series"] })
|
|||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: Page(Season),
|
200: Page(Season),
|
||||||
|
404: {
|
||||||
|
...KError,
|
||||||
|
description: "No serie found with the given id or slug.",
|
||||||
|
},
|
||||||
422: KError,
|
422: KError,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -7,6 +7,11 @@ import { bubble } from "~/models/examples";
|
|||||||
import { dune, duneVideo } from "~/models/examples/dune-2021";
|
import { dune, duneVideo } from "~/models/examples/dune-2021";
|
||||||
import { createMovie, createVideo } from "../helpers";
|
import { createMovie, createVideo } from "../helpers";
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await db.delete(shows);
|
||||||
|
await db.delete(videos);
|
||||||
|
});
|
||||||
|
|
||||||
describe("Movie seeding", () => {
|
describe("Movie seeding", () => {
|
||||||
it("Can create a movie", async () => {
|
it("Can create a movie", async () => {
|
||||||
// create video beforehand to test linking
|
// create video beforehand to test linking
|
||||||
@ -404,10 +409,3 @@ describe("Movie seeding", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const cleanup = async () => {
|
|
||||||
await db.delete(shows);
|
|
||||||
await db.delete(videos);
|
|
||||||
};
|
|
||||||
// cleanup db beforehand to unsure tests are consistent
|
|
||||||
beforeAll(cleanup);
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, it } from "bun:test";
|
import { beforeAll, describe, expect, it } from "bun:test";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { expectStatus } from "tests/utils";
|
import { expectStatus } from "tests/utils";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
@ -6,6 +6,11 @@ import { seasons, shows, videos } from "~/db/schema";
|
|||||||
import { madeInAbyss, madeInAbyssVideo } from "~/models/examples";
|
import { madeInAbyss, madeInAbyssVideo } from "~/models/examples";
|
||||||
import { createSerie } from "../helpers";
|
import { createSerie } from "../helpers";
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await db.delete(shows);
|
||||||
|
await db.delete(videos);
|
||||||
|
});
|
||||||
|
|
||||||
describe("Serie seeding", () => {
|
describe("Serie seeding", () => {
|
||||||
it("Can create a serie with seasons and episodes", async () => {
|
it("Can create a serie with seasons and episodes", async () => {
|
||||||
// create video beforehand to test linking
|
// create video beforehand to test linking
|
||||||
@ -69,6 +74,7 @@ describe("Serie seeding", () => {
|
|||||||
{
|
{
|
||||||
language: "en",
|
language: "en",
|
||||||
...movie.translations.en,
|
...movie.translations.en,
|
||||||
|
poster: { source: movie.translations.en.poster },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user